forked from timvisee/advent-of-code-2022
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
24 lines (22 loc) · 730 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
pub fn main() {
let cmds = include_bytes!("../input.txt")
.split(|b| b == &b'\n')
.map(|l| match (l[0], atoi::atoi(&l[2..]).unwrap()) {
(b'U', l) => ((0, -1), l),
(b'D', l) => ((0, 1), l),
(b'L', l) => ((-1, 0), l),
(_, l) => ((1, 0), l),
});
let (mut h, mut t, mut s): ((i32, i32), (_, _), rustc_hash::FxHashSet<_>) = Default::default();
s.insert((0, 0));
for (d, l) in cmds {
for _ in 0..l {
h = (h.0 + d.0, h.1 + d.1);
if h.0.abs_diff(t.0) > 1 || h.1.abs_diff(t.1) > 1 {
t = (h.0 - d.0, h.1 - d.1);
s.insert(t);
}
}
}
println!("{}", s.len());
}