Solution to day 14.

This commit is contained in:
Bert Peters
2015-12-14 19:22:05 +01:00
parent 7a72d5f5d1
commit 113f97d0ac
2 changed files with 43 additions and 0 deletions

9
day-14/input.txt Normal file
View 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
View 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()))