day 14, just run the race

This commit is contained in:
setop 2024-11-23 00:51:21 +01:00
parent 5c6f10c81e
commit c1e2a28ac5
1 changed files with 41 additions and 0 deletions

41
d14/run.py Normal file
View File

@ -0,0 +1,41 @@
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))