-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathd14.py
43 lines (36 loc) · 979 Bytes
/
d14.py
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
# p1
cl = [3, 7]
elf1 = 0
elf2 = 1
offset = 293801
minscores = offset + 10
while len(cl) < minscores:
elf1_score = cl[elf1 % len(cl)]
elf2_score = cl[elf2 % len(cl)]
newscore = elf1_score + elf2_score
for digit in str(newscore):
cl.append(int(digit))
elf1 = (elf1 + elf1_score + 1) % len(cl)
elf2 = (elf2 + elf2_score + 1) % len(cl)
print(''.join([str(x) for x in cl[offset:minscores]]))
seek = [2, 9, 3, 8, 0, 1]
for i in range(len(cl)):
if cl[i:i+6] == seek:
print('found', i)
# p2
cl = [3, 7]
elf1 = 0
elf2 = 1
minscores = 21000000
while len(cl) < minscores:
elf1_score = cl[elf1 % len(cl)]
elf2_score = cl[elf2 % len(cl)]
newscore = elf1_score + elf2_score
for digit in str(newscore):
cl.append(int(digit))
elf1 = (elf1 + elf1_score + 1) % len(cl)
elf2 = (elf2 + elf2_score + 1) % len(cl)
seek = [2, 9, 3, 8, 0, 1]
for i in range(len(cl)):
if cl[i:i+6] == seek:
print('found', i)