summary refs log tree commit diff stats
path: root/day14.py
diff options
context:
space:
mode:
authorBrian Chu <brianmchu42@gmail.com>2021-12-30 15:11:21 -0800
committerBrian Chu <brianmchu42@gmail.com>2021-12-30 15:11:21 -0800
commite7085453864431ace3ad8f3123b259ed0829ae74 (patch)
tree2ef1fbb0e9d02fc934b5e09d96dd187f3e371ea6 /day14.py
downloadAdventOfCode2015-e7085453864431ace3ad8f3123b259ed0829ae74.tar.gz
all solutions for 2015 main
Diffstat (limited to 'day14.py')
-rw-r--r--day14.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/day14.py b/day14.py
new file mode 100644
index 0000000..a377fa8
--- /dev/null
+++ b/day14.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+from collections import defaultdict
+
+with open('day14.txt') as data:
+    racers = [tuple(map(int, (line[3], line[6], line[-2])))
+              for reindeer in data if (line := reindeer.strip().split())]
+
+def distance(reindeer, time):
+    speed, dur, rest = reindeer
+    total_distance = speed * dur * (time // (dur + rest))
+    remainder = time % (dur + rest)
+    total_distance += speed * remainder if remainder <= dur else speed * dur
+    return total_distance
+
+print(max(map(lambda x: distance(x, 2503), racers)))
+
+def points(reindeer, TOTAL_TIME):
+    scores = defaultdict(int)
+
+    for second in range(1, TOTAL_TIME+1):
+        distances = {deer: distance(deer, second) for deer in reindeer}
+        max_dist = max(distances.values())
+        for deer in distances:
+            if distances[deer] == max_dist:
+                scores[deer] += 1
+    return max(scores.values())
+
+print(points(racers, 2503))