Day 15 (visualize)
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
22
day15/visualize.py
Normal 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()
|
||||
Reference in New Issue
Block a user