From b5c941c684172fb63f4b32bc941221e71128b5e0 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Mon, 12 Dec 2022 20:00:20 +0100 Subject: [PATCH] 2022 day10/rust: cleanup --- 2022/day12/rust/src/main.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/2022/day12/rust/src/main.rs b/2022/day12/rust/src/main.rs index f128bd1..20bf026 100644 --- a/2022/day12/rust/src/main.rs +++ b/2022/day12/rust/src/main.rs @@ -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::::new(); - let grid: Vec> = data + let grid: Vec> = stdin() .lines() .map(|line| { - line.chars() + line.unwrap() + .chars() .map(|c| { let (kind, c) = match c { 'S' => (Some(NodeKind::Start), 'a'), @@ -52,13 +50,14 @@ 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)] - .into_iter() - .filter_map(|(dx, dy)| { - let x = usize::try_from(x + dx).ok()?; - let y = usize::try_from(y + dy).ok()?; - grid.get(x)?.get(y) - }); + let neighbours = + [(-1, 0), (0, -1), (1, 0), (0, 1)] + .into_iter() + .filter_map(|(dx, dy)| { + let x = usize::try_from(x + dx).ok()?; + let y = usize::try_from(y + dy).ok()?; + grid.get(x)?.get(y) + }); for &neighbour_id in neighbours { let neighbour = graph[neighbour_id];