2015 day 14, part 1
This commit is contained in:
parent
2b107ba91d
commit
d1418edbd9
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env python3
|
||||
from collections import namedtuple
|
||||
from math import ceil
|
||||
from operator import itemgetter
|
||||
import fileinput
|
||||
import re
|
||||
|
||||
INPUT_RE = re.compile(r'^(?P<name>[A-Za-z]+) can fly (?P<speed>\d+) km/s for (?P<duration>\d+) seconds, but then must rest for (?P<cooldown>\d+) seconds\.$')
|
||||
RACE_DURATION = 2503
|
||||
|
||||
reindeers = []
|
||||
for line in fileinput.input():
|
||||
data = INPUT_RE.match(line).groupdict()
|
||||
for k in ('speed', 'duration', 'cooldown'):
|
||||
data[k] = int(data[k])
|
||||
reindeers.append(data)
|
||||
|
||||
for reindeer in reindeers:
|
||||
cycle_duration = reindeer['duration'] + reindeer['cooldown']
|
||||
reindeer['distance'] = RACE_DURATION // cycle_duration * reindeer['speed'] * reindeer['duration']
|
||||
reindeer['distance'] += min(RACE_DURATION % cycle_duration, reindeer['duration']) * reindeer['speed']
|
||||
|
||||
print(sorted(map(itemgetter('distance'), reindeers))[-1])
|
Loading…
Reference in New Issue