2018-12-10 17:34:14 +10:30
|
|
|
with open('day10-input', 'r') as file:
|
|
|
|
data = [l.strip('\n') for l in file]
|
|
|
|
import numpy as np
|
2018-12-10 20:12:38 +10:30
|
|
|
import re
|
2018-12-10 17:34:14 +10:30
|
|
|
|
2018-12-10 20:12:38 +10:30
|
|
|
numbers = np.array([[int(s) for s in re.findall(r'-?\d+', d)] for d in data], dtype=np.int64)
|
|
|
|
start_positions = numbers[:,:2]
|
|
|
|
velocities = numbers[:,2:]
|
2018-12-10 17:34:14 +10:30
|
|
|
|
|
|
|
max_t = 11000
|
2018-12-10 20:12:38 +10:30
|
|
|
positions = np.empty((*start_positions.shape, max_t))
|
2018-12-10 17:34:14 +10:30
|
|
|
for t in range(max_t):
|
2018-12-10 20:12:38 +10:30
|
|
|
positions[:,:,t] = start_positions + t*velocities
|
|
|
|
|
|
|
|
heights = positions[:,1,:].max(0)-positions[:,1,:].min(0)
|
2018-12-10 17:34:14 +10:30
|
|
|
t = np.argmin(heights)
|
|
|
|
|
2018-12-10 20:12:38 +10:30
|
|
|
|
2018-12-10 17:34:14 +10:30
|
|
|
from pyqtgraph.Qt import QtCore, QtGui
|
|
|
|
import pyqtgraph as pg
|
|
|
|
|
|
|
|
app = QtGui.QApplication([])
|
|
|
|
win = pg.GraphicsLayoutWidget()
|
|
|
|
win.resize(2000,600)
|
|
|
|
win.setWindowTitle('Scatter Plot')
|
|
|
|
win.show()
|
|
|
|
|
2018-12-10 20:12:38 +10:30
|
|
|
plot = win.addPlot(title=f't={t}')
|
|
|
|
plot.plot(positions[:,:,t], pen=None, symbol='s', symbolPen=None, symbolSize=10, symbolBrush=(100, 100, 255, 250))
|
|
|
|
plot.getViewBox().invertY(True)
|
2018-12-10 17:34:14 +10:30
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
|
|
|
|
QtGui.QApplication.instance().exec_()
|