2022 day10/rust: cleanup
This commit is contained in:
parent
20981716c3
commit
b5c941c684
1 changed files with 12 additions and 13 deletions
|
@ -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,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];
|
||||
|
|
Loading…
Reference in a new issue