-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution.py
32 lines (22 loc) · 831 Bytes
/
solution.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
# https://adventofcode.com/2018/day/14
def part1_condition(recipes, puzzle_input):
return len(recipes) >= 10 + puzzle_input
def part2_condition(recipes, puzzle_input):
search = [int(x) for x in str(puzzle_input)]
return recipes[-len(search):] == search
def do_until(condition, puzzle_input):
recipes = [3,7]
current = [0,1]
while True:
current_scores = [recipes[i] for i in current]
newscore = sum(current_scores)
for r in [int(x) for x in str(newscore)]:
recipes.append(r)
if condition(recipes, puzzle_input):
return recipes
current = [(current[i] + current_scores[i] + 1) % len(recipes) for i in range(len(current_scores))]
inp = 147061
recipes = do_until(part1_condition, inp)
print("".join(map(str, recipes[-10:])))
recipes = do_until(part2_condition, inp)
print(len(recipes)-len(str(inp)))