Day 15
This commit is contained in:
1
day15/input.txt
Normal file
1
day15/input.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
0,13,16,17,1,10,6
|
||||||
25
day15/part1.py
Normal file
25
day15/part1.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
lines = (x.strip() for x in open("input.txt"))
|
||||||
|
nums = defaultdict(list)
|
||||||
|
TARGET = 2020
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
print(line)
|
||||||
|
turn = 0
|
||||||
|
last_spoken = 0
|
||||||
|
for starting in map(int, line.split(",")):
|
||||||
|
nums[starting] = [turn]
|
||||||
|
turn += 1
|
||||||
|
last_spoken = starting
|
||||||
|
for t in range(turn, TARGET):
|
||||||
|
last = nums[last_spoken]
|
||||||
|
if len(last) == 2:
|
||||||
|
n = last[1] - last[0]
|
||||||
|
else:
|
||||||
|
n = 0
|
||||||
|
nums[n] = nums[n][-1:] + [t]
|
||||||
|
last_spoken = n
|
||||||
|
print("->", last_spoken)
|
||||||
25
day15/part2.py
Normal file
25
day15/part2.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
lines = (x.strip() for x in open("input.txt"))
|
||||||
|
nums = defaultdict(list)
|
||||||
|
TARGET = 30000000
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
print(line)
|
||||||
|
turn = 0
|
||||||
|
last_spoken = 0
|
||||||
|
for starting in map(int, line.split(",")):
|
||||||
|
nums[starting] = [turn]
|
||||||
|
turn += 1
|
||||||
|
last_spoken = starting
|
||||||
|
for t in range(turn, TARGET):
|
||||||
|
last = nums[last_spoken]
|
||||||
|
if len(last) == 2:
|
||||||
|
n = last[1] - last[0]
|
||||||
|
else:
|
||||||
|
n = 0
|
||||||
|
nums[n] = nums[n][-1:] + [t]
|
||||||
|
last_spoken = n
|
||||||
|
print("->", last_spoken)
|
||||||
Reference in New Issue
Block a user