From c1e2a28ac51df1f56b3324a97786d77570ba606f Mon Sep 17 00:00:00 2001 From: setop Date: Sat, 23 Nov 2024 00:51:21 +0100 Subject: [PATCH] day 14, just run the race --- d14/run.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 d14/run.py diff --git a/d14/run.py b/d14/run.py new file mode 100644 index 0000000..4b42e56 --- /dev/null +++ b/d14/run.py @@ -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)) +