diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2021-11-24 22:25:42 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2021-11-24 22:25:42 +0000 |
commit | a7a6b86002b595bc167af72606b14c67ed1bdf8f (patch) | |
tree | bff94329cf969bd9df68d3b9782fee2107db56c2 /14 | |
download | aoc2015-a7a6b86002b595bc167af72606b14c67ed1bdf8f.tar.gz aoc2015-a7a6b86002b595bc167af72606b14c67ed1bdf8f.tar.xz aoc2015-a7a6b86002b595bc167af72606b14c67ed1bdf8f.zip |
init commit
Diffstat (limited to '14')
-rw-r--r-- | 14/input | 9 | ||||
-rw-r--r-- | 14/solution.py | 43 |
2 files changed, 52 insertions, 0 deletions
diff --git a/14/input b/14/input new file mode 100644 index 0000000..1532578 --- /dev/null +++ b/14/input @@ -0,0 +1,9 @@ +Vixen can fly 8 km/s for 8 seconds, but then must rest for 53 seconds. +Blitzen can fly 13 km/s for 4 seconds, but then must rest for 49 seconds. +Rudolph can fly 20 km/s for 7 seconds, but then must rest for 132 seconds. +Cupid can fly 12 km/s for 4 seconds, but then must rest for 43 seconds. +Donner can fly 9 km/s for 5 seconds, but then must rest for 38 seconds. +Dasher can fly 10 km/s for 4 seconds, but then must rest for 37 seconds. +Comet can fly 3 km/s for 37 seconds, but then must rest for 76 seconds. +Prancer can fly 9 km/s for 12 seconds, but then must rest for 97 seconds. +Dancer can fly 37 km/s for 1 seconds, but then must rest for 36 seconds. diff --git a/14/solution.py b/14/solution.py new file mode 100644 index 0000000..9ce32dd --- /dev/null +++ b/14/solution.py @@ -0,0 +1,43 @@ +from dataclasses import dataclass + +@dataclass +class Reindeer: + name: str + speed: int + fly_time: int + rest_time: int + def distance_after(self, seconds): + cycle_time = self.fly_time + self.rest_time + cycles = seconds // cycle_time + remaining_time = seconds % cycle_time + if remaining_time > self.fly_time: + remaining_time = self.fly_time + return cycles * self.speed * self.fly_time + remaining_time * self.speed + +def part1(reindeer: list[Reindeer]) -> int: + return max(r.distance_after(2503) for r in reindeer) + +def part2(reindeer: list[Reindeer]) -> int: + points = [0] * len(reindeer) + for s in range(1, 2504): + distances = [r.distance_after(s) for r in reindeer] + max_dist = max(distances) + for i, d in enumerate(distances): + if d == max_dist: + points[i] += 1 + return max(points) + +if __name__ == '__main__': + reindeer = [ + Reindeer('Vixen', 8, 8, 53), + Reindeer('Blitzen', 13, 4, 49), + Reindeer('Rudolph', 20, 7, 132), + Reindeer('Cupid', 12, 4, 43), + Reindeer('Donner', 9, 5, 38), + Reindeer('Dasher', 10, 4, 37), + Reindeer('Comet', 3, 37, 76), + Reindeer('Prancer', 9, 12, 97), + Reindeer('Dancer', 37, 1, 36), + ] + print(part1(reindeer)) + print(part2(reindeer)) |