2020 day 13 Added Challenge Description

This commit is contained in:
Burnus 2023-04-07 10:50:40 +02:00
parent 9c29367c46
commit 711fed5cac

View file

@ -1,132 +1,56 @@
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.
As your ferry approaches the sea port, the captain asks for your help again. The computer system that runs this port isn't compatible with the docking program on the ferry, so the docking parameters aren't being correctly initialized in the docking program's memory.
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*.
After a brief inspection, you discover that the sea port's computer system uses a strange [bitmask](https://en.wikipedia.org/wiki/Mask_(computing)) system in its initialization program. Although you don't have the correct decoder chip handy, you can emulate it in software!
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 initialization program (your puzzle input) can either update the bitmask or write a value to memory. Values and memory addresses are both 36-bit unsigned integers. For example, ignoring bitmasks for a moment, a line like `mem[8] = 11` would write the value `11` to memory address `8`.
The time this loop takes a particular bus is also its ID number: the bus with ID `5` departs from the sea port at timestamps `0`, `5`, `10`, `15`, and so on. The bus with ID `11` departs at `0`, `11`, `22`, `33`, and so on. If you are there when the bus departs, you can ride that bus to the airport!
The bitmask is always given as a string of 36 bits, written with the most significant bit (representing `2^35`) on the left and the least significant bit (`2^0`, that is, the `1`s bit) on the right. The current bitmask is applied to values immediately before they are written to memory: a `0` or `1` overwrites the corresponding bit in the value, while an `X` leaves the bit in the value unchanged.
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:
For example, consider the following program:
```
939
7,13,x,x,59,x,31,19
mask = XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
mem[8] = 11
mem[7] = 101
mem[8] = 0
```
Here, the earliest timestamp you could depart is `939`, and the bus IDs in service are `7`, `13`, `59`, `31`, and `19`. Near timestamp `939`, these bus IDs depart at the times marked `D`:
This program starts by specifying a bitmask (`mask = ....`). The mask it specifies will overwrite two bits in every written value: the `2`s bit is overwritten with `0`, and the `64`s bit is overwritten with `1`.
The program then attempts to write the value `11` to memory address `8`. By expanding everything out to individual bits, the mask is applied as follows:
```
time bus 7 bus 13 bus 59 bus 31 bus 19
929 . . . . .
930 . . . D .
931 D . . . D
932 . . . . .
933 . . . . .
934 . . . . .
935 . . . . .
936 . D . . .
937 . . . . .
938 D . . . .
939 . . . . .
940 . . . . .
941 . . . . .
942 . . . . .
943 . . . . .
944 . . D . .
945 D . . . .
946 . . . . .
947 . . . . .
948 . . . . .
949 . D . . .
value: 000000000000000000000000000000001011 (decimal 11)
mask: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
result: 000000000000000000000000000001001001 (decimal 73)
```
The earliest bus you could take is bus ID `59`. It doesn't depart until timestamp `944`, so you would need to wait `944 - 939 = 5` minutes before it departs. Multiplying the bus ID by the number of minutes you'd need to wait gives *`295`*.
*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?*
Your puzzle answer was `2406`.
\--- 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:
So, because of the mask, the value `73` is written to memory address `8` instead. Then, the program tries to write `101` to address `7`:
```
7,13,x,x,59,x,31,19
```
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:
* Bus ID `7` departs at timestamp `t`.
* Bus ID `13` departs one minute after timestamp `t`.
* There are no requirements or restrictions on departures at two or three minutes after timestamp `t`.
* Bus ID `59` departs four minutes after timestamp `t`.
* There are no requirements or restrictions on departures at five minutes after timestamp `t`.
* Bus ID `31` departs six minutes after timestamp `t`.
* Bus ID `19` departs seven minutes after timestamp `t`.
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 ID `19` must depart seven minutes after the timestamp at which bus ID `7` departs, bus ID `7` will always *also* be departing with bus ID `19` at seven minutes after timestamp `t`.
In this example, the earliest timestamp at which this occurs is *`1068781`*:
```
time bus 7 bus 13 bus 59 bus 31 bus 19
1068773 . . . . .
1068774 D . . . .
1068775 . . . . .
1068776 . . . . .
1068777 . . . . .
1068778 . . . . .
1068779 . . . . .
1068780 . . . . .
1068781 D . . . .
1068782 . D . . .
1068783 . . . . .
1068784 . . . . .
1068785 . . D . .
1068786 . . . . .
1068787 . . . D .
1068788 D . . . D
1068789 . . . . .
1068790 . . . . .
1068791 . . . . .
1068792 . . . . .
1068793 . . . . .
1068794 . . . . .
1068795 D D . . .
1068796 . . . . .
1068797 . . . . .
value: 000000000000000000000000000001100101 (decimal 101)
mask: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
result: 000000000000000000000000000001100101 (decimal 101)
```
In the above example, bus ID `7` departs at timestamp `1068788` (seven minutes after `t`). This is fine; the only requirement on that minute is that bus ID `19` departs then, and it does.
This time, the mask has no effect, as the bits it overwrote were already the values the mask tried to set. Finally, the program tries to write `0` to address `8`:
Here are some other examples:
```
value: 000000000000000000000000000000000000 (decimal 0)
mask: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
result: 000000000000000000000000000001000000 (decimal 64)
* The earliest timestamp that matches the list `17,x,13,19` is *`3417`*.
* `67,7,59,61` first occurs at timestamp *`754018`*.
* `67,x,7,59,61` first occurs at timestamp *`779210`*.
* `67,7,x,59,61` first occurs at timestamp *`1261476`*.
* `1789,37,47,1889` first occurs at timestamp *`1202161486`*.
```
However, with so many bus IDs in your list, surely the actual earliest timestamp will be larger than `100000000000000`!
`64` is written to address `8` instead, overwriting the value that was there previously.
*What is the earliest timestamp such that all of the listed bus IDs depart at offsets matching their positions in the list?*
To initialize your ferry's docking program, you need the sum of all values left in memory after the initialization program completes. (The entire 36-bit address space begins initialized to the value `0` at every address.) In the above example, only two values in memory are not zero - `101` (at address `7`) and `64` (at address `8`) - producing a sum of *`165`*.
Your puzzle answer was `225850756401039`.
Execute the initialization program. *What is the sum of all values left in memory after it completes?* (Do not truncate the sum to 36 bits.)
Both parts of this puzzle are complete! They provide two gold stars: \*\*
To begin, [get your puzzle input](14/input).
At this point, you should [return to your Advent calendar](/2020) and try another puzzle.
If you still want to see it, you can [get your puzzle input](13/input).
Answer: