-
Notifications
You must be signed in to change notification settings - Fork 0
/
14a.py
34 lines (28 loc) · 976 Bytes
/
14a.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Deer:
def __init__(self, name, speed, travel_time, rest_time):
self.name = name
self.speed = speed
self.travel_time = travel_time
self.rest_time = rest_time
self.walking = False
self.time_to_change = 0
self.distance = 0
def start(self):
self.walking = True
self.time_to_change = self.travel_time
def tick(self):
if self.walking:
self.distance += self.speed
self.time_to_change -= 1
if self.time_to_change == 0:
self.walking = not self.walking
self.time_to_change = self.travel_time if self.walking else self.rest_time
ds = []
for line in open('14.txt'):
name, _, _, speed, _, _, travel_time, *_, rest_time, _ = line.split()
d = Deer(name, int(speed), int(travel_time), int(rest_time))
ds.append(d)
[d.start() for d in ds]
for time in range(2503):
[d.tick() for d in ds]
print(max(d.distance for d in ds))