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