You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.2 KiB
45 lines
1.2 KiB
file = open('input.txt', 'r')
|
|
|
|
reindeer = {}
|
|
|
|
def tick_reindeer(key):
|
|
runner = reindeer[key]
|
|
|
|
if runner['resting']:
|
|
runner['rest_progress'] += 1
|
|
if runner['rest_progress'] == runner['recovery']:
|
|
runner['rest_progress'] = 0
|
|
runner['resting'] = False
|
|
return
|
|
|
|
runner['distance_travelled'] += runner['speed']
|
|
runner['running_for'] += 1
|
|
|
|
if runner['running_for'] == runner['stamina']:
|
|
runner['running_for'] = 0
|
|
runner['resting'] = True
|
|
|
|
def award_points():
|
|
progress = []
|
|
for key in reindeer:
|
|
progress.append([reindeer[key]['distance_travelled'], key])
|
|
progress = sorted(progress, reverse=True)
|
|
for i in range(0, len(progress)-1):
|
|
if progress[i][0] == progress[0][0]:
|
|
reindeer[progress[i][1]]['points'] += 1
|
|
|
|
|
|
for line in file:
|
|
splits = line.split(' ')
|
|
reindeer.setdefault(splits[0], {'speed' : int(splits[3]), 'stamina': int(splits[6]), 'recovery': int(splits[13]), 'distance_travelled' : 0, 'rest_progress' : 0, 'running_for' : 0, 'resting' : False, 'points' : 0})
|
|
|
|
timer = 0
|
|
while timer != 2503:
|
|
|
|
for key in reindeer:
|
|
tick_reindeer(key)
|
|
|
|
award_points()
|
|
timer += 1
|
|
|
|
print(reindeer)
|