1use crate::util::hash::*;
10use crate::util::point::*;
11
12pub fn parse(input: &str) -> Vec<Point> {
13 input.trim().bytes().map(Point::from).collect()
14}
15
16pub fn part1(input: &[Point]) -> usize {
17 deliver(input, |_| true)
18}
19
20pub fn part2(input: &[Point]) -> usize {
21 deliver(input, |i| i % 2 == 0)
22}
23
24fn deliver(input: &[Point], predicate: fn(usize) -> bool) -> usize {
25 let mut santa = ORIGIN;
26 let mut robot = ORIGIN;
27 let mut set = FastSet::with_capacity(10_000);
28 set.insert(ORIGIN);
29
30 for (index, point) in input.iter().enumerate() {
31 if predicate(index) {
32 santa += *point;
33 set.insert(santa);
34 } else {
35 robot += *point;
36 set.insert(robot);
37 }
38 }
39
40 set.len()
41}