1
0
Fork 0

2015 day 14, part 1

This commit is contained in:
Lucidiot 2019-11-17 14:22:10 +01:00
parent 2b107ba91d
commit d1418edbd9
Signed by: lucidiot
GPG Key ID: 3358C1CA6906FB8D
1 changed files with 23 additions and 0 deletions

23
2015/14/part1.py Executable file
View File

@ -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])