day15 - raw solution

This commit is contained in:
Stefan Harmuth 2020-12-15 06:29:38 +01:00
parent 7fa39e155d
commit 017e04a27c
3 changed files with 31 additions and 0 deletions

29
day15.py Normal file
View File

@ -0,0 +1,29 @@
import aoclib
DAY = 15
TEST_SOLUTION_PART1 = 436
TEST_SOLUTION_PART2 = 175594
def part1(test_mode=False, count=2020):
my_input = aoclib.getInputAsArraySplit(day=DAY, return_type=int, split_char=",", test=test_mode)
memory_last = {v: i for i, v in enumerate(my_input)}
memory_prev = {}
last_spoken = my_input[-1]
for i in range(len(my_input), count):
if last_spoken not in memory_prev:
last_spoken = 0
else:
last_spoken = i - 1 - memory_prev[last_spoken]
if last_spoken in memory_last:
memory_prev[last_spoken] = memory_last[last_spoken]
memory_last[last_spoken] = i
return last_spoken
def part2(test_mode=False):
return part1(test_mode, count=30000000)

1
inputs/15 Normal file
View File

@ -0,0 +1 @@
16,12,1,0,15,7,11

1
inputs/15_test Normal file
View File

@ -0,0 +1 @@
0,3,6