aoc2015/d14/run.py

42 lines
882 B
Python

from math import log10
import sys, os
from dataclasses import dataclass
@dataclass
class Rein:
name: str
speed: int
duration: int
rest: int
distance: int = 0
score: int = 0
D:list[Rein] = []
for l in sys.stdin.readlines():
L = l[:-1].split(" ")
D.append(Rein(L[0],int(L[3]),int(L[6]),int(L[13])))
howlong = int(sys.argv[1])
lead_distance = 0
for t in range(howlong):
# increment each rein
for rein in D:
period = rein.duration + rein.rest
(p, m) = divmod(t, period)
# is flying or at rest ?
if m < rein.duration:
rein.distance += rein.speed
lead_distance = max(lead_distance, rein.distance)
# compute score
for rein in D:
if rein.distance == lead_distance:
rein.score += 1
# part1
print(lead_distance)
# part2
print(max(rein.score for rein in D))