Day 15 (cleanup)
This commit is contained in:
@@ -3,11 +3,11 @@
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
lines = (x.strip() for x in open("input.txt"))
|
lines = (x.strip() for x in open("input.txt"))
|
||||||
nums = defaultdict(list)
|
|
||||||
TARGET = 2020
|
TARGET = 2020
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
print(line)
|
print(line)
|
||||||
|
nums = defaultdict(list)
|
||||||
turn = 0
|
turn = 0
|
||||||
last_spoken = 0
|
last_spoken = 0
|
||||||
for starting in map(int, line.split(",")):
|
for starting in map(int, line.split(",")):
|
||||||
@@ -16,10 +16,7 @@ for line in lines:
|
|||||||
last_spoken = starting
|
last_spoken = starting
|
||||||
for t in range(turn, TARGET):
|
for t in range(turn, TARGET):
|
||||||
last = nums[last_spoken]
|
last = nums[last_spoken]
|
||||||
if len(last) == 2:
|
n = last[1] - last[0] if len(last) == 2 else 0
|
||||||
n = last[1] - last[0]
|
|
||||||
else:
|
|
||||||
n = 0
|
|
||||||
nums[n] = nums[n][-1:] + [t]
|
nums[n] = nums[n][-1:] + [t]
|
||||||
last_spoken = n
|
last_spoken = n
|
||||||
print("->", last_spoken)
|
print("->", last_spoken)
|
||||||
|
|||||||
@@ -3,11 +3,11 @@
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
lines = (x.strip() for x in open("input.txt"))
|
lines = (x.strip() for x in open("input.txt"))
|
||||||
nums = defaultdict(list)
|
|
||||||
TARGET = 30000000
|
TARGET = 30000000
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
print(line)
|
print(line)
|
||||||
|
nums = defaultdict(list)
|
||||||
turn = 0
|
turn = 0
|
||||||
last_spoken = 0
|
last_spoken = 0
|
||||||
for starting in map(int, line.split(",")):
|
for starting in map(int, line.split(",")):
|
||||||
@@ -16,10 +16,7 @@ for line in lines:
|
|||||||
last_spoken = starting
|
last_spoken = starting
|
||||||
for t in range(turn, TARGET):
|
for t in range(turn, TARGET):
|
||||||
last = nums[last_spoken]
|
last = nums[last_spoken]
|
||||||
if len(last) == 2:
|
n = last[1] - last[0] if len(last) == 2 else 0
|
||||||
n = last[1] - last[0]
|
|
||||||
else:
|
|
||||||
n = 0
|
|
||||||
nums[n] = nums[n][-1:] + [t]
|
nums[n] = nums[n][-1:] + [t]
|
||||||
last_spoken = n
|
last_spoken = n
|
||||||
print("->", last_spoken)
|
print("->", last_spoken)
|
||||||
|
|||||||
Reference in New Issue
Block a user