mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Solution to day 14.
This commit is contained in:
9
day-14/input.txt
Normal file
9
day-14/input.txt
Normal file
@@ -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.
|
||||
34
day-14/solution.py
Normal file
34
day-14/solution.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from __future__ import division, print_function
|
||||
import fileinput
|
||||
import re
|
||||
import itertools
|
||||
from collections import defaultdict
|
||||
|
||||
pattern = re.compile("(\w+) can fly (\d+) km\/s for (\d+) seconds, but then must rest for (\d+) seconds.")
|
||||
|
||||
runners = defaultdict(lambda: 0)
|
||||
runnerData = {}
|
||||
runnerPoints = defaultdict(lambda: 0)
|
||||
|
||||
totalTime = 2503
|
||||
|
||||
for line in fileinput.input():
|
||||
match = pattern.search(line)
|
||||
reindeer, speed, runtime, resttime = match.group(1, 2, 3, 4)
|
||||
speed = int(speed)
|
||||
runtime = int(runtime)
|
||||
resttime = int(resttime)
|
||||
|
||||
runnerData[reindeer] = itertools.cycle([speed] * runtime + [0] * resttime)
|
||||
|
||||
for _ in range(totalTime):
|
||||
for i in runnerData:
|
||||
runners[i] += next(runnerData[i])
|
||||
|
||||
best = max(runners.values())
|
||||
for i in runners:
|
||||
if runners[i] == best:
|
||||
runnerPoints[i] += 1
|
||||
|
||||
print("Fastest runner covered", max(runners.values()))
|
||||
print("Highest score is", max(runnerPoints.values()))
|
||||
Reference in New Issue
Block a user