day15 - raw solution
This commit is contained in:
parent
7fa39e155d
commit
017e04a27c
29
day15.py
Normal file
29
day15.py
Normal 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_test
Normal file
1
inputs/15_test
Normal file
@ -0,0 +1 @@
|
||||
0,3,6
|
||||
Loading…
Reference in New Issue
Block a user