-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
71 lines (58 loc) · 1.54 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use std::collections::HashSet;
fn main() {
{
let mut seen = HashSet::new();
seen.insert((0, 0));
let s = include_str!("../in.txt");
let mut x = 0;
let mut y = 0;
for c in s.chars() {
let m = match c {
'>' => (1, 0),
'<' => (-1, 0),
'^' => (0, 1),
'v' => (0, -1),
_ => (0, 0),
};
x += m.0;
y += m.1;
seen.insert((x, y));
}
println!("Part 1: {}", seen.len());
}
{
let mut santa = HashSet::new();
let mut robo = HashSet::new();
santa.insert((0, 0));
robo.insert((0, 0));
let s = include_str!("../in.txt");
let mut santa_x = 0;
let mut santa_y = 0;
let mut robo_x = 0;
let mut robo_y = 0;
for (i, c) in s.chars().enumerate() {
let m = match c {
'>' => (1, 0),
'<' => (-1, 0),
'^' => (0, 1),
'v' => (0, -1),
_ => (0, 0),
};
if i % 2 == 0 {
santa_x += m.0;
santa_y += m.1;
santa.insert((santa_x, santa_y));
} else {
robo_x += m.0;
robo_y += m.1;
santa.insert((robo_x, robo_y));
}
}
println!(
"Part 2: {} + {} = {}",
santa.len(),
robo.len(),
santa.len()
);
}
}