Skip to content

Commit

Permalink
Add the ones I finished...
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio M committed Dec 15, 2020
1 parent d84b7f9 commit 1d7c1c2
Show file tree
Hide file tree
Showing 6 changed files with 700 additions and 0 deletions.
2 changes: 2 additions & 0 deletions day13.input
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1000677
29,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,41,x,x,x,x,x,x,x,x,x,661,x,x,x,x,x,x,x,x,x,x,x,x,13,17,x,x,x,x,x,x,x,x,23,x,x,x,x,x,x,x,521,x,x,x,x,x,37,x,x,x,x,x,x,x,x,x,x,x,x,19
20 changes: 20 additions & 0 deletions day13.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
input_filename = __file__.split(".")[0] + ".input"
with open(input_filename) as f:
raw = f.read().strip().split("\n")

reach_bustop_at = int(raw[0])
in_service_bus_routes = [int(x) for x in raw[1].split(",") if x != "x"]

earliest = {}
for bus in in_service_bus_routes:
x = 0
while x < reach_bustop_at:
x += bus
earliest[bus] = x

earliest_buses = sorted(earliest.items(), key=lambda x: x[1])
print(earliest_buses)

waiting_time = earliest_buses[0][1] - reach_bustop_at
print(waiting_time)
print(earliest_buses[0][0] * waiting_time)
Loading

0 comments on commit 1d7c1c2

Please sign in to comment.