#!/usr/bin/env python3
# -*- coding: utf-8 -*-

file = "./input.txt"
Y_TALL = 103
X_WIDE = 101

#file = "./ex.txt"
#Y_TALL = 7
#X_WIDE = 11

from time import time
import re
start_time = time()

def parse_and_go(input_file:str, seconds) -> list[list[int]]:
    global Y_TALL, X_WIDE
    field = []
    for i in range(Y_TALL):
        temp = []
        for j in range(X_WIDE):
            temp.append(0)
        field.append(temp)
    with open(input_file, 'r') as d:
        datei = d.read()
    pat = r'p\=(-?\d+),(-?\d+) v\=(-?\d+),(-?\d+)'
    match = re.findall(pat, datei)
    for m in match:
        x, y, vx, vy = map(int, m)
        # move X seconds
        x = (x + (seconds * vx)) % X_WIDE
        y = (y + (seconds * vy)) % Y_TALL
        field[y][x] += 1
    return field

def print_field(f):
    for r in f:
        for s in r:
            if s == 0:
                print(".", end="")
            else:
                print(s, end="")
        print()


if __name__ == "__main__":
    field_s = parse_and_go(file, 6516)
    print_field(field_s)
    print(f'Runtime: {time()-start_time:.2f} s')