-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpartOne.py
More file actions
29 lines (19 loc) · 805 Bytes
/
Copy pathpartOne.py
File metadata and controls
29 lines (19 loc) · 805 Bytes
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
from typing import List
class Timetable:
earliest_departure: int
services: List[int]
def __init__(self, earliest_departure: int, services: str):
self.earliest_departure = earliest_departure
self.services = [int(s) for s in services.split(",") if s != "x"]
def parse(instr: str) -> Timetable:
instr = instr.strip().split("\n")
return Timetable(int(instr[0]), instr[1])
def partOne(instr: str) -> int:
timetable = parse(instr)
earliest_times = []
for service in timetable.services:
earliest_times.append(
(service, (int(timetable.earliest_departure / service) + 1) * service)
)
route, earliest_departure = min(earliest_times, key=lambda x: x[1])
return route * (earliest_departure - timetable.earliest_departure)