In [1]:
import re
import numpy as np
import matplotlib.pyplot as plt

In [2]:
def split(s):
    return re.split('<|>|=<|,', s)

def extract(l):
    pos = (int(l[1]), int(l[2]))
    vel = (int(l[4]), int(l[5]))
    return pos, vel
    
def parse():
    l = ! cat input.txt | tr '\n' ';'
    l = list(map(split, l[0].split(';')))
    return list(map(extract, l[:-1]))

l = parse()

In [3]:
pos, vel = zip(*l)
pos = np.array(pos)
posx, posy = zip(*pos)
posx = list(posx)
posy = list(posy)

In [6]:
l = parse()

def coords(pos):
    posx, posy = zip(*pos)
    posx = list(posx)
    posy = list(posy)
    posy = list(map(lambda x: -1*x, posy))
    return posx, posy

def diameter(pos):
    return np.max(list(map(np.linalg.norm, pos)))

def draw(diam):
    pos, vel = zip(*l)
    pos = np.array(pos)
    vel = np.array(vel)
    c = 1
    while diameter(pos) > diam:
        pos += vel
        c += 1
    while diameter(pos) <= diam:
        pos += vel
        posx, posy = coords(pos)
        plt.scatter(posx, posy)
        plt.show()
        print(c)
        print(diameter(pos))
        c += 1
        
def iterate(iters):
    pos, vel = zip(*l)
    pos = np.array(pos)
    vel = np.array(vel)
    c = 1
    while c <= iters:
        pos += vel
        c += 1
    posx, posy = coords(pos)
    plt.scatter(posx, posy)
    plt.show()

Solution


In [7]:
iterate(10054)