Log in to get your input and submit your answers.
Day 13: Bus Search
After navigating 42's labyrinthine corridors, you finally picked up your equipment from the Bocal. But it's getting late, and you need to catch the bus home.
City bus operate on rigid timetables: each bus line has an ID number and departs at regular intervals (every X minutes, starting from timestamp 0).
Your puzzle input consists of two lines:
- The first line is your arrival timestamp at the bus stop.
- The second line lists the IDs of running bus. Entries marked
xdenote out-of-service lines that can be ignored.
Part 1
You want to find the earliest bus you can board at or after your arrival timestamp.
Example
Consider this sample input:
939
7,13,x,x,59,x,31,19You arrive at the stop at timestamp 939. The bus departure times after you arrive are:
- Bus 7: departs at 938, then 945 (6-minute wait).
- Bus 13: departs at 936, then 949 (10-minute wait).
- Bus 59: departs at 885, then 944 (5-minute wait).
- Bus 31: departs at 930, then 961 (22-minute wait).
- Bus 19: departs at 931, then 950 (11-minute wait).
The earliest bus is 59, and you only need to wait 5 minutes.
Multiplying the bus ID by the waiting time: 59 × 5 = 295.
Consult your own timetable input. What is the ID of the earliest bus you can take to the airport multiplied by the number of minutes you'll need to wait for that bus?