Day 15 (visualize)

This commit is contained in:
Sebastian Seedorf
2020-12-15 23:10:09 +01:00
parent 5a2b9fe23f
commit 20e80270ca
4 changed files with 26 additions and 4 deletions

View File

@@ -9,12 +9,12 @@ def yield_numbers(line: str, target: int):
nums[last_spoken] = turn
turn += 1
last_spoken = starting
yield turn, last_spoken
yield turn, last_spoken, nums
for t in range(turn, target):
n = t - nums[last_spoken] if last_spoken in nums else 0
nums[last_spoken] = t
last_spoken = n
yield t+1, last_spoken
yield t+1, last_spoken, nums
def get_target(line: str, target: int):

View File

@@ -6,5 +6,5 @@ lines = (x.strip() for x in open("input.txt"))
for line in lines:
print(line)
last_spoken = get_target(line, 2020)
last_spoken = get_target(line, 2020)[1]
print("->", last_spoken)

View File

@@ -6,5 +6,5 @@ lines = (x.strip() for x in open("input.txt"))
for line in lines:
print(line)
last_spoken = get_target(line, 30000000)
last_spoken = get_target(line, 30000000)[1]
print("->", last_spoken)

22
day15/visualize.py Normal file
View File

@@ -0,0 +1,22 @@
from day15.common import yield_numbers
from matplotlib import pyplot as plt
import numpy as np
data = list(map(lambda x: (x[1],len(x[2]),len(x[2])/x[0]), yield_numbers("0,3,6", 30000000)))
data = np.array(data)
plt.plot(
data[:,:2],
linestyle='none',
marker='.',
markersize=1
)
plt.show()
plt.plot(
data[:,2],
linestyle='none',
marker='.',
markersize=1,
color='g'
)
plt.show()