-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
main.rs
31 lines (28 loc) · 875 Bytes
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use pathfinding::directed::dijkstra;
const NEXT: [(i32, i32); 4] = [(1, 0), (-1, 0), (0, 1), (0, -1)];
pub fn main() {
let map: Vec<Vec<_>> = include_str!("../input.txt")
.lines()
.map(|l| l.bytes().map(|c| c - b'0').collect())
.collect();
let goal = (map[0].len() as i32 - 1, map.len() as i32 - 1);
println!(
"{}",
dijkstra::dijkstra(
&(0, 0),
|(x, y)| {
NEXT.iter()
.map(|(xx, yy)| {
map.get((y + yy) as usize)
.and_then(|r| r.get((x + xx) as usize))
.map(|c| ((x + xx, y + yy), *c as u32))
})
.flatten()
.collect::<Vec<_>>()
},
|&p| p == goal,
)
.unwrap()
.1,
);
}