-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solve Day 13 #23
Merged
Merged
Solve Day 13 #23
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov Report
@@ Coverage Diff @@
## main #23 +/- ##
==========================================
+ Coverage 95.08% 95.45% +0.37%
==========================================
Files 17 18 +1
Lines 244 264 +20
Branches 21 21
==========================================
+ Hits 232 252 +20
Misses 6 6
Partials 6 6
Continue to review full report at Codecov.
|
manuphatak
added a commit
that referenced
this pull request
Dec 20, 2020
* origin/main: Solve Day 13 (#23)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Day 13: Shuttle Search
Your ferry can make it safely to a nearby port, but it won't get much further. When you call to book another ship, you discover that no ships embark from that port to your vacation island. You'll need to get from the port to the nearest airport.
Fortunately, a shuttle bus service is available to bring you from the sea port to the airport! Each bus has an ID number that also indicates how often the bus leaves for the airport .
Bus schedules are defined based on a timestamp that measures the number of minutes since some fixed reference point in the past. At timestamp
0
, every bus simultaneously departed from the sea port. After that, each bus travels to the airport, then various other locations, and finally returns to the sea port to repeat its journey forever.The time this loop takes a particular bus is also its ID number: the bus with ID
5
departs from the sea port at timestamps0
,5
,10
,15
, and so on. The bus with ID11
departs at0
,11
,22
,33
, and so on. If you are there when the bus departs, you can ride that bus to the airport!Your notes (your puzzle input) consist of two lines. The first line is your estimate of the earliest timestamp you could depart on a bus . The second line lists the bus IDs that are in service according to the shuttle company; entries that show
x
must be out of service, so you decide to ignore them.To save time once you arrive, your goal is to figure out the earliest bus you can take to the airport . (There will be exactly one such bus.)
For example, suppose you have the following notes:
Here, the earliest timestamp you could depart is
939
, and the bus IDs in service are7
,13
,59
,31
, and19
. Near timestamp939
, these bus IDs depart at the times markedD
:The earliest bus you could take is bus ID
59
. It doesn't depart until timestamp944
, so you would need to wait944 - 939 = 5
minutes before it departs. Multiplying the bus ID by the number of minutes you'd need to wait gives295
.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?
Part Two
The shuttle company is running a contest : one gold coin for anyone that can find the earliest timestamp such that the first bus ID departs at that time and each subsequent listed bus ID departs at that subsequent minute. (The first line in your input is no longer relevant.)
For example, suppose you have the same list of bus IDs as above:
An
x
in the schedule means there are no constraints on what bus IDs must depart at that time.This means you are looking for the earliest timestamp (called
t
) such that:7
departs at timestampt
.13
departs one minute after timestampt
.t
.59
departs four minutes after timestampt
.t
.31
departs six minutes after timestampt
.19
departs seven minutes after timestampt
.The only bus departures that matter are the listed bus IDs at their specific offsets from
t
. Those bus IDs can depart at other times, and other bus IDs can depart at those times. For example, in the list above, because bus ID19
must depart seven minutes after the timestamp at which bus ID7
departs, bus ID7
will always also be departing with bus ID19
at seven minutes after timestampt
.In this example, the earliest timestamp at which this occurs is
1068781
:In the above example, bus ID
7
departs at timestamp1068788
(seven minutes aftert
). This is fine; the only requirement on that minute is that bus ID19
departs then, and it does.Here are some other examples:
17,x,13,19
is3417
.67,7,59,61
first occurs at timestamp754018
.67,x,7,59,61
first occurs at timestamp779210
.67,7,x,59,61
first occurs at timestamp1261476
.1789,37,47,1889
first occurs at timestamp1202161486
.However, with so many bus IDs in your list, surely the actual earliest timestamp will be larger than
100000000000000
!What is the earliest timestamp such that all of the listed bus IDs depart at offsets matching their positions in the list?
Link
https://adventofcode.com/2020/day/13