-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
25 lines (20 loc) · 792 Bytes
/
main.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
from itertools import dropwhile
from io_utils import read_file, write_file
def clear_missed_rides(rides, max_time, ctime):
time_left = max_time - ctime
if rides and rides[0].score > time_left:
rides = list(dropwhile(lambda x: x.score > time_left, rides))
return rides
def run_example(input_file, output_file):
print("Reading file: {}\n".format(input_file))
max_time, bonus, cars, rides, cars_nb = read_file(input_file)
for ctime in range(max_time):
cars_idle = 0
for car in cars:
car.drive(rides)
if car.current_ride is None:
cars_idle += 1
rides = clear_missed_rides(rides, max_time, ctime)
if not rides and cars_idle == cars_nb:
break
write_file(cars, output_file)