diff --git a/day15/common.py b/day15/common.py index a42b0a6..168c724 100644 --- a/day15/common.py +++ b/day15/common.py @@ -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): diff --git a/day15/part1.py b/day15/part1.py index 5633b79..e7aa285 100644 --- a/day15/part1.py +++ b/day15/part1.py @@ -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) diff --git a/day15/part2.py b/day15/part2.py index 62ec9f3..917bbf9 100644 --- a/day15/part2.py +++ b/day15/part2.py @@ -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) diff --git a/day15/visualize.py b/day15/visualize.py new file mode 100644 index 0000000..2d847a0 --- /dev/null +++ b/day15/visualize.py @@ -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()