-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday14.rs
44 lines (40 loc) · 1.13 KB
/
day14.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
fn main() {
let mut scores = vec![3,7];
let limit = 633601;
let mut elf1 = 0;
let mut elf2 = 1;
// Part 1
while scores.len() < limit + 11 {
let new_score = scores[elf1] + scores[elf2];
if new_score > 9 {
scores.push(1);
}
scores.push(new_score % 10);
elf1 = (elf1 + 1 + scores[elf1]) % scores.len();
elf2 = (elf2 + 1 + scores[elf2]) % scores.len();
}
println!("{:?}", &scores[limit..limit+10]);
// Part 2
let mut scores = vec![3,7];
let limit = [6,3,3,6,0,1];
let mut elf1 = 0;
let mut elf2 = 1;
let mut index = 0;
loop {
let new_score = scores[elf1] + scores[elf2];
if new_score > 9 {
scores.push(1);
}
scores.push(new_score % 10);
elf1 = (elf1 + 1 + scores[elf1]) % scores.len();
elf2 = (elf2 + 1 + scores[elf2]) % scores.len();
if scores.len() >= limit.len() {
if scores[index..index+limit.len()] == limit {
println!("{:?}", index);
break;
} else {
index += 1;
}
}
}
}