-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day14Task2.py
40 lines (29 loc) · 1.07 KB
/
Day14Task2.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
# Need number of recipes left of the first occurrence of sublist 509671
import time
def addNewRecipes(recipe_scores, elf1, elf2):
elf1_score = recipe_scores[elf1]
elf2_score = recipe_scores[elf2]
total_score = elf1_score + elf2_score # maximum of 18
if total_score < 10: recipe_scores.append(total_score)
else:
recipe_scores.append(1)
recipe_scores.append(total_score-10)
elf1 = (elf1 + 1 + elf1_score) % len(recipe_scores)
elf2 = (elf2 + 1 + elf2_score) % len(recipe_scores)
return recipe_scores, elf1, elf2
input = '074501'
recipe_scores = [3, 7]
elf1 = 0
elf2 = 1
pattern = [int(digit) for digit in input]
t1 = time.time()
while True:
recipe_scores, elf1, elf2 = addNewRecipes(recipe_scores, elf1, elf2)
if recipe_scores[-len(pattern):] == pattern:
print(len(recipe_scores)-len(pattern))
break
elif recipe_scores[-len(pattern)-1:-1] == pattern:
print(len(recipe_scores)-len(pattern)-1)
break
if len(recipe_scores) %100000 == 0: print(len(recipe_scores))
print(time.time()-t1)