-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaoc_day14.py
48 lines (33 loc) · 978 Bytes
/
aoc_day14.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
44
45
46
47
48
board = [3,7]
elf1 = 0
elf2 = 1
input = 110201
def add_recipes():
global elf1, elf2
score = board[elf1] + board[elf2]
if score < 10: board.append(score)
else:
board.append(1)
board.append(score%10)
elf1 = (elf1 + board[elf1] + 1) % len(board)
elf2 = (elf2 + board[elf2] + 1) % len(board)
while len(board) < input + 10:
add_recipes()
print('Solution 14.1:', ''.join([str(x) for x in board[-10:]]))
board = [3,7]
elf1 = 0
elf2 = 1
found = False
target = [int(x) for x in str(input)]
while not found:
add_recipes()
if len(board) < len(target): continue
if board[-len(target):] == target:
found = True
print('Solution 14.2:', len(board) - len(target))
break
# need to also do an offset check because it could have been two added
if board[-len(target) - 1:-1] == target:
found = True
print('Solution 14.2:', len(board) - len(target) - 1)
break