-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmain.rs
More file actions
21 lines (20 loc) · 668 Bytes
/
main.rs
File metadata and controls
21 lines (20 loc) · 668 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
pub fn main() {
let map = include_bytes!("../input.txt")
.split(|&b| b == b'\n')
.collect::<Vec<_>>();
let neighbors = [(0, -1), (0, 1), (-1, 0), (1, 0)];
let mut sum = 0;
for (y, line) in map.iter().enumerate() {
for (x, cell) in line.iter().enumerate() {
if neighbors.iter().all(|&(xx, yy)| {
map.get((y as isize + yy) as usize)
.and_then(|l| l.get((x as isize + xx) as usize))
.map(|n| cell < n)
.unwrap_or(true)
}) {
sum += (cell - b'0') as usize + 1;
}
}
}
println!("{sum}");
}