2022 day10/rust: cleanup

This commit is contained in:
Xiretza 2022-12-12 20:00:20 +01:00
parent 20981716c3
commit b5c941c684

View file

@ -1,6 +1,6 @@
#![warn(clippy::pedantic)]
use std::io::{stdin, Read};
use std::io::stdin;
use petgraph::{
algo::k_shortest_path,
@ -21,16 +21,14 @@ struct NodeData {
}
fn main() {
let mut data = String::new();
stdin().read_to_string(&mut data).unwrap();
// graph of "downhill" edges - edge from A to B means that A is reachable from B
let mut graph = Graph::<NodeData, (), _>::new();
let grid: Vec<Vec<NodeIndex>> = data
let grid: Vec<Vec<NodeIndex>> = stdin()
.lines()
.map(|line| {
line.chars()
line.unwrap()
.chars()
.map(|c| {
let (kind, c) = match c {
'S' => (Some(NodeKind::Start), 'a'),
@ -52,7 +50,8 @@ fn main() {
let x = i32::try_from(x).unwrap();
let y = i32::try_from(y).unwrap();
let neighbours = [(-1i32, 0), (0, -1), (1, 0), (0, 1)]
let neighbours =
[(-1, 0), (0, -1), (1, 0), (0, 1)]
.into_iter()
.filter_map(|(dx, dy)| {
let x = usize::try_from(x + dx).ok()?;