From 20e80270cae899f22e690f874cdeb03db306578a Mon Sep 17 00:00:00 2001 From: Sebastian Seedorf Date: Tue, 15 Dec 2020 23:10:09 +0100 Subject: [PATCH] Day 15 (visualize) --- day15/common.py | 4 ++-- day15/part1.py | 2 +- day15/part2.py | 2 +- day15/visualize.py | 22 ++++++++++++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 day15/visualize.py 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()