-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03.rs
37 lines (31 loc) · 755 Bytes
/
03.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
32
33
34
35
36
37
#![feature(test)]
use aoc::grid::Direction;
use rustc_hash::FxHashSet;
type Input = Vec<Direction>;
fn setup(input: &str) -> Input {
input.trim().chars().map(|b| b.into()).collect()
}
fn part1(input: &Input) -> usize {
input
.iter()
.scan((0, 0), |acc, &x| {
*acc = x.step_signed(*acc);
Some(*acc)
})
.chain([(0, 0)])
.collect::<FxHashSet<_>>()
.len()
}
fn part2(input: &Input) -> usize {
input
.iter()
.scan(((0, 0), (0, 0)), |(a, b), &x| {
std::mem::swap(a, b);
*a = x.step_signed(*a);
Some(*a)
})
.chain([(0, 0)])
.collect::<FxHashSet<_>>()
.len()
}
aoc::main!(2015, 3, ex: 1);