In [2]:
#!/usr/bin/env python3
In [3]:
class Deer:
def __init__(self, name, flyspeed, flytime, resttime):
self.name = name
self.flyspeed = int(flyspeed)
self.flytime = int(flytime)
self.resttime = int(resttime)
self.points = 0
def distance(self, time):
full = (time // (self.flytime + self.resttime)) * self.flyspeed * self.flytime
rest = min(self.flytime, time % (self.flytime + self.resttime)) * self.flyspeed
return (full+rest)
def receive_award(self):
self.points += 1
def tell_award(self):
return(self.points)
In [4]:
filename = './input'
deers = []
attime = 2503
with open(filename) as f:
for line in f:
deer = name, _, _, speed, _, _, fly, _, _, _, _, _, _, rest, _ = line.split()
deers.append(Deer(deer[0], deer[3], deer[6], deer[13]))
print ("Distance has the winning reindeer:", max(i.distance(attime) for i in deers))
for n in range(1, attime):
furthest = max(i.distance(n) for i in deers)
for i in deers:
if i.distance(n) == furthest:
i.receive_award()
print ("Points for the winning reindeer: ", max(i.tell_award() for i in deers))
In [ ]: