Spaces:
Running
Running
Add problem descriptions
Browse files- day01/problem.txt +67 -0
- day02/problem.txt +53 -0
- day03/problem.txt +35 -0
- day04/problem.txt +63 -0
- day05/problem.txt +87 -0
- day06/problem.txt +175 -0
- day07/problem.txt +44 -0
- day08/problem.txt +111 -0
- day09/problem.txt +64 -0
- day10/problem.txt +113 -0
- day11/problem.txt +57 -0
- day12/problem.txt +135 -0
- day13/problem.txt +71 -0
- day14/problem.txt +121 -0
- day15/problem.txt +404 -0
- day16/problem.txt +131 -0
- day17/problem.txt +74 -0
- day18/problem.txt +87 -0
- day19/problem.txt +76 -0
- day20/problem.txt +176 -0
- day21/problem.txt +105 -0
- day22/problem.txt +111 -0
- day23/problem.txt +83 -0
- day24/problem.txt +189 -0
- day25/problem.txt +120 -0
day01/problem.txt
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 1: Historian Hysteria ---
|
2 |
+
The Chief Historian is always present for the big Christmas sleigh launch, but nobody has seen him in months! Last anyone heard, he was visiting locations that are historically significant to the North Pole; a group of Senior Historians has asked you to accompany them as they check the places they think he was most likely to visit.
|
3 |
+
|
4 |
+
As each location is checked, they will mark it on their list with a star. They figure the Chief Historian must be in one of the first fifty places they'll look, so in order to save Christmas, you need to help them get fifty stars on their list before Santa takes off on December 25th.
|
5 |
+
|
6 |
+
Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
|
7 |
+
|
8 |
+
You haven't even left yet and the group of Elvish Senior Historians has already hit a problem: their list of locations to check is currently empty. Eventually, someone decides that the best place to check first would be the Chief Historian's office.
|
9 |
+
|
10 |
+
Upon pouring into the office, everyone confirms that the Chief Historian is indeed nowhere to be found. Instead, the Elves discover an assortment of notes and lists of historically significant locations! This seems to be the planning the Chief Historian was doing before he left. Perhaps these notes can be used to determine which locations to search?
|
11 |
+
|
12 |
+
Throughout the Chief's office, the historically significant locations are listed not by name but by a unique number called the location ID. To make sure they don't miss anything, The Historians split into two groups, each searching the office and trying to create their own complete list of location IDs.
|
13 |
+
|
14 |
+
There's just one problem: by holding the two lists up side by side (your puzzle input), it quickly becomes clear that the lists aren't very similar. Maybe you can help The Historians reconcile their lists?
|
15 |
+
|
16 |
+
For example:
|
17 |
+
|
18 |
+
3 4
|
19 |
+
4 3
|
20 |
+
2 5
|
21 |
+
1 3
|
22 |
+
3 9
|
23 |
+
3 3
|
24 |
+
Maybe the lists are only off by a small amount! To find out, pair up the numbers and measure how far apart they are. Pair up the smallest number in the left list with the smallest number in the right list, then the second-smallest left number with the second-smallest right number, and so on.
|
25 |
+
|
26 |
+
Within each pair, figure out how far apart the two numbers are; you'll need to add up all of those distances. For example, if you pair up a 3 from the left list with a 7 from the right list, the distance apart is 4; if you pair up a 9 with a 3, the distance apart is 6.
|
27 |
+
|
28 |
+
In the example list above, the pairs and distances would be as follows:
|
29 |
+
|
30 |
+
The smallest number in the left list is 1, and the smallest number in the right list is 3. The distance between them is 2.
|
31 |
+
The second-smallest number in the left list is 2, and the second-smallest number in the right list is another 3. The distance between them is 1.
|
32 |
+
The third-smallest number in both lists is 3, so the distance between them is 0.
|
33 |
+
The next numbers to pair up are 3 and 4, a distance of 1.
|
34 |
+
The fifth-smallest numbers in each list are 3 and 5, a distance of 2.
|
35 |
+
Finally, the largest number in the left list is 4, while the largest number in the right list is 9; these are a distance 5 apart.
|
36 |
+
To find the total distance between the left list and the right list, add up the distances between all of the pairs you found. In the example above, this is 2 + 1 + 0 + 1 + 2 + 5, a total distance of 11!
|
37 |
+
|
38 |
+
Your actual left and right lists contain many location IDs. What is the total distance between your lists?
|
39 |
+
|
40 |
+
--- Part Two ---
|
41 |
+
Your analysis only confirmed what everyone feared: the two lists of location IDs are indeed very different.
|
42 |
+
|
43 |
+
Or are they?
|
44 |
+
|
45 |
+
The Historians can't agree on which group made the mistakes or how to read most of the Chief's handwriting, but in the commotion you notice an interesting detail: a lot of location IDs appear in both lists! Maybe the other numbers aren't location IDs at all but rather misinterpreted handwriting.
|
46 |
+
|
47 |
+
This time, you'll need to figure out exactly how often each number from the left list appears in the right list. Calculate a total similarity score by adding up each number in the left list after multiplying it by the number of times that number appears in the right list.
|
48 |
+
|
49 |
+
Here are the same example lists again:
|
50 |
+
|
51 |
+
3 4
|
52 |
+
4 3
|
53 |
+
2 5
|
54 |
+
1 3
|
55 |
+
3 9
|
56 |
+
3 3
|
57 |
+
For these example lists, here is the process of finding the similarity score:
|
58 |
+
|
59 |
+
The first number in the left list is 3. It appears in the right list three times, so the similarity score increases by 3 * 3 = 9.
|
60 |
+
The second number in the left list is 4. It appears in the right list once, so the similarity score increases by 4 * 1 = 4.
|
61 |
+
The third number in the left list is 2. It does not appear in the right list, so the similarity score does not increase (2 * 0 = 0).
|
62 |
+
The fourth number, 1, also does not appear in the right list.
|
63 |
+
The fifth number, 3, appears in the right list three times; the similarity score increases by 9.
|
64 |
+
The last number, 3, appears in the right list three times; the similarity score again increases by 9.
|
65 |
+
So, for these example lists, the similarity score at the end of this process is 31 (9 + 4 + 0 + 0 + 9 + 9).
|
66 |
+
|
67 |
+
Once again consider your left and right lists. What is their similarity score?
|
day02/problem.txt
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 2: Red-Nosed Reports ---
|
2 |
+
Fortunately, the first location The Historians want to search isn't a long walk from the Chief Historian's office.
|
3 |
+
|
4 |
+
While the Red-Nosed Reindeer nuclear fusion/fission plant appears to contain no sign of the Chief Historian, the engineers there run up to you as soon as they see you. Apparently, they still talk about the time Rudolph was saved through molecular synthesis from a single electron.
|
5 |
+
|
6 |
+
They're quick to add that - since you're already here - they'd really appreciate your help analyzing some unusual data from the Red-Nosed reactor. You turn to check if The Historians are waiting for you, but they seem to have already divided into groups that are currently searching every corner of the facility. You offer to help with the unusual data.
|
7 |
+
|
8 |
+
The unusual data (your puzzle input) consists of many reports, one report per line. Each report is a list of numbers called levels that are separated by spaces. For example:
|
9 |
+
|
10 |
+
7 6 4 2 1
|
11 |
+
1 2 7 8 9
|
12 |
+
9 7 6 2 1
|
13 |
+
1 3 2 4 5
|
14 |
+
8 6 4 4 1
|
15 |
+
1 3 6 7 9
|
16 |
+
This example data contains six reports each containing five levels.
|
17 |
+
|
18 |
+
The engineers are trying to figure out which reports are safe. The Red-Nosed reactor safety systems can only tolerate levels that are either gradually increasing or gradually decreasing. So, a report only counts as safe if both of the following are true:
|
19 |
+
|
20 |
+
The levels are either all increasing or all decreasing.
|
21 |
+
Any two adjacent levels differ by at least one and at most three.
|
22 |
+
In the example above, the reports can be found safe or unsafe by checking those rules:
|
23 |
+
|
24 |
+
7 6 4 2 1: Safe because the levels are all decreasing by 1 or 2.
|
25 |
+
1 2 7 8 9: Unsafe because 2 7 is an increase of 5.
|
26 |
+
9 7 6 2 1: Unsafe because 6 2 is a decrease of 4.
|
27 |
+
1 3 2 4 5: Unsafe because 1 3 is increasing but 3 2 is decreasing.
|
28 |
+
8 6 4 4 1: Unsafe because 4 4 is neither an increase or a decrease.
|
29 |
+
1 3 6 7 9: Safe because the levels are all increasing by 1, 2, or 3.
|
30 |
+
So, in this example, 2 reports are safe.
|
31 |
+
|
32 |
+
Analyze the unusual data from the engineers. How many reports are safe?
|
33 |
+
|
34 |
+
|
35 |
+
--- Part Two ---
|
36 |
+
The engineers are surprised by the low number of safe reports until they realize they forgot to tell you about the Problem Dampener.
|
37 |
+
|
38 |
+
The Problem Dampener is a reactor-mounted module that lets the reactor safety systems tolerate a single bad level in what would otherwise be a safe report. It's like the bad level never happened!
|
39 |
+
|
40 |
+
Now, the same rules apply as before, except if removing a single level from an unsafe report would make it safe, the report instead counts as safe.
|
41 |
+
|
42 |
+
More of the above example's reports are now safe:
|
43 |
+
|
44 |
+
7 6 4 2 1: Safe without removing any level.
|
45 |
+
1 2 7 8 9: Unsafe regardless of which level is removed.
|
46 |
+
9 7 6 2 1: Unsafe regardless of which level is removed.
|
47 |
+
1 3 2 4 5: Safe by removing the second level, 3.
|
48 |
+
8 6 4 4 1: Safe by removing the third level, 4.
|
49 |
+
1 3 6 7 9: Safe without removing any level.
|
50 |
+
Thanks to the Problem Dampener, 4 reports are actually safe!
|
51 |
+
|
52 |
+
Update your analysis by handling situations where the Problem Dampener can remove a single level from unsafe reports. How many reports are now safe?
|
53 |
+
|
day03/problem.txt
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 3: Mull It Over ---
|
2 |
+
"Our computers are having issues, so I have no idea if we have any Chief Historians in stock! You're welcome to check the warehouse, though," says the mildly flustered shopkeeper at the North Pole Toboggan Rental Shop. The Historians head out to take a look.
|
3 |
+
|
4 |
+
The shopkeeper turns to you. "Any chance you can see why our computers are having issues again?"
|
5 |
+
|
6 |
+
The computer appears to be trying to run a program, but its memory (your puzzle input) is corrupted. All of the instructions have been jumbled up!
|
7 |
+
|
8 |
+
It seems like the goal of the program is just to multiply some numbers. It does that with instructions like mul(X,Y), where X and Y are each 1-3 digit numbers. For instance, mul(44,46) multiplies 44 by 46 to get a result of 2024. Similarly, mul(123,4) would multiply 123 by 4.
|
9 |
+
|
10 |
+
However, because the program's memory has been corrupted, there are also many invalid characters that should be ignored, even if they look like part of a mul instruction. Sequences like mul(4*, mul(6,9!, ?(12,34), or mul ( 2 , 4 ) do nothing.
|
11 |
+
|
12 |
+
For example, consider the following section of corrupted memory:
|
13 |
+
|
14 |
+
xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))
|
15 |
+
Only the four highlighted sections are real mul instructions. Adding up the result of each instruction produces 161 (2*4 + 5*5 + 11*8 + 8*5).
|
16 |
+
|
17 |
+
Scan the corrupted memory for uncorrupted mul instructions. What do you get if you add up all of the results of the multiplications?
|
18 |
+
|
19 |
+
--- Part Two ---
|
20 |
+
As you scan through the corrupted memory, you notice that some of the conditional statements are also still intact. If you handle some of the uncorrupted conditional statements in the program, you might be able to get an even more accurate result.
|
21 |
+
|
22 |
+
There are two new instructions you'll need to handle:
|
23 |
+
|
24 |
+
The do() instruction enables future mul instructions.
|
25 |
+
The don't() instruction disables future mul instructions.
|
26 |
+
Only the most recent do() or don't() instruction applies. At the beginning of the program, mul instructions are enabled.
|
27 |
+
|
28 |
+
For example:
|
29 |
+
|
30 |
+
xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))
|
31 |
+
This corrupted memory is similar to the example from before, but this time the mul(5,5) and mul(11,8) instructions are disabled because there is a don't() instruction before them. The other mul instructions function normally, including the one at the end that gets re-enabled by a do() instruction.
|
32 |
+
|
33 |
+
This time, the sum of the results is 48 (2*4 + 8*5).
|
34 |
+
|
35 |
+
Handle the new instructions; what do you get if you add up all of the results of just the enabled multiplications?
|
day04/problem.txt
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 4: Ceres Search ---
|
2 |
+
"Looks like the Chief's not here. Next!" One of The Historians pulls out a device and pushes the only button on it. After a brief flash, you recognize the interior of the Ceres monitoring station!
|
3 |
+
|
4 |
+
As the search for the Chief continues, a small Elf who lives on the station tugs on your shirt; she'd like to know if you could help her with her word search (your puzzle input). She only has to find one word: XMAS.
|
5 |
+
|
6 |
+
This word search allows words to be horizontal, vertical, diagonal, written backwards, or even overlapping other words. It's a little unusual, though, as you don't merely need to find one instance of XMAS - you need to find all of them. Here are a few ways XMAS might appear, where irrelevant characters have been replaced with .:
|
7 |
+
|
8 |
+
..X...
|
9 |
+
.SAMX.
|
10 |
+
.A..A.
|
11 |
+
XMAS.S
|
12 |
+
.X....
|
13 |
+
The actual word search will be full of letters instead. For example:
|
14 |
+
|
15 |
+
MMMSXXMASM
|
16 |
+
MSAMXMSMSA
|
17 |
+
AMXSXMAAMM
|
18 |
+
MSAMASMSMX
|
19 |
+
XMASAMXAMM
|
20 |
+
XXAMMXXAMA
|
21 |
+
SMSMSASXSS
|
22 |
+
SAXAMASAAA
|
23 |
+
MAMMMXMMMM
|
24 |
+
MXMXAXMASX
|
25 |
+
In this word search, XMAS occurs a total of 18 times; here's the same word search again, but where letters not involved in any XMAS have been replaced with .:
|
26 |
+
|
27 |
+
....XXMAS.
|
28 |
+
.SAMXMS...
|
29 |
+
...S..A...
|
30 |
+
..A.A.MS.X
|
31 |
+
XMASAMX.MM
|
32 |
+
X.....XA.A
|
33 |
+
S.S.S.S.SS
|
34 |
+
.A.A.A.A.A
|
35 |
+
..M.M.M.MM
|
36 |
+
.X.X.XMASX
|
37 |
+
Take a look at the little Elf's word search. How many times does XMAS appear?
|
38 |
+
|
39 |
+
--- Part Two ---
|
40 |
+
The Elf looks quizzically at you. Did you misunderstand the assignment?
|
41 |
+
|
42 |
+
Looking for the instructions, you flip over the word search to find that this isn't actually an XMAS puzzle; it's an X-MAS puzzle in which you're supposed to find two MAS in the shape of an X. One way to achieve that is like this:
|
43 |
+
|
44 |
+
M.S
|
45 |
+
.A.
|
46 |
+
M.S
|
47 |
+
Irrelevant characters have again been replaced with . in the above diagram. Within the X, each MAS can be written forwards or backwards.
|
48 |
+
|
49 |
+
Here's the same example from before, but this time all of the X-MASes have been kept instead:
|
50 |
+
|
51 |
+
.M.S......
|
52 |
+
..A..MSMS.
|
53 |
+
.M.S.MAA..
|
54 |
+
..A.ASMSM.
|
55 |
+
.M.S.M....
|
56 |
+
..........
|
57 |
+
S.S.S.S.S.
|
58 |
+
.A.A.A.A..
|
59 |
+
M.M.M.M.M.
|
60 |
+
..........
|
61 |
+
In this example, an X-MAS appears 9 times.
|
62 |
+
|
63 |
+
Flip the word search from the instructions back over to the word search side and try again. How many times does an X-MAS appear?
|
day05/problem.txt
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 5: Print Queue ---
|
2 |
+
Satisfied with their search on Ceres, the squadron of scholars suggests subsequently scanning the stationery stacks of sub-basement 17.
|
3 |
+
|
4 |
+
The North Pole printing department is busier than ever this close to Christmas, and while The Historians continue their search of this historically significant facility, an Elf operating a very familiar printer beckons you over.
|
5 |
+
|
6 |
+
The Elf must recognize you, because they waste no time explaining that the new sleigh launch safety manual updates won't print correctly. Failure to update the safety manuals would be dire indeed, so you offer your services.
|
7 |
+
|
8 |
+
Safety protocols clearly indicate that new pages for the safety manuals must be printed in a very specific order. The notation X|Y means that if both page number X and page number Y are to be produced as part of an update, page number X must be printed at some point before page number Y.
|
9 |
+
|
10 |
+
The Elf has for you both the page ordering rules and the pages to produce in each update (your puzzle input), but can't figure out whether each update has the pages in the right order.
|
11 |
+
|
12 |
+
For example:
|
13 |
+
|
14 |
+
47|53
|
15 |
+
97|13
|
16 |
+
97|61
|
17 |
+
97|47
|
18 |
+
75|29
|
19 |
+
61|13
|
20 |
+
75|53
|
21 |
+
29|13
|
22 |
+
97|29
|
23 |
+
53|29
|
24 |
+
61|53
|
25 |
+
97|53
|
26 |
+
61|29
|
27 |
+
47|13
|
28 |
+
75|47
|
29 |
+
97|75
|
30 |
+
47|61
|
31 |
+
75|61
|
32 |
+
47|29
|
33 |
+
75|13
|
34 |
+
53|13
|
35 |
+
|
36 |
+
75,47,61,53,29
|
37 |
+
97,61,53,29,13
|
38 |
+
75,29,13
|
39 |
+
75,97,47,61,53
|
40 |
+
61,13,29
|
41 |
+
97,13,75,29,47
|
42 |
+
The first section specifies the page ordering rules, one per line. The first rule, 47|53, means that if an update includes both page number 47 and page number 53, then page number 47 must be printed at some point before page number 53. (47 doesn't necessarily need to be immediately before 53; other pages are allowed to be between them.)
|
43 |
+
|
44 |
+
The second section specifies the page numbers of each update. Because most safety manuals are different, the pages needed in the updates are different too. The first update, 75,47,61,53,29, means that the update consists of page numbers 75, 47, 61, 53, and 29.
|
45 |
+
|
46 |
+
To get the printers going as soon as possible, start by identifying which updates are already in the right order.
|
47 |
+
|
48 |
+
In the above example, the first update (75,47,61,53,29) is in the right order:
|
49 |
+
|
50 |
+
75 is correctly first because there are rules that put each other page after it: 75|47, 75|61, 75|53, and 75|29.
|
51 |
+
47 is correctly second because 75 must be before it (75|47) and every other page must be after it according to 47|61, 47|53, and 47|29.
|
52 |
+
61 is correctly in the middle because 75 and 47 are before it (75|61 and 47|61) and 53 and 29 are after it (61|53 and 61|29).
|
53 |
+
53 is correctly fourth because it is before page number 29 (53|29).
|
54 |
+
29 is the only page left and so is correctly last.
|
55 |
+
Because the first update does not include some page numbers, the ordering rules involving those missing page numbers are ignored.
|
56 |
+
|
57 |
+
The second and third updates are also in the correct order according to the rules. Like the first update, they also do not include every page number, and so only some of the ordering rules apply - within each update, the ordering rules that involve missing page numbers are not used.
|
58 |
+
|
59 |
+
The fourth update, 75,97,47,61,53, is not in the correct order: it would print 75 before 97, which violates the rule 97|75.
|
60 |
+
|
61 |
+
The fifth update, 61,13,29, is also not in the correct order, since it breaks the rule 29|13.
|
62 |
+
|
63 |
+
The last update, 97,13,75,29,47, is not in the correct order due to breaking several rules.
|
64 |
+
|
65 |
+
For some reason, the Elves also need to know the middle page number of each update being printed. Because you are currently only printing the correctly-ordered updates, you will need to find the middle page number of each correctly-ordered update. In the above example, the correctly-ordered updates are:
|
66 |
+
|
67 |
+
75,47,61,53,29
|
68 |
+
97,61,53,29,13
|
69 |
+
75,29,13
|
70 |
+
These have middle page numbers of 61, 53, and 29 respectively. Adding these page numbers together gives 143.
|
71 |
+
|
72 |
+
Of course, you'll need to be careful: the actual list of page ordering rules is bigger and more complicated than the above example.
|
73 |
+
|
74 |
+
Determine which updates are already in the correct order. What do you get if you add up the middle page number from those correctly-ordered updates?
|
75 |
+
|
76 |
+
--- Part Two ---
|
77 |
+
While the Elves get to work printing the correctly-ordered updates, you have a little time to fix the rest of them.
|
78 |
+
|
79 |
+
For each of the incorrectly-ordered updates, use the page ordering rules to put the page numbers in the right order. For the above example, here are the three incorrectly-ordered updates and their correct orderings:
|
80 |
+
|
81 |
+
75,97,47,61,53 becomes 97,75,47,61,53.
|
82 |
+
61,13,29 becomes 61,29,13.
|
83 |
+
97,13,75,29,47 becomes 97,75,47,29,13.
|
84 |
+
After taking only the incorrectly-ordered updates and ordering them correctly, their middle page numbers are 47, 29, and 47. Adding these together produces 123.
|
85 |
+
|
86 |
+
Find the updates which are not in the correct order. What do you get if you add up the middle page numbers after correctly ordering just those updates?
|
87 |
+
|
day06/problem.txt
ADDED
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 6: Guard Gallivant ---
|
2 |
+
The Historians use their fancy device again, this time to whisk you all away to the North Pole prototype suit manufacturing lab... in the year 1518! It turns out that having direct access to history is very convenient for a group of historians.
|
3 |
+
|
4 |
+
You still have to be careful of time paradoxes, and so it will be important to avoid anyone from 1518 while The Historians search for the Chief. Unfortunately, a single guard is patrolling this part of the lab.
|
5 |
+
|
6 |
+
Maybe you can work out where the guard will go ahead of time so that The Historians can search safely?
|
7 |
+
|
8 |
+
You start by making a map (your puzzle input) of the situation. For example:
|
9 |
+
|
10 |
+
....#.....
|
11 |
+
.........#
|
12 |
+
..........
|
13 |
+
..#.......
|
14 |
+
.......#..
|
15 |
+
..........
|
16 |
+
.#..^.....
|
17 |
+
........#.
|
18 |
+
#.........
|
19 |
+
......#...
|
20 |
+
The map shows the current position of the guard with ^ (to indicate the guard is currently facing up from the perspective of the map). Any obstructions - crates, desks, alchemical reactors, etc. - are shown as #.
|
21 |
+
|
22 |
+
Lab guards in 1518 follow a very strict patrol protocol which involves repeatedly following these steps:
|
23 |
+
|
24 |
+
If there is something directly in front of you, turn right 90 degrees.
|
25 |
+
Otherwise, take a step forward.
|
26 |
+
Following the above protocol, the guard moves up several times until she reaches an obstacle (in this case, a pile of failed suit prototypes):
|
27 |
+
|
28 |
+
....#.....
|
29 |
+
....^....#
|
30 |
+
..........
|
31 |
+
..#.......
|
32 |
+
.......#..
|
33 |
+
..........
|
34 |
+
.#........
|
35 |
+
........#.
|
36 |
+
#.........
|
37 |
+
......#...
|
38 |
+
Because there is now an obstacle in front of the guard, she turns right before continuing straight in her new facing direction:
|
39 |
+
|
40 |
+
....#.....
|
41 |
+
........>#
|
42 |
+
..........
|
43 |
+
..#.......
|
44 |
+
.......#..
|
45 |
+
..........
|
46 |
+
.#........
|
47 |
+
........#.
|
48 |
+
#.........
|
49 |
+
......#...
|
50 |
+
Reaching another obstacle (a spool of several very long polymers), she turns right again and continues downward:
|
51 |
+
|
52 |
+
....#.....
|
53 |
+
.........#
|
54 |
+
..........
|
55 |
+
..#.......
|
56 |
+
.......#..
|
57 |
+
..........
|
58 |
+
.#......v.
|
59 |
+
........#.
|
60 |
+
#.........
|
61 |
+
......#...
|
62 |
+
This process continues for a while, but the guard eventually leaves the mapped area (after walking past a tank of universal solvent):
|
63 |
+
|
64 |
+
....#.....
|
65 |
+
.........#
|
66 |
+
..........
|
67 |
+
..#.......
|
68 |
+
.......#..
|
69 |
+
..........
|
70 |
+
.#........
|
71 |
+
........#.
|
72 |
+
#.........
|
73 |
+
......#v..
|
74 |
+
By predicting the guard's route, you can determine which specific positions in the lab will be in the patrol path. Including the guard's starting position, the positions visited by the guard before leaving the area are marked with an X:
|
75 |
+
|
76 |
+
....#.....
|
77 |
+
....XXXXX#
|
78 |
+
....X...X.
|
79 |
+
..#.X...X.
|
80 |
+
..XXXXX#X.
|
81 |
+
..X.X.X.X.
|
82 |
+
.#XXXXXXX.
|
83 |
+
.XXXXXXX#.
|
84 |
+
#XXXXXXX..
|
85 |
+
......#X..
|
86 |
+
In this example, the guard will visit 41 distinct positions on your map.
|
87 |
+
|
88 |
+
Predict the path of the guard. How many distinct positions will the guard visit before leaving the mapped area?
|
89 |
+
|
90 |
+
--- Part Two ---
|
91 |
+
While The Historians begin working around the guard's patrol route, you borrow their fancy device and step outside the lab. From the safety of a supply closet, you time travel through the last few months and record the nightly status of the lab's guard post on the walls of the closet.
|
92 |
+
|
93 |
+
Returning after what seems like only a few seconds to The Historians, they explain that the guard's patrol area is simply too large for them to safely search the lab without getting caught.
|
94 |
+
|
95 |
+
Fortunately, they are pretty sure that adding a single new obstruction won't cause a time paradox. They'd like to place the new obstruction in such a way that the guard will get stuck in a loop, making the rest of the lab safe to search.
|
96 |
+
|
97 |
+
To have the lowest chance of creating a time paradox, The Historians would like to know all of the possible positions for such an obstruction. The new obstruction can't be placed at the guard's starting position - the guard is there right now and would notice.
|
98 |
+
|
99 |
+
In the above example, there are only 6 different positions where a new obstruction would cause the guard to get stuck in a loop. The diagrams of these six situations use O to mark the new obstruction, | to show a position where the guard moves up/down, - to show a position where the guard moves left/right, and + to show a position where the guard moves both up/down and left/right.
|
100 |
+
|
101 |
+
Option one, put a printing press next to the guard's starting position:
|
102 |
+
|
103 |
+
....#.....
|
104 |
+
....+---+#
|
105 |
+
....|...|.
|
106 |
+
..#.|...|.
|
107 |
+
....|..#|.
|
108 |
+
....|...|.
|
109 |
+
.#.O^---+.
|
110 |
+
........#.
|
111 |
+
#.........
|
112 |
+
......#...
|
113 |
+
Option two, put a stack of failed suit prototypes in the bottom right quadrant of the mapped area:
|
114 |
+
|
115 |
+
....#.....
|
116 |
+
....+---+#
|
117 |
+
....|...|.
|
118 |
+
..#.|...|.
|
119 |
+
..+-+-+#|.
|
120 |
+
..|.|.|.|.
|
121 |
+
.#+-^-+-+.
|
122 |
+
......O.#.
|
123 |
+
#.........
|
124 |
+
......#...
|
125 |
+
Option three, put a crate of chimney-squeeze prototype fabric next to the standing desk in the bottom right quadrant:
|
126 |
+
|
127 |
+
....#.....
|
128 |
+
....+---+#
|
129 |
+
....|...|.
|
130 |
+
..#.|...|.
|
131 |
+
..+-+-+#|.
|
132 |
+
..|.|.|.|.
|
133 |
+
.#+-^-+-+.
|
134 |
+
.+----+O#.
|
135 |
+
#+----+...
|
136 |
+
......#...
|
137 |
+
Option four, put an alchemical retroencabulator near the bottom left corner:
|
138 |
+
|
139 |
+
....#.....
|
140 |
+
....+---+#
|
141 |
+
....|...|.
|
142 |
+
..#.|...|.
|
143 |
+
..+-+-+#|.
|
144 |
+
..|.|.|.|.
|
145 |
+
.#+-^-+-+.
|
146 |
+
..|...|.#.
|
147 |
+
#O+---+...
|
148 |
+
......#...
|
149 |
+
Option five, put the alchemical retroencabulator a bit to the right instead:
|
150 |
+
|
151 |
+
....#.....
|
152 |
+
....+---+#
|
153 |
+
....|...|.
|
154 |
+
..#.|...|.
|
155 |
+
..+-+-+#|.
|
156 |
+
..|.|.|.|.
|
157 |
+
.#+-^-+-+.
|
158 |
+
....|.|.#.
|
159 |
+
#..O+-+...
|
160 |
+
......#...
|
161 |
+
Option six, put a tank of sovereign glue right next to the tank of universal solvent:
|
162 |
+
|
163 |
+
....#.....
|
164 |
+
....+---+#
|
165 |
+
....|...|.
|
166 |
+
..#.|...|.
|
167 |
+
..+-+-+#|.
|
168 |
+
..|.|.|.|.
|
169 |
+
.#+-^-+-+.
|
170 |
+
.+----++#.
|
171 |
+
#+----++..
|
172 |
+
......#O..
|
173 |
+
It doesn't really matter what you choose to use as an obstacle so long as you and The Historians can put it into position without the guard noticing. The important thing is having enough options that you can find one that minimizes time paradoxes, and in this example, there are 6 different positions you could choose.
|
174 |
+
|
175 |
+
You need to get the guard stuck in a loop by adding a single new obstruction. How many different positions could you choose for this obstruction?
|
day07/problem.txt
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 7: Bridge Repair ---
|
2 |
+
The Historians take you to a familiar rope bridge over a river in the middle of a jungle. The Chief isn't on this side of the bridge, though; maybe he's on the other side?
|
3 |
+
|
4 |
+
When you go to cross the bridge, you notice a group of engineers trying to repair it. (Apparently, it breaks pretty frequently.) You won't be able to cross until it's fixed.
|
5 |
+
|
6 |
+
You ask how long it'll take; the engineers tell you that it only needs final calibrations, but some young elephants were playing nearby and stole all the operators from their calibration equations! They could finish the calibrations if only someone could determine which test values could possibly be produced by placing any combination of operators into their calibration equations (your puzzle input).
|
7 |
+
|
8 |
+
For example:
|
9 |
+
|
10 |
+
190: 10 19
|
11 |
+
3267: 81 40 27
|
12 |
+
83: 17 5
|
13 |
+
156: 15 6
|
14 |
+
7290: 6 8 6 15
|
15 |
+
161011: 16 10 13
|
16 |
+
192: 17 8 14
|
17 |
+
21037: 9 7 18 13
|
18 |
+
292: 11 6 16 20
|
19 |
+
Each line represents a single equation. The test value appears before the colon on each line; it is your job to determine whether the remaining numbers can be combined with operators to produce the test value.
|
20 |
+
|
21 |
+
Operators are always evaluated left-to-right, not according to precedence rules. Furthermore, numbers in the equations cannot be rearranged. Glancing into the jungle, you can see elephants holding two different types of operators: add (+) and multiply (*).
|
22 |
+
|
23 |
+
Only three of the above equations can be made true by inserting operators:
|
24 |
+
|
25 |
+
190: 10 19 has only one position that accepts an operator: between 10 and 19. Choosing + would give 29, but choosing * would give the test value (10 * 19 = 190).
|
26 |
+
3267: 81 40 27 has two positions for operators. Of the four possible configurations of the operators, two cause the right side to match the test value: 81 + 40 * 27 and 81 * 40 + 27 both equal 3267 (when evaluated left-to-right)!
|
27 |
+
292: 11 6 16 20 can be solved in exactly one way: 11 + 6 * 16 + 20.
|
28 |
+
The engineers just need the total calibration result, which is the sum of the test values from just the equations that could possibly be true. In the above example, the sum of the test values for the three equations listed above is 3749.
|
29 |
+
|
30 |
+
Determine which equations could possibly be true. What is their total calibration result?
|
31 |
+
|
32 |
+
--- Part Two ---
|
33 |
+
The engineers seem concerned; the total calibration result you gave them is nowhere close to being within safety tolerances. Just then, you spot your mistake: some well-hidden elephants are holding a third type of operator.
|
34 |
+
|
35 |
+
The concatenation operator (||) combines the digits from its left and right inputs into a single number. For example, 12 || 345 would become 12345. All operators are still evaluated left-to-right.
|
36 |
+
|
37 |
+
Now, apart from the three equations that could be made true using only addition and multiplication, the above example has three more equations that can be made true by inserting operators:
|
38 |
+
|
39 |
+
156: 15 6 can be made true through a single concatenation: 15 || 6 = 156.
|
40 |
+
7290: 6 8 6 15 can be made true using 6 * 8 || 6 * 15.
|
41 |
+
192: 17 8 14 can be made true using 17 || 8 + 14.
|
42 |
+
Adding up all six test values (the three that could be made before using only + and * plus the new three that can now be made by also using ||) produces the new total calibration result of 11387.
|
43 |
+
|
44 |
+
Using your new knowledge of elephant hiding spots, determine which equations could possibly be true. What is their total calibration result?
|
day08/problem.txt
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 8: Resonant Collinearity ---
|
2 |
+
You find yourselves on the roof of a top-secret Easter Bunny installation.
|
3 |
+
|
4 |
+
While The Historians do their thing, you take a look at the familiar huge antenna. Much to your surprise, it seems to have been reconfigured to emit a signal that makes people 0.1% more likely to buy Easter Bunny brand Imitation Mediocre Chocolate as a Christmas gift! Unthinkable!
|
5 |
+
|
6 |
+
Scanning across the city, you find that there are actually many such antennas. Each antenna is tuned to a specific frequency indicated by a single lowercase letter, uppercase letter, or digit. You create a map (your puzzle input) of these antennas. For example:
|
7 |
+
|
8 |
+
............
|
9 |
+
........0...
|
10 |
+
.....0......
|
11 |
+
.......0....
|
12 |
+
....0.......
|
13 |
+
......A.....
|
14 |
+
............
|
15 |
+
............
|
16 |
+
........A...
|
17 |
+
.........A..
|
18 |
+
............
|
19 |
+
............
|
20 |
+
The signal only applies its nefarious effect at specific antinodes based on the resonant frequencies of the antennas. In particular, an antinode occurs at any point that is perfectly in line with two antennas of the same frequency - but only when one of the antennas is twice as far away as the other. This means that for any pair of antennas with the same frequency, there are two antinodes, one on either side of them.
|
21 |
+
|
22 |
+
So, for these two antennas with frequency a, they create the two antinodes marked with #:
|
23 |
+
|
24 |
+
..........
|
25 |
+
...#......
|
26 |
+
..........
|
27 |
+
....a.....
|
28 |
+
..........
|
29 |
+
.....a....
|
30 |
+
..........
|
31 |
+
......#...
|
32 |
+
..........
|
33 |
+
..........
|
34 |
+
Adding a third antenna with the same frequency creates several more antinodes. It would ideally add four antinodes, but two are off the right side of the map, so instead it adds only two:
|
35 |
+
|
36 |
+
..........
|
37 |
+
...#......
|
38 |
+
#.........
|
39 |
+
....a.....
|
40 |
+
........a.
|
41 |
+
.....a....
|
42 |
+
..#.......
|
43 |
+
......#...
|
44 |
+
..........
|
45 |
+
..........
|
46 |
+
Antennas with different frequencies don't create antinodes; A and a count as different frequencies. However, antinodes can occur at locations that contain antennas. In this diagram, the lone antenna with frequency capital A creates no antinodes but has a lowercase-a-frequency antinode at its location:
|
47 |
+
|
48 |
+
..........
|
49 |
+
...#......
|
50 |
+
#.........
|
51 |
+
....a.....
|
52 |
+
........a.
|
53 |
+
.....a....
|
54 |
+
..#.......
|
55 |
+
......A...
|
56 |
+
..........
|
57 |
+
..........
|
58 |
+
The first example has antennas with two different frequencies, so the antinodes they create look like this, plus an antinode overlapping the topmost A-frequency antenna:
|
59 |
+
|
60 |
+
......#....#
|
61 |
+
...#....0...
|
62 |
+
....#0....#.
|
63 |
+
..#....0....
|
64 |
+
....0....#..
|
65 |
+
.#....A.....
|
66 |
+
...#........
|
67 |
+
#......#....
|
68 |
+
........A...
|
69 |
+
.........A..
|
70 |
+
..........#.
|
71 |
+
..........#.
|
72 |
+
Because the topmost A-frequency antenna overlaps with a 0-frequency antinode, there are 14 total unique locations that contain an antinode within the bounds of the map.
|
73 |
+
|
74 |
+
Calculate the impact of the signal. How many unique locations within the bounds of the map contain an antinode?
|
75 |
+
|
76 |
+
--- Part Two ---
|
77 |
+
Watching over your shoulder as you work, one of The Historians asks if you took the effects of resonant harmonics into your calculations.
|
78 |
+
|
79 |
+
Whoops!
|
80 |
+
|
81 |
+
After updating your model, it turns out that an antinode occurs at any grid position exactly in line with at least two antennas of the same frequency, regardless of distance. This means that some of the new antinodes will occur at the position of each antenna (unless that antenna is the only one of its frequency).
|
82 |
+
|
83 |
+
So, these three T-frequency antennas now create many antinodes:
|
84 |
+
|
85 |
+
T....#....
|
86 |
+
...T......
|
87 |
+
.T....#...
|
88 |
+
.........#
|
89 |
+
..#.......
|
90 |
+
..........
|
91 |
+
...#......
|
92 |
+
..........
|
93 |
+
....#.....
|
94 |
+
..........
|
95 |
+
In fact, the three T-frequency antennas are all exactly in line with two antennas, so they are all also antinodes! This brings the total number of antinodes in the above example to 9.
|
96 |
+
|
97 |
+
The original example now has 34 antinodes, including the antinodes that appear on every antenna:
|
98 |
+
|
99 |
+
##....#....#
|
100 |
+
.#.#....0...
|
101 |
+
..#.#0....#.
|
102 |
+
..##...0....
|
103 |
+
....0....#..
|
104 |
+
.#...#A....#
|
105 |
+
...#..#.....
|
106 |
+
#....#.#....
|
107 |
+
..#.....A...
|
108 |
+
....#....A..
|
109 |
+
.#........#.
|
110 |
+
...#......##
|
111 |
+
Calculate the impact of the signal using this updated model. How many unique locations within the bounds of the map contain an antinode?
|
day09/problem.txt
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 9: Disk Fragmenter ---
|
2 |
+
Another push of the button leaves you in the familiar hallways of some friendly amphipods! Good thing you each somehow got your own personal mini submarine. The Historians jet away in search of the Chief, mostly by driving directly into walls.
|
3 |
+
|
4 |
+
While The Historians quickly figure out how to pilot these things, you notice an amphipod in the corner struggling with his computer. He's trying to make more contiguous free space by compacting all of the files, but his program isn't working; you offer to help.
|
5 |
+
|
6 |
+
He shows you the disk map (your puzzle input) he's already generated. For example:
|
7 |
+
|
8 |
+
2333133121414131402
|
9 |
+
The disk map uses a dense format to represent the layout of files and free space on the disk. The digits alternate between indicating the length of a file and the length of free space.
|
10 |
+
|
11 |
+
So, a disk map like 12345 would represent a one-block file, two blocks of free space, a three-block file, four blocks of free space, and then a five-block file. A disk map like 90909 would represent three nine-block files in a row (with no free space between them).
|
12 |
+
|
13 |
+
Each file on disk also has an ID number based on the order of the files as they appear before they are rearranged, starting with ID 0. So, the disk map 12345 has three files: a one-block file with ID 0, a three-block file with ID 1, and a five-block file with ID 2. Using one character for each block where digits are the file ID and . is free space, the disk map 12345 represents these individual blocks:
|
14 |
+
|
15 |
+
0..111....22222
|
16 |
+
The first example above, 2333133121414131402, represents these individual blocks:
|
17 |
+
|
18 |
+
00...111...2...333.44.5555.6666.777.888899
|
19 |
+
The amphipod would like to move file blocks one at a time from the end of the disk to the leftmost free space block (until there are no gaps remaining between file blocks). For the disk map 12345, the process looks like this:
|
20 |
+
|
21 |
+
0..111....22222
|
22 |
+
02.111....2222.
|
23 |
+
022111....222..
|
24 |
+
0221112...22...
|
25 |
+
02211122..2....
|
26 |
+
022111222......
|
27 |
+
The first example requires a few more steps:
|
28 |
+
|
29 |
+
00...111...2...333.44.5555.6666.777.888899
|
30 |
+
009..111...2...333.44.5555.6666.777.88889.
|
31 |
+
0099.111...2...333.44.5555.6666.777.8888..
|
32 |
+
00998111...2...333.44.5555.6666.777.888...
|
33 |
+
009981118..2...333.44.5555.6666.777.88....
|
34 |
+
0099811188.2...333.44.5555.6666.777.8.....
|
35 |
+
009981118882...333.44.5555.6666.777.......
|
36 |
+
0099811188827..333.44.5555.6666.77........
|
37 |
+
00998111888277.333.44.5555.6666.7.........
|
38 |
+
009981118882777333.44.5555.6666...........
|
39 |
+
009981118882777333644.5555.666............
|
40 |
+
00998111888277733364465555.66.............
|
41 |
+
0099811188827773336446555566..............
|
42 |
+
The final step of this file-compacting process is to update the filesystem checksum. To calculate the checksum, add up the result of multiplying each of these blocks' position with the file ID number it contains. The leftmost block is in position 0. If a block contains free space, skip it instead.
|
43 |
+
|
44 |
+
Continuing the first example, the first few blocks' position multiplied by its file ID number are 0 * 0 = 0, 1 * 0 = 0, 2 * 9 = 18, 3 * 9 = 27, 4 * 8 = 32, and so on. In this example, the checksum is the sum of these, 1928.
|
45 |
+
|
46 |
+
Compact the amphipod's hard drive using the process he requested. What is the resulting filesystem checksum? (Be careful copy/pasting the input for this puzzle; it is a single, very long line.)
|
47 |
+
|
48 |
+
--- Part Two ---
|
49 |
+
Upon completion, two things immediately become clear. First, the disk definitely has a lot more contiguous free space, just like the amphipod hoped. Second, the computer is running much more slowly! Maybe introducing all of that file system fragmentation was a bad idea?
|
50 |
+
|
51 |
+
The eager amphipod already has a new plan: rather than move individual blocks, he'd like to try compacting the files on his disk by moving whole files instead.
|
52 |
+
|
53 |
+
This time, attempt to move whole files to the leftmost span of free space blocks that could fit the file. Attempt to move each file exactly once in order of decreasing file ID number starting with the file with the highest file ID number. If there is no span of free space to the left of a file that is large enough to fit the file, the file does not move.
|
54 |
+
|
55 |
+
The first example from above now proceeds differently:
|
56 |
+
|
57 |
+
00...111...2...333.44.5555.6666.777.888899
|
58 |
+
0099.111...2...333.44.5555.6666.777.8888..
|
59 |
+
0099.1117772...333.44.5555.6666.....8888..
|
60 |
+
0099.111777244.333....5555.6666.....8888..
|
61 |
+
00992111777.44.333....5555.6666.....8888..
|
62 |
+
The process of updating the filesystem checksum is the same; now, this example's checksum would be 2858.
|
63 |
+
|
64 |
+
Start over, now compacting the amphipod's hard drive using this new method instead. What is the resulting filesystem checksum?
|
day10/problem.txt
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 10: Hoof It ---
|
2 |
+
You all arrive at a Lava Production Facility on a floating island in the sky. As the others begin to search the massive industrial complex, you feel a small nose boop your leg and look down to discover a reindeer wearing a hard hat.
|
3 |
+
|
4 |
+
The reindeer is holding a book titled "Lava Island Hiking Guide". However, when you open the book, you discover that most of it seems to have been scorched by lava! As you're about to ask how you can help, the reindeer brings you a blank topographic map of the surrounding area (your puzzle input) and looks up at you excitedly.
|
5 |
+
|
6 |
+
Perhaps you can help fill in the missing hiking trails?
|
7 |
+
|
8 |
+
The topographic map indicates the height at each position using a scale from 0 (lowest) to 9 (highest). For example:
|
9 |
+
|
10 |
+
0123
|
11 |
+
1234
|
12 |
+
8765
|
13 |
+
9876
|
14 |
+
Based on un-scorched scraps of the book, you determine that a good hiking trail is as long as possible and has an even, gradual, uphill slope. For all practical purposes, this means that a hiking trail is any path that starts at height 0, ends at height 9, and always increases by a height of exactly 1 at each step. Hiking trails never include diagonal steps - only up, down, left, or right (from the perspective of the map).
|
15 |
+
|
16 |
+
You look up from the map and notice that the reindeer has helpfully begun to construct a small pile of pencils, markers, rulers, compasses, stickers, and other equipment you might need to update the map with hiking trails.
|
17 |
+
|
18 |
+
A trailhead is any position that starts one or more hiking trails - here, these positions will always have height 0. Assembling more fragments of pages, you establish that a trailhead's score is the number of 9-height positions reachable from that trailhead via a hiking trail. In the above example, the single trailhead in the top left corner has a score of 1 because it can reach a single 9 (the one in the bottom left).
|
19 |
+
|
20 |
+
This trailhead has a score of 2:
|
21 |
+
|
22 |
+
...0...
|
23 |
+
...1...
|
24 |
+
...2...
|
25 |
+
6543456
|
26 |
+
7.....7
|
27 |
+
8.....8
|
28 |
+
9.....9
|
29 |
+
(The positions marked . are impassable tiles to simplify these examples; they do not appear on your actual topographic map.)
|
30 |
+
|
31 |
+
This trailhead has a score of 4 because every 9 is reachable via a hiking trail except the one immediately to the left of the trailhead:
|
32 |
+
|
33 |
+
..90..9
|
34 |
+
...1.98
|
35 |
+
...2..7
|
36 |
+
6543456
|
37 |
+
765.987
|
38 |
+
876....
|
39 |
+
987....
|
40 |
+
This topographic map contains two trailheads; the trailhead at the top has a score of 1, while the trailhead at the bottom has a score of 2:
|
41 |
+
|
42 |
+
10..9..
|
43 |
+
2...8..
|
44 |
+
3...7..
|
45 |
+
4567654
|
46 |
+
...8..3
|
47 |
+
...9..2
|
48 |
+
.....01
|
49 |
+
Here's a larger example:
|
50 |
+
|
51 |
+
89010123
|
52 |
+
78121874
|
53 |
+
87430965
|
54 |
+
96549874
|
55 |
+
45678903
|
56 |
+
32019012
|
57 |
+
01329801
|
58 |
+
10456732
|
59 |
+
This larger example has 9 trailheads. Considering the trailheads in reading order, they have scores of 5, 6, 5, 3, 1, 3, 5, 3, and 5. Adding these scores together, the sum of the scores of all trailheads is 36.
|
60 |
+
|
61 |
+
The reindeer gleefully carries over a protractor and adds it to the pile. What is the sum of the scores of all trailheads on your topographic map?
|
62 |
+
|
63 |
+
--- Part Two ---
|
64 |
+
The reindeer spends a few minutes reviewing your hiking trail map before realizing something, disappearing for a few minutes, and finally returning with yet another slightly-charred piece of paper.
|
65 |
+
|
66 |
+
The paper describes a second way to measure a trailhead called its rating. A trailhead's rating is the number of distinct hiking trails which begin at that trailhead. For example:
|
67 |
+
|
68 |
+
.....0.
|
69 |
+
..4321.
|
70 |
+
..5..2.
|
71 |
+
..6543.
|
72 |
+
..7..4.
|
73 |
+
..8765.
|
74 |
+
..9....
|
75 |
+
The above map has a single trailhead; its rating is 3 because there are exactly three distinct hiking trails which begin at that position:
|
76 |
+
|
77 |
+
.....0. .....0. .....0.
|
78 |
+
..4321. .....1. .....1.
|
79 |
+
..5.... .....2. .....2.
|
80 |
+
..6.... ..6543. .....3.
|
81 |
+
..7.... ..7.... .....4.
|
82 |
+
..8.... ..8.... ..8765.
|
83 |
+
..9.... ..9.... ..9....
|
84 |
+
Here is a map containing a single trailhead with rating 13:
|
85 |
+
|
86 |
+
..90..9
|
87 |
+
...1.98
|
88 |
+
...2..7
|
89 |
+
6543456
|
90 |
+
765.987
|
91 |
+
876....
|
92 |
+
987....
|
93 |
+
This map contains a single trailhead with rating 227 (because there are 121 distinct hiking trails that lead to the 9 on the right edge and 106 that lead to the 9 on the bottom edge):
|
94 |
+
|
95 |
+
012345
|
96 |
+
123456
|
97 |
+
234567
|
98 |
+
345678
|
99 |
+
4.6789
|
100 |
+
56789.
|
101 |
+
Here's the larger example from before:
|
102 |
+
|
103 |
+
89010123
|
104 |
+
78121874
|
105 |
+
87430965
|
106 |
+
96549874
|
107 |
+
45678903
|
108 |
+
32019012
|
109 |
+
01329801
|
110 |
+
10456732
|
111 |
+
Considering its trailheads in reading order, they have ratings of 20, 24, 10, 4, 1, 4, 5, 8, and 5. The sum of all trailhead ratings in this larger example topographic map is 81.
|
112 |
+
|
113 |
+
You're not sure how, but the reindeer seems to have crafted some tiny flags out of toothpicks and bits of paper and is using them to mark trailheads on your topographic map. What is the sum of the ratings of all trailheads?
|
day11/problem.txt
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 11: Plutonian Pebbles ---
|
2 |
+
The ancient civilization on Pluto was known for its ability to manipulate spacetime, and while The Historians explore their infinite corridors, you've noticed a strange set of physics-defying stones.
|
3 |
+
|
4 |
+
At first glance, they seem like normal stones: they're arranged in a perfectly straight line, and each stone has a number engraved on it.
|
5 |
+
|
6 |
+
The strange part is that every time you blink, the stones change.
|
7 |
+
|
8 |
+
Sometimes, the number engraved on a stone changes. Other times, a stone might split in two, causing all the other stones to shift over a bit to make room in their perfectly straight line.
|
9 |
+
|
10 |
+
As you observe them for a while, you find that the stones have a consistent behavior. Every time you blink, the stones each simultaneously change according to the first applicable rule in this list:
|
11 |
+
|
12 |
+
If the stone is engraved with the number 0, it is replaced by a stone engraved with the number 1.
|
13 |
+
If the stone is engraved with a number that has an even number of digits, it is replaced by two stones. The left half of the digits are engraved on the new left stone, and the right half of the digits are engraved on the new right stone. (The new numbers don't keep extra leading zeroes: 1000 would become stones 10 and 0.)
|
14 |
+
If none of the other rules apply, the stone is replaced by a new stone; the old stone's number multiplied by 2024 is engraved on the new stone.
|
15 |
+
No matter how the stones change, their order is preserved, and they stay on their perfectly straight line.
|
16 |
+
|
17 |
+
How will the stones evolve if you keep blinking at them? You take a note of the number engraved on each stone in the line (your puzzle input).
|
18 |
+
|
19 |
+
If you have an arrangement of five stones engraved with the numbers 0 1 10 99 999 and you blink once, the stones transform as follows:
|
20 |
+
|
21 |
+
The first stone, 0, becomes a stone marked 1.
|
22 |
+
The second stone, 1, is multiplied by 2024 to become 2024.
|
23 |
+
The third stone, 10, is split into a stone marked 1 followed by a stone marked 0.
|
24 |
+
The fourth stone, 99, is split into two stones marked 9.
|
25 |
+
The fifth stone, 999, is replaced by a stone marked 2021976.
|
26 |
+
So, after blinking once, your five stones would become an arrangement of seven stones engraved with the numbers 1 2024 1 0 9 9 2021976.
|
27 |
+
|
28 |
+
Here is a longer example:
|
29 |
+
|
30 |
+
Initial arrangement:
|
31 |
+
125 17
|
32 |
+
|
33 |
+
After 1 blink:
|
34 |
+
253000 1 7
|
35 |
+
|
36 |
+
After 2 blinks:
|
37 |
+
253 0 2024 14168
|
38 |
+
|
39 |
+
After 3 blinks:
|
40 |
+
512072 1 20 24 28676032
|
41 |
+
|
42 |
+
After 4 blinks:
|
43 |
+
512 72 2024 2 0 2 4 2867 6032
|
44 |
+
|
45 |
+
After 5 blinks:
|
46 |
+
1036288 7 2 20 24 4048 1 4048 8096 28 67 60 32
|
47 |
+
|
48 |
+
After 6 blinks:
|
49 |
+
2097446912 14168 4048 2 0 2 4 40 48 2024 40 48 80 96 2 8 6 7 6 0 3 2
|
50 |
+
In this example, after blinking six times, you would have 22 stones. After blinking 25 times, you would have 55312 stones!
|
51 |
+
|
52 |
+
Consider the arrangement of stones in front of you. How many stones will you have after blinking 25 times?
|
53 |
+
|
54 |
+
--- Part Two ---
|
55 |
+
The Historians sure are taking a long time. To be fair, the infinite corridors are very large.
|
56 |
+
|
57 |
+
How many stones would you have after blinking a total of 75 times?
|
day12/problem.txt
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 12: Garden Groups ---
|
2 |
+
Why not search for the Chief Historian near the gardener and his massive farm? There's plenty of food, so The Historians grab something to eat while they search.
|
3 |
+
|
4 |
+
You're about to settle near a complex arrangement of garden plots when some Elves ask if you can lend a hand. They'd like to set up fences around each region of garden plots, but they can't figure out how much fence they need to order or how much it will cost. They hand you a map (your puzzle input) of the garden plots.
|
5 |
+
|
6 |
+
Each garden plot grows only a single type of plant and is indicated by a single letter on your map. When multiple garden plots are growing the same type of plant and are touching (horizontally or vertically), they form a region. For example:
|
7 |
+
|
8 |
+
AAAA
|
9 |
+
BBCD
|
10 |
+
BBCC
|
11 |
+
EEEC
|
12 |
+
This 4x4 arrangement includes garden plots growing five different types of plants (labeled A, B, C, D, and E), each grouped into their own region.
|
13 |
+
|
14 |
+
In order to accurately calculate the cost of the fence around a single region, you need to know that region's area and perimeter.
|
15 |
+
|
16 |
+
The area of a region is simply the number of garden plots the region contains. The above map's type A, B, and C plants are each in a region of area 4. The type E plants are in a region of area 3; the type D plants are in a region of area 1.
|
17 |
+
|
18 |
+
Each garden plot is a square and so has four sides. The perimeter of a region is the number of sides of garden plots in the region that do not touch another garden plot in the same region. The type A and C plants are each in a region with perimeter 10. The type B and E plants are each in a region with perimeter 8. The lone D plot forms its own region with perimeter 4.
|
19 |
+
|
20 |
+
Visually indicating the sides of plots in each region that contribute to the perimeter using - and |, the above map's regions' perimeters are measured as follows:
|
21 |
+
|
22 |
+
+-+-+-+-+
|
23 |
+
|A A A A|
|
24 |
+
+-+-+-+-+ +-+
|
25 |
+
|D|
|
26 |
+
+-+-+ +-+ +-+
|
27 |
+
|B B| |C|
|
28 |
+
+ + + +-+
|
29 |
+
|B B| |C C|
|
30 |
+
+-+-+ +-+ +
|
31 |
+
|C|
|
32 |
+
+-+-+-+ +-+
|
33 |
+
|E E E|
|
34 |
+
+-+-+-+
|
35 |
+
Plants of the same type can appear in multiple separate regions, and regions can even appear within other regions. For example:
|
36 |
+
|
37 |
+
OOOOO
|
38 |
+
OXOXO
|
39 |
+
OOOOO
|
40 |
+
OXOXO
|
41 |
+
OOOOO
|
42 |
+
The above map contains five regions, one containing all of the O garden plots, and the other four each containing a single X plot.
|
43 |
+
|
44 |
+
The four X regions each have area 1 and perimeter 4. The region containing 21 type O plants is more complicated; in addition to its outer edge contributing a perimeter of 20, its boundary with each X region contributes an additional 4 to its perimeter, for a total perimeter of 36.
|
45 |
+
|
46 |
+
Due to "modern" business practices, the price of fence required for a region is found by multiplying that region's area by its perimeter. The total price of fencing all regions on a map is found by adding together the price of fence for every region on the map.
|
47 |
+
|
48 |
+
In the first example, region A has price 4 * 10 = 40, region B has price 4 * 8 = 32, region C has price 4 * 10 = 40, region D has price 1 * 4 = 4, and region E has price 3 * 8 = 24. So, the total price for the first example is 140.
|
49 |
+
|
50 |
+
In the second example, the region with all of the O plants has price 21 * 36 = 756, and each of the four smaller X regions has price 1 * 4 = 4, for a total price of 772 (756 + 4 + 4 + 4 + 4).
|
51 |
+
|
52 |
+
Here's a larger example:
|
53 |
+
|
54 |
+
RRRRIICCFF
|
55 |
+
RRRRIICCCF
|
56 |
+
VVRRRCCFFF
|
57 |
+
VVRCCCJFFF
|
58 |
+
VVVVCJJCFE
|
59 |
+
VVIVCCJJEE
|
60 |
+
VVIIICJJEE
|
61 |
+
MIIIIIJJEE
|
62 |
+
MIIISIJEEE
|
63 |
+
MMMISSJEEE
|
64 |
+
It contains:
|
65 |
+
|
66 |
+
A region of R plants with price 12 * 18 = 216.
|
67 |
+
A region of I plants with price 4 * 8 = 32.
|
68 |
+
A region of C plants with price 14 * 28 = 392.
|
69 |
+
A region of F plants with price 10 * 18 = 180.
|
70 |
+
A region of V plants with price 13 * 20 = 260.
|
71 |
+
A region of J plants with price 11 * 20 = 220.
|
72 |
+
A region of C plants with price 1 * 4 = 4.
|
73 |
+
A region of E plants with price 13 * 18 = 234.
|
74 |
+
A region of I plants with price 14 * 22 = 308.
|
75 |
+
A region of M plants with price 5 * 12 = 60.
|
76 |
+
A region of S plants with price 3 * 8 = 24.
|
77 |
+
So, it has a total price of 1930.
|
78 |
+
|
79 |
+
What is the total price of fencing all regions on your map?
|
80 |
+
|
81 |
+
The first half of this puzzle is complete! It provides one gold star: *
|
82 |
+
|
83 |
+
--- Part Two ---
|
84 |
+
Fortunately, the Elves are trying to order so much fence that they qualify for a bulk discount!
|
85 |
+
|
86 |
+
Under the bulk discount, instead of using the perimeter to calculate the price, you need to use the number of sides each region has. Each straight section of fence counts as a side, regardless of how long it is.
|
87 |
+
|
88 |
+
Consider this example again:
|
89 |
+
|
90 |
+
AAAA
|
91 |
+
BBCD
|
92 |
+
BBCC
|
93 |
+
EEEC
|
94 |
+
The region containing type A plants has 4 sides, as does each of the regions containing plants of type B, D, and E. However, the more complex region containing the plants of type C has 8 sides!
|
95 |
+
|
96 |
+
Using the new method of calculating the per-region price by multiplying the region's area by its number of sides, regions A through E have prices 16, 16, 32, 4, and 12, respectively, for a total price of 80.
|
97 |
+
|
98 |
+
The second example above (full of type X and O plants) would have a total price of 436.
|
99 |
+
|
100 |
+
Here's a map that includes an E-shaped region full of type E plants:
|
101 |
+
|
102 |
+
EEEEE
|
103 |
+
EXXXX
|
104 |
+
EEEEE
|
105 |
+
EXXXX
|
106 |
+
EEEEE
|
107 |
+
The E-shaped region has an area of 17 and 12 sides for a price of 204. Including the two regions full of type X plants, this map has a total price of 236.
|
108 |
+
|
109 |
+
This map has a total price of 368:
|
110 |
+
|
111 |
+
AAAAAA
|
112 |
+
AAABBA
|
113 |
+
AAABBA
|
114 |
+
ABBAAA
|
115 |
+
ABBAAA
|
116 |
+
AAAAAA
|
117 |
+
It includes two regions full of type B plants (each with 4 sides) and a single region full of type A plants (with 4 sides on the outside and 8 more sides on the inside, a total of 12 sides). Be especially careful when counting the fence around regions like the one full of type A plants; in particular, each section of fence has an in-side and an out-side, so the fence does not connect across the middle of the region (where the two B regions touch diagonally). (The Elves would have used the Möbius Fencing Company instead, but their contract terms were too one-sided.)
|
118 |
+
|
119 |
+
The larger example from before now has the following updated prices:
|
120 |
+
|
121 |
+
A region of R plants with price 12 * 10 = 120.
|
122 |
+
A region of I plants with price 4 * 4 = 16.
|
123 |
+
A region of C plants with price 14 * 22 = 308.
|
124 |
+
A region of F plants with price 10 * 12 = 120.
|
125 |
+
A region of V plants with price 13 * 10 = 130.
|
126 |
+
A region of J plants with price 11 * 12 = 132.
|
127 |
+
A region of C plants with price 1 * 4 = 4.
|
128 |
+
A region of E plants with price 13 * 8 = 104.
|
129 |
+
A region of I plants with price 14 * 16 = 224.
|
130 |
+
A region of M plants with price 5 * 6 = 30.
|
131 |
+
A region of S plants with price 3 * 6 = 18.
|
132 |
+
Adding these together produces its new total price of 1206.
|
133 |
+
|
134 |
+
What is the new total price of fencing all regions on your map?
|
135 |
+
|
day13/problem.txt
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 13: Claw Contraption ---
|
2 |
+
Next up: the lobby of a resort on a tropical island. The Historians take a moment to admire the hexagonal floor tiles before spreading out.
|
3 |
+
|
4 |
+
Fortunately, it looks like the resort has a new arcade! Maybe you can win some prizes from the claw machines?
|
5 |
+
|
6 |
+
The claw machines here are a little unusual. Instead of a joystick or directional buttons to control the claw, these machines have two buttons labeled A and B. Worse, you can't just put in a token and play; it costs 3 tokens to push the A button and 1 token to push the B button.
|
7 |
+
|
8 |
+
With a little experimentation, you figure out that each machine's buttons are configured to move the claw a specific amount to the right (along the X axis) and a specific amount forward (along the Y axis) each time that button is pressed.
|
9 |
+
|
10 |
+
Each machine contains one prize; to win the prize, the claw must be positioned exactly above the prize on both the X and Y axes.
|
11 |
+
|
12 |
+
You wonder: what is the smallest number of tokens you would have to spend to win as many prizes as possible? You assemble a list of every machine's button behavior and prize location (your puzzle input). For example:
|
13 |
+
|
14 |
+
Button A: X+94, Y+34
|
15 |
+
Button B: X+22, Y+67
|
16 |
+
Prize: X=8400, Y=5400
|
17 |
+
|
18 |
+
Button A: X+26, Y+66
|
19 |
+
Button B: X+67, Y+21
|
20 |
+
Prize: X=12748, Y=12176
|
21 |
+
|
22 |
+
Button A: X+17, Y+86
|
23 |
+
Button B: X+84, Y+37
|
24 |
+
Prize: X=7870, Y=6450
|
25 |
+
|
26 |
+
Button A: X+69, Y+23
|
27 |
+
Button B: X+27, Y+71
|
28 |
+
Prize: X=18641, Y=10279
|
29 |
+
This list describes the button configuration and prize location of four different claw machines.
|
30 |
+
|
31 |
+
For now, consider just the first claw machine in the list:
|
32 |
+
|
33 |
+
Pushing the machine's A button would move the claw 94 units along the X axis and 34 units along the Y axis.
|
34 |
+
Pushing the B button would move the claw 22 units along the X axis and 67 units along the Y axis.
|
35 |
+
The prize is located at X=8400, Y=5400; this means that from the claw's initial position, it would need to move exactly 8400 units along the X axis and exactly 5400 units along the Y axis to be perfectly aligned with the prize in this machine.
|
36 |
+
The cheapest way to win the prize is by pushing the A button 80 times and the B button 40 times. This would line up the claw along the X axis (because 80*94 + 40*22 = 8400) and along the Y axis (because 80*34 + 40*67 = 5400). Doing this would cost 80*3 tokens for the A presses and 40*1 for the B presses, a total of 280 tokens.
|
37 |
+
|
38 |
+
For the second and fourth claw machines, there is no combination of A and B presses that will ever win a prize.
|
39 |
+
|
40 |
+
For the third claw machine, the cheapest way to win the prize is by pushing the A button 38 times and the B button 86 times. Doing this would cost a total of 200 tokens.
|
41 |
+
|
42 |
+
So, the most prizes you could possibly win is two; the minimum tokens you would have to spend to win all (two) prizes is 480.
|
43 |
+
|
44 |
+
You estimate that each button would need to be pressed no more than 100 times to win a prize. How else would someone be expected to play?
|
45 |
+
|
46 |
+
Figure out how to win as many prizes as possible. What is the fewest tokens you would have to spend to win all possible prizes?
|
47 |
+
|
48 |
+
--- Part Two ---
|
49 |
+
As you go to win the first prize, you discover that the claw is nowhere near where you expected it would be. Due to a unit conversion error in your measurements, the position of every prize is actually 10000000000000 higher on both the X and Y axis!
|
50 |
+
|
51 |
+
Add 10000000000000 to the X and Y position of every prize. After making this change, the example above would now look like this:
|
52 |
+
|
53 |
+
Button A: X+94, Y+34
|
54 |
+
Button B: X+22, Y+67
|
55 |
+
Prize: X=10000000008400, Y=10000000005400
|
56 |
+
|
57 |
+
Button A: X+26, Y+66
|
58 |
+
Button B: X+67, Y+21
|
59 |
+
Prize: X=10000000012748, Y=10000000012176
|
60 |
+
|
61 |
+
Button A: X+17, Y+86
|
62 |
+
Button B: X+84, Y+37
|
63 |
+
Prize: X=10000000007870, Y=10000000006450
|
64 |
+
|
65 |
+
Button A: X+69, Y+23
|
66 |
+
Button B: X+27, Y+71
|
67 |
+
Prize: X=10000000018641, Y=10000000010279
|
68 |
+
Now, it is only possible to win a prize on the second and fourth claw machines. Unfortunately, it will take many more than 100 presses to do so.
|
69 |
+
|
70 |
+
Using the corrected prize coordinates, figure out how to win as many prizes as possible. What is the fewest tokens you would have to spend to win all possible prizes?
|
71 |
+
|
day14/problem.txt
ADDED
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 14: Restroom Redoubt ---
|
2 |
+
One of The Historians needs to use the bathroom; fortunately, you know there's a bathroom near an unvisited location on their list, and so you're all quickly teleported directly to the lobby of Easter Bunny Headquarters.
|
3 |
+
|
4 |
+
Unfortunately, EBHQ seems to have "improved" bathroom security again after your last visit. The area outside the bathroom is swarming with robots!
|
5 |
+
|
6 |
+
To get The Historian safely to the bathroom, you'll need a way to predict where the robots will be in the future. Fortunately, they all seem to be moving on the tile floor in predictable straight lines.
|
7 |
+
|
8 |
+
You make a list (your puzzle input) of all of the robots' current positions (p) and velocities (v), one robot per line. For example:
|
9 |
+
|
10 |
+
p=0,4 v=3,-3
|
11 |
+
p=6,3 v=-1,-3
|
12 |
+
p=10,3 v=-1,2
|
13 |
+
p=2,0 v=2,-1
|
14 |
+
p=0,0 v=1,3
|
15 |
+
p=3,0 v=-2,-2
|
16 |
+
p=7,6 v=-1,-3
|
17 |
+
p=3,0 v=-1,-2
|
18 |
+
p=9,3 v=2,3
|
19 |
+
p=7,3 v=-1,2
|
20 |
+
p=2,4 v=2,-3
|
21 |
+
p=9,5 v=-3,-3
|
22 |
+
Each robot's position is given as p=x,y where x represents the number of tiles the robot is from the left wall and y represents the number of tiles from the top wall (when viewed from above). So, a position of p=0,0 means the robot is all the way in the top-left corner.
|
23 |
+
|
24 |
+
Each robot's velocity is given as v=x,y where x and y are given in tiles per second. Positive x means the robot is moving to the right, and positive y means the robot is moving down. So, a velocity of v=1,-2 means that each second, the robot moves 1 tile to the right and 2 tiles up.
|
25 |
+
|
26 |
+
The robots outside the actual bathroom are in a space which is 101 tiles wide and 103 tiles tall (when viewed from above). However, in this example, the robots are in a space which is only 11 tiles wide and 7 tiles tall.
|
27 |
+
|
28 |
+
The robots are good at navigating over/under each other (due to a combination of springs, extendable legs, and quadcopters), so they can share the same tile and don't interact with each other. Visually, the number of robots on each tile in this example looks like this:
|
29 |
+
|
30 |
+
1.12.......
|
31 |
+
...........
|
32 |
+
...........
|
33 |
+
......11.11
|
34 |
+
1.1........
|
35 |
+
.........1.
|
36 |
+
.......1...
|
37 |
+
These robots have a unique feature for maximum bathroom security: they can teleport. When a robot would run into an edge of the space they're in, they instead teleport to the other side, effectively wrapping around the edges. Here is what robot p=2,4 v=2,-3 does for the first few seconds:
|
38 |
+
|
39 |
+
Initial state:
|
40 |
+
...........
|
41 |
+
...........
|
42 |
+
...........
|
43 |
+
...........
|
44 |
+
..1........
|
45 |
+
...........
|
46 |
+
...........
|
47 |
+
|
48 |
+
After 1 second:
|
49 |
+
...........
|
50 |
+
....1......
|
51 |
+
...........
|
52 |
+
...........
|
53 |
+
...........
|
54 |
+
...........
|
55 |
+
...........
|
56 |
+
|
57 |
+
After 2 seconds:
|
58 |
+
...........
|
59 |
+
...........
|
60 |
+
...........
|
61 |
+
...........
|
62 |
+
...........
|
63 |
+
......1....
|
64 |
+
...........
|
65 |
+
|
66 |
+
After 3 seconds:
|
67 |
+
...........
|
68 |
+
...........
|
69 |
+
........1..
|
70 |
+
...........
|
71 |
+
...........
|
72 |
+
...........
|
73 |
+
...........
|
74 |
+
|
75 |
+
After 4 seconds:
|
76 |
+
...........
|
77 |
+
...........
|
78 |
+
...........
|
79 |
+
...........
|
80 |
+
...........
|
81 |
+
...........
|
82 |
+
..........1
|
83 |
+
|
84 |
+
After 5 seconds:
|
85 |
+
...........
|
86 |
+
...........
|
87 |
+
...........
|
88 |
+
.1.........
|
89 |
+
...........
|
90 |
+
...........
|
91 |
+
...........
|
92 |
+
The Historian can't wait much longer, so you don't have to simulate the robots for very long. Where will the robots be after 100 seconds?
|
93 |
+
|
94 |
+
In the above example, the number of robots on each tile after 100 seconds has elapsed looks like this:
|
95 |
+
|
96 |
+
......2..1.
|
97 |
+
...........
|
98 |
+
1..........
|
99 |
+
.11........
|
100 |
+
.....1.....
|
101 |
+
...12......
|
102 |
+
.1....1....
|
103 |
+
To determine the safest area, count the number of robots in each quadrant after 100 seconds. Robots that are exactly in the middle (horizontally or vertically) don't count as being in any quadrant, so the only relevant robots are:
|
104 |
+
|
105 |
+
..... 2..1.
|
106 |
+
..... .....
|
107 |
+
1.... .....
|
108 |
+
|
109 |
+
..... .....
|
110 |
+
...12 .....
|
111 |
+
.1... 1....
|
112 |
+
In this example, the quadrants contain 1, 3, 4, and 1 robot. Multiplying these together gives a total safety factor of 12.
|
113 |
+
|
114 |
+
Predict the motion of the robots in your list within a space which is 101 tiles wide and 103 tiles tall. What will the safety factor be after exactly 100 seconds have elapsed?
|
115 |
+
|
116 |
+
|
117 |
+
--- Part Two ---
|
118 |
+
During the bathroom break, someone notices that these robots seem awfully similar to ones built and used at the North Pole. If they're the same type of robots, they should have a hard-coded Easter egg: very rarely, most of the robots should arrange themselves into a picture of a Christmas tree.
|
119 |
+
|
120 |
+
What is the fewest number of seconds that must elapse for the robots to display the Easter egg?
|
121 |
+
|
day15/problem.txt
ADDED
@@ -0,0 +1,404 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 15: Warehouse Woes ---
|
2 |
+
You appear back inside your own mini submarine! Each Historian drives their mini submarine in a different direction; maybe the Chief has his own submarine down here somewhere as well?
|
3 |
+
|
4 |
+
You look up to see a vast school of lanternfish swimming past you. On closer inspection, they seem quite anxious, so you drive your mini submarine over to see if you can help.
|
5 |
+
|
6 |
+
Because lanternfish populations grow rapidly, they need a lot of food, and that food needs to be stored somewhere. That's why these lanternfish have built elaborate warehouse complexes operated by robots!
|
7 |
+
|
8 |
+
These lanternfish seem so anxious because they have lost control of the robot that operates one of their most important warehouses! It is currently running amok, pushing around boxes in the warehouse with no regard for lanternfish logistics or lanternfish inventory management strategies.
|
9 |
+
|
10 |
+
Right now, none of the lanternfish are brave enough to swim up to an unpredictable robot so they could shut it off. However, if you could anticipate the robot's movements, maybe they could find a safe option.
|
11 |
+
|
12 |
+
The lanternfish already have a map of the warehouse and a list of movements the robot will attempt to make (your puzzle input). The problem is that the movements will sometimes fail as boxes are shifted around, making the actual movements of the robot difficult to predict.
|
13 |
+
|
14 |
+
For example:
|
15 |
+
|
16 |
+
##########
|
17 |
+
#..O..O.O#
|
18 |
+
#......O.#
|
19 |
+
#.OO..O.O#
|
20 |
+
#[email protected].#
|
21 |
+
#O#..O...#
|
22 |
+
#O..O..O.#
|
23 |
+
#.OO.O.OO#
|
24 |
+
#....O...#
|
25 |
+
##########
|
26 |
+
|
27 |
+
<vv>^<v^>v>^vv^v>v<>v^v<v<^vv<<<^><<><>>v<vvv<>^v^>^<<<><<v<<<v^vv^v>^
|
28 |
+
vvv<<^>^v^^><<>>><>^<<><^vv^^<>vvv<>><^^v>^>vv<>v<<<<v<^v>^<^^>>>^<v<v
|
29 |
+
><>vv>v^v^<>><>>>><^^>vv>v<^^^>>v^v^<^^>v^^>v^<^v>v<>>v^v^<v>v^^<^^vv<
|
30 |
+
<<v<^>>^^^^>>>v^<>vvv^><v<<<>^^^vv^<vvv>^>v<^^^^v<>^>vvvv><>>v^<<^^^^^
|
31 |
+
^><^><>>><>^^<<^^v>>><^<v>^<vv>>v>>>^v><>^v><<<<v>>v<v<v>vvv>^<><<>^><
|
32 |
+
^>><>^v<><^vvv<^^<><v<<<<<><^v<<<><<<^^<v<^^^><^>>^<v^><<<^>>^v<v^v<v^
|
33 |
+
>^>>^v>vv>^<<^v<>><<><<v<<v><>v<^vv<<<>^^v^>^^>>><<^v>>v^v><^^>>^<>vv^
|
34 |
+
<><^^>^^^<><vvvvv^v<v<<>^v<v>v<<^><<><<><<<^^<<<^<<>><<><^^^>^^<>^>v<>
|
35 |
+
^^>vv<^v^v<vv>^<><v<^v>^^^>>>^^vvv^>vvv<>>>^<^>>>>>^<<^v>^vvv<>^<><<v>
|
36 |
+
v^^>>><<^^<>>^v^<v^vv<>v^<<>^<^v^v><^<<<><<^<v><v<>vv>>v><v^<vv<>v^<<^
|
37 |
+
As the robot (@) attempts to move, if there are any boxes (O) in the way, the robot will also attempt to push those boxes. However, if this action would cause the robot or a box to move into a wall (#), nothing moves instead, including the robot. The initial positions of these are shown on the map at the top of the document the lanternfish gave you.
|
38 |
+
|
39 |
+
The rest of the document describes the moves (^ for up, v for down, < for left, > for right) that the robot will attempt to make, in order. (The moves form a single giant sequence; they are broken into multiple lines just to make copy-pasting easier. Newlines within the move sequence should be ignored.)
|
40 |
+
|
41 |
+
Here is a smaller example to get started:
|
42 |
+
|
43 |
+
########
|
44 |
+
#..O.O.#
|
45 |
+
##@.O..#
|
46 |
+
#...O..#
|
47 |
+
#.#.O..#
|
48 |
+
#...O..#
|
49 |
+
#......#
|
50 |
+
########
|
51 |
+
|
52 |
+
<^^>>>vv<v>>v<<
|
53 |
+
Were the robot to attempt the given sequence of moves, it would push around the boxes as follows:
|
54 |
+
|
55 |
+
Initial state:
|
56 |
+
########
|
57 |
+
#..O.O.#
|
58 |
+
##@.O..#
|
59 |
+
#...O..#
|
60 |
+
#.#.O..#
|
61 |
+
#...O..#
|
62 |
+
#......#
|
63 |
+
########
|
64 |
+
|
65 |
+
Move <:
|
66 |
+
########
|
67 |
+
#..O.O.#
|
68 |
+
##@.O..#
|
69 |
+
#...O..#
|
70 |
+
#.#.O..#
|
71 |
+
#...O..#
|
72 |
+
#......#
|
73 |
+
########
|
74 |
+
|
75 |
+
Move ^:
|
76 |
+
########
|
77 |
+
#[email protected].#
|
78 |
+
##..O..#
|
79 |
+
#...O..#
|
80 |
+
#.#.O..#
|
81 |
+
#...O..#
|
82 |
+
#......#
|
83 |
+
########
|
84 |
+
|
85 |
+
Move ^:
|
86 |
+
########
|
87 |
+
#[email protected].#
|
88 |
+
##..O..#
|
89 |
+
#...O..#
|
90 |
+
#.#.O..#
|
91 |
+
#...O..#
|
92 |
+
#......#
|
93 |
+
########
|
94 |
+
|
95 |
+
Move >:
|
96 |
+
########
|
97 |
+
#..@OO.#
|
98 |
+
##..O..#
|
99 |
+
#...O..#
|
100 |
+
#.#.O..#
|
101 |
+
#...O..#
|
102 |
+
#......#
|
103 |
+
########
|
104 |
+
|
105 |
+
Move >:
|
106 |
+
########
|
107 |
+
#...@OO#
|
108 |
+
##..O..#
|
109 |
+
#...O..#
|
110 |
+
#.#.O..#
|
111 |
+
#...O..#
|
112 |
+
#......#
|
113 |
+
########
|
114 |
+
|
115 |
+
Move >:
|
116 |
+
########
|
117 |
+
#...@OO#
|
118 |
+
##..O..#
|
119 |
+
#...O..#
|
120 |
+
#.#.O..#
|
121 |
+
#...O..#
|
122 |
+
#......#
|
123 |
+
########
|
124 |
+
|
125 |
+
Move v:
|
126 |
+
########
|
127 |
+
#....OO#
|
128 |
+
##..@..#
|
129 |
+
#...O..#
|
130 |
+
#.#.O..#
|
131 |
+
#...O..#
|
132 |
+
#...O..#
|
133 |
+
########
|
134 |
+
|
135 |
+
Move v:
|
136 |
+
########
|
137 |
+
#....OO#
|
138 |
+
##..@..#
|
139 |
+
#...O..#
|
140 |
+
#.#.O..#
|
141 |
+
#...O..#
|
142 |
+
#...O..#
|
143 |
+
########
|
144 |
+
|
145 |
+
Move <:
|
146 |
+
########
|
147 |
+
#....OO#
|
148 |
+
##.@...#
|
149 |
+
#...O..#
|
150 |
+
#.#.O..#
|
151 |
+
#...O..#
|
152 |
+
#...O..#
|
153 |
+
########
|
154 |
+
|
155 |
+
Move v:
|
156 |
+
########
|
157 |
+
#....OO#
|
158 |
+
##.....#
|
159 |
+
#..@O..#
|
160 |
+
#.#.O..#
|
161 |
+
#...O..#
|
162 |
+
#...O..#
|
163 |
+
########
|
164 |
+
|
165 |
+
Move >:
|
166 |
+
########
|
167 |
+
#....OO#
|
168 |
+
##.....#
|
169 |
+
#...@O.#
|
170 |
+
#.#.O..#
|
171 |
+
#...O..#
|
172 |
+
#...O..#
|
173 |
+
########
|
174 |
+
|
175 |
+
Move >:
|
176 |
+
########
|
177 |
+
#....OO#
|
178 |
+
##.....#
|
179 |
+
#....@O#
|
180 |
+
#.#.O..#
|
181 |
+
#...O..#
|
182 |
+
#...O..#
|
183 |
+
########
|
184 |
+
|
185 |
+
Move v:
|
186 |
+
########
|
187 |
+
#....OO#
|
188 |
+
##.....#
|
189 |
+
#.....O#
|
190 |
+
#.#.O@.#
|
191 |
+
#...O..#
|
192 |
+
#...O..#
|
193 |
+
########
|
194 |
+
|
195 |
+
Move <:
|
196 |
+
########
|
197 |
+
#....OO#
|
198 |
+
##.....#
|
199 |
+
#.....O#
|
200 |
+
#.#O@..#
|
201 |
+
#...O..#
|
202 |
+
#...O..#
|
203 |
+
########
|
204 |
+
|
205 |
+
Move <:
|
206 |
+
########
|
207 |
+
#....OO#
|
208 |
+
##.....#
|
209 |
+
#.....O#
|
210 |
+
#.#O@..#
|
211 |
+
#...O..#
|
212 |
+
#...O..#
|
213 |
+
########
|
214 |
+
The larger example has many more moves; after the robot has finished those moves, the warehouse would look like this:
|
215 |
+
|
216 |
+
##########
|
217 |
+
#.O.O.OOO#
|
218 |
+
#........#
|
219 |
+
#OO......#
|
220 |
+
#OO@.....#
|
221 |
+
#O#.....O#
|
222 |
+
#O.....OO#
|
223 |
+
#O.....OO#
|
224 |
+
#OO....OO#
|
225 |
+
##########
|
226 |
+
The lanternfish use their own custom Goods Positioning System (GPS for short) to track the locations of the boxes. The GPS coordinate of a box is equal to 100 times its distance from the top edge of the map plus its distance from the left edge of the map. (This process does not stop at wall tiles; measure all the way to the edges of the map.)
|
227 |
+
|
228 |
+
So, the box shown below has a distance of 1 from the top edge of the map and 4 from the left edge of the map, resulting in a GPS coordinate of 100 * 1 + 4 = 104.
|
229 |
+
|
230 |
+
#######
|
231 |
+
#...O..
|
232 |
+
#......
|
233 |
+
The lanternfish would like to know the sum of all boxes' GPS coordinates after the robot finishes moving. In the larger example, the sum of all boxes' GPS coordinates is 10092. In the smaller example, the sum is 2028.
|
234 |
+
|
235 |
+
Predict the motion of the robot and boxes in the warehouse. After the robot is finished moving, what is the sum of all boxes' GPS coordinates?
|
236 |
+
|
237 |
+
The first half of this puzzle is complete! It provides one gold star: *
|
238 |
+
|
239 |
+
--- Part Two ---
|
240 |
+
The lanternfish use your information to find a safe moment to swim in and turn off the malfunctioning robot! Just as they start preparing a festival in your honor, reports start coming in that a second warehouse's robot is also malfunctioning.
|
241 |
+
|
242 |
+
This warehouse's layout is surprisingly similar to the one you just helped. There is one key difference: everything except the robot is twice as wide! The robot's list of movements doesn't change.
|
243 |
+
|
244 |
+
To get the wider warehouse's map, start with your original map and, for each tile, make the following changes:
|
245 |
+
|
246 |
+
If the tile is #, the new map contains ## instead.
|
247 |
+
If the tile is O, the new map contains [] instead.
|
248 |
+
If the tile is ., the new map contains .. instead.
|
249 |
+
If the tile is @, the new map contains @. instead.
|
250 |
+
This will produce a new warehouse map which is twice as wide and with wide boxes that are represented by []. (The robot does not change size.)
|
251 |
+
|
252 |
+
The larger example from before would now look like this:
|
253 |
+
|
254 |
+
####################
|
255 |
+
##....[]....[]..[]##
|
256 |
+
##............[]..##
|
257 |
+
##..[][]....[]..[]##
|
258 |
+
##....[]@.....[]..##
|
259 |
+
##[]##....[]......##
|
260 |
+
##[]....[]....[]..##
|
261 |
+
##..[][]..[]..[][]##
|
262 |
+
##........[]......##
|
263 |
+
####################
|
264 |
+
Because boxes are now twice as wide but the robot is still the same size and speed, boxes can be aligned such that they directly push two other boxes at once. For example, consider this situation:
|
265 |
+
|
266 |
+
#######
|
267 |
+
#...#.#
|
268 |
+
#.....#
|
269 |
+
#..OO@#
|
270 |
+
#..O..#
|
271 |
+
#.....#
|
272 |
+
#######
|
273 |
+
|
274 |
+
<vv<<^^<<^^
|
275 |
+
After appropriately resizing this map, the robot would push around these boxes as follows:
|
276 |
+
|
277 |
+
Initial state:
|
278 |
+
##############
|
279 |
+
##......##..##
|
280 |
+
##..........##
|
281 |
+
##....[][]@.##
|
282 |
+
##....[]....##
|
283 |
+
##..........##
|
284 |
+
##############
|
285 |
+
|
286 |
+
Move <:
|
287 |
+
##############
|
288 |
+
##......##..##
|
289 |
+
##..........##
|
290 |
+
##...[][]@..##
|
291 |
+
##....[]....##
|
292 |
+
##..........##
|
293 |
+
##############
|
294 |
+
|
295 |
+
Move v:
|
296 |
+
##############
|
297 |
+
##......##..##
|
298 |
+
##..........##
|
299 |
+
##...[][]...##
|
300 |
+
##....[].@..##
|
301 |
+
##..........##
|
302 |
+
##############
|
303 |
+
|
304 |
+
Move v:
|
305 |
+
##############
|
306 |
+
##......##..##
|
307 |
+
##..........##
|
308 |
+
##...[][]...##
|
309 |
+
##....[]....##
|
310 |
+
##.......@..##
|
311 |
+
##############
|
312 |
+
|
313 |
+
Move <:
|
314 |
+
##############
|
315 |
+
##......##..##
|
316 |
+
##..........##
|
317 |
+
##...[][]...##
|
318 |
+
##....[]....##
|
319 |
+
##......@...##
|
320 |
+
##############
|
321 |
+
|
322 |
+
Move <:
|
323 |
+
##############
|
324 |
+
##......##..##
|
325 |
+
##..........##
|
326 |
+
##...[][]...##
|
327 |
+
##....[]....##
|
328 |
+
##.....@....##
|
329 |
+
##############
|
330 |
+
|
331 |
+
Move ^:
|
332 |
+
##############
|
333 |
+
##......##..##
|
334 |
+
##...[][]...##
|
335 |
+
##....[]....##
|
336 |
+
##.....@....##
|
337 |
+
##..........##
|
338 |
+
##############
|
339 |
+
|
340 |
+
Move ^:
|
341 |
+
##############
|
342 |
+
##......##..##
|
343 |
+
##...[][]...##
|
344 |
+
##....[]....##
|
345 |
+
##.....@....##
|
346 |
+
##..........##
|
347 |
+
##############
|
348 |
+
|
349 |
+
Move <:
|
350 |
+
##############
|
351 |
+
##......##..##
|
352 |
+
##...[][]...##
|
353 |
+
##....[]....##
|
354 |
+
##....@.....##
|
355 |
+
##..........##
|
356 |
+
##############
|
357 |
+
|
358 |
+
Move <:
|
359 |
+
##############
|
360 |
+
##......##..##
|
361 |
+
##...[][]...##
|
362 |
+
##....[]....##
|
363 |
+
##...@......##
|
364 |
+
##..........##
|
365 |
+
##############
|
366 |
+
|
367 |
+
Move ^:
|
368 |
+
##############
|
369 |
+
##......##..##
|
370 |
+
##...[][]...##
|
371 |
+
##...@[]....##
|
372 |
+
##..........##
|
373 |
+
##..........##
|
374 |
+
##############
|
375 |
+
|
376 |
+
Move ^:
|
377 |
+
##############
|
378 |
+
##...[].##..##
|
379 |
+
##...@.[]...##
|
380 |
+
##....[]....##
|
381 |
+
##..........##
|
382 |
+
##..........##
|
383 |
+
##############
|
384 |
+
This warehouse also uses GPS to locate the boxes. For these larger boxes, distances are measured from the edge of the map to the closest edge of the box in question. So, the box shown below has a distance of 1 from the top edge of the map and 5 from the left edge of the map, resulting in a GPS coordinate of 100 * 1 + 5 = 105.
|
385 |
+
|
386 |
+
##########
|
387 |
+
##...[]...
|
388 |
+
##........
|
389 |
+
In the scaled-up version of the larger example from above, after the robot has finished all of its moves, the warehouse would look like this:
|
390 |
+
|
391 |
+
####################
|
392 |
+
##[].......[].[][]##
|
393 |
+
##[]...........[].##
|
394 |
+
##[]........[][][]##
|
395 |
+
##[]......[]....[]##
|
396 |
+
##..##......[]....##
|
397 |
+
##..[]............##
|
398 |
+
##..@......[].[][]##
|
399 |
+
##......[][]..[]..##
|
400 |
+
####################
|
401 |
+
The sum of these boxes' GPS coordinates is 9021.
|
402 |
+
|
403 |
+
Predict the motion of the robot and boxes in this new, scaled-up warehouse. What is the sum of all boxes' final GPS coordinates?
|
404 |
+
|
day16/problem.txt
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 16: Reindeer Maze ---
|
2 |
+
It's time again for the Reindeer Olympics! This year, the big event is the Reindeer Maze, where the Reindeer compete for the lowest score.
|
3 |
+
|
4 |
+
You and The Historians arrive to search for the Chief right as the event is about to start. It wouldn't hurt to watch a little, right?
|
5 |
+
|
6 |
+
The Reindeer start on the Start Tile (marked S) facing East and need to reach the End Tile (marked E). They can move forward one tile at a time (increasing their score by 1 point), but never into a wall (#). They can also rotate clockwise or counterclockwise 90 degrees at a time (increasing their score by 1000 points).
|
7 |
+
|
8 |
+
To figure out the best place to sit, you start by grabbing a map (your puzzle input) from a nearby kiosk. For example:
|
9 |
+
|
10 |
+
###############
|
11 |
+
#.......#....E#
|
12 |
+
#.#.###.#.###.#
|
13 |
+
#.....#.#...#.#
|
14 |
+
#.###.#####.#.#
|
15 |
+
#.#.#.......#.#
|
16 |
+
#.#.#####.###.#
|
17 |
+
#...........#.#
|
18 |
+
###.#.#####.#.#
|
19 |
+
#...#.....#.#.#
|
20 |
+
#.#.#.###.#.#.#
|
21 |
+
#.....#...#.#.#
|
22 |
+
#.###.#.#.#.#.#
|
23 |
+
#S..#.....#...#
|
24 |
+
###############
|
25 |
+
There are many paths through this maze, but taking any of the best paths would incur a score of only 7036. This can be achieved by taking a total of 36 steps forward and turning 90 degrees a total of 7 times:
|
26 |
+
|
27 |
+
|
28 |
+
###############
|
29 |
+
#.......#....E#
|
30 |
+
#.#.###.#.###^#
|
31 |
+
#.....#.#...#^#
|
32 |
+
#.###.#####.#^#
|
33 |
+
#.#.#.......#^#
|
34 |
+
#.#.#####.###^#
|
35 |
+
#..>>>>>>>>v#^#
|
36 |
+
###^#.#####v#^#
|
37 |
+
#>>^#.....#v#^#
|
38 |
+
#^#.#.###.#v#^#
|
39 |
+
#^....#...#v#^#
|
40 |
+
#^###.#.#.#v#^#
|
41 |
+
#S..#.....#>>^#
|
42 |
+
###############
|
43 |
+
Here's a second example:
|
44 |
+
|
45 |
+
#################
|
46 |
+
#...#...#...#..E#
|
47 |
+
#.#.#.#.#.#.#.#.#
|
48 |
+
#.#.#.#...#...#.#
|
49 |
+
#.#.#.#.###.#.#.#
|
50 |
+
#...#.#.#.....#.#
|
51 |
+
#.#.#.#.#.#####.#
|
52 |
+
#.#...#.#.#.....#
|
53 |
+
#.#.#####.#.###.#
|
54 |
+
#.#.#.......#...#
|
55 |
+
#.#.###.#####.###
|
56 |
+
#.#.#...#.....#.#
|
57 |
+
#.#.#.#####.###.#
|
58 |
+
#.#.#.........#.#
|
59 |
+
#.#.#.#########.#
|
60 |
+
#S#.............#
|
61 |
+
#################
|
62 |
+
In this maze, the best paths cost 11048 points; following one such path would look like this:
|
63 |
+
|
64 |
+
#################
|
65 |
+
#...#...#...#..E#
|
66 |
+
#.#.#.#.#.#.#.#^#
|
67 |
+
#.#.#.#...#...#^#
|
68 |
+
#.#.#.#.###.#.#^#
|
69 |
+
#>>v#.#.#.....#^#
|
70 |
+
#^#v#.#.#.#####^#
|
71 |
+
#^#v..#.#.#>>>>^#
|
72 |
+
#^#v#####.#^###.#
|
73 |
+
#^#v#..>>>>^#...#
|
74 |
+
#^#v###^#####.###
|
75 |
+
#^#v#>>^#.....#.#
|
76 |
+
#^#v#^#####.###.#
|
77 |
+
#^#v#^........#.#
|
78 |
+
#^#v#^#########.#
|
79 |
+
#S#>>^..........#
|
80 |
+
#################
|
81 |
+
Note that the path shown above includes one 90 degree turn as the very first move, rotating the Reindeer from facing East to facing North.
|
82 |
+
|
83 |
+
Analyze your map carefully. What is the lowest score a Reindeer could possibly get?
|
84 |
+
|
85 |
+
The first half of this puzzle is complete! It provides one gold star: *
|
86 |
+
|
87 |
+
--- Part Two ---
|
88 |
+
Now that you know what the best paths look like, you can figure out the best spot to sit.
|
89 |
+
|
90 |
+
Every non-wall tile (S, ., or E) is equipped with places to sit along the edges of the tile. While determining which of these tiles would be the best spot to sit depends on a whole bunch of factors (how comfortable the seats are, how far away the bathrooms are, whether there's a pillar blocking your view, etc.), the most important factor is whether the tile is on one of the best paths through the maze. If you sit somewhere else, you'd miss all the action!
|
91 |
+
|
92 |
+
So, you'll need to determine which tiles are part of any best path through the maze, including the S and E tiles.
|
93 |
+
|
94 |
+
In the first example, there are 45 tiles (marked O) that are part of at least one of the various best paths through the maze:
|
95 |
+
|
96 |
+
###############
|
97 |
+
#.......#....O#
|
98 |
+
#.#.###.#.###O#
|
99 |
+
#.....#.#...#O#
|
100 |
+
#.###.#####.#O#
|
101 |
+
#.#.#.......#O#
|
102 |
+
#.#.#####.###O#
|
103 |
+
#..OOOOOOOOO#O#
|
104 |
+
###O#O#####O#O#
|
105 |
+
#OOO#O....#O#O#
|
106 |
+
#O#O#O###.#O#O#
|
107 |
+
#OOOOO#...#O#O#
|
108 |
+
#O###.#.#.#O#O#
|
109 |
+
#O..#.....#OOO#
|
110 |
+
###############
|
111 |
+
In the second example, there are 64 tiles that are part of at least one of the best paths:
|
112 |
+
|
113 |
+
#################
|
114 |
+
#...#...#...#..O#
|
115 |
+
#.#.#.#.#.#.#.#O#
|
116 |
+
#.#.#.#...#...#O#
|
117 |
+
#.#.#.#.###.#.#O#
|
118 |
+
#OOO#.#.#.....#O#
|
119 |
+
#O#O#.#.#.#####O#
|
120 |
+
#O#O..#.#.#OOOOO#
|
121 |
+
#O#O#####.#O###O#
|
122 |
+
#O#O#..OOOOO#OOO#
|
123 |
+
#O#O###O#####O###
|
124 |
+
#O#O#OOO#..OOO#.#
|
125 |
+
#O#O#O#####O###.#
|
126 |
+
#O#O#OOOOOOO..#.#
|
127 |
+
#O#O#O#########.#
|
128 |
+
#O#OOO..........#
|
129 |
+
#################
|
130 |
+
Analyze your map further. How many tiles are part of at least one of the best paths through the maze?
|
131 |
+
|
day17/problem.txt
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 17: Chronospatial Computer ---
|
2 |
+
The Historians push the button on their strange device, but this time, you all just feel like you're falling.
|
3 |
+
|
4 |
+
"Situation critical", the device announces in a familiar voice. "Bootstrapping process failed. Initializing debugger...."
|
5 |
+
|
6 |
+
The small handheld device suddenly unfolds into an entire computer! The Historians look around nervously before one of them tosses it to you.
|
7 |
+
|
8 |
+
This seems to be a 3-bit computer: its program is a list of 3-bit numbers (0 through 7), like 0,1,2,3. The computer also has three registers named A, B, and C, but these registers aren't limited to 3 bits and can instead hold any integer.
|
9 |
+
|
10 |
+
The computer knows eight instructions, each identified by a 3-bit number (called the instruction's opcode). Each instruction also reads the 3-bit number after it as an input; this is called its operand.
|
11 |
+
|
12 |
+
A number called the instruction pointer identifies the position in the program from which the next opcode will be read; it starts at 0, pointing at the first 3-bit number in the program. Except for jump instructions, the instruction pointer increases by 2 after each instruction is processed (to move past the instruction's opcode and its operand). If the computer tries to read an opcode past the end of the program, it instead halts.
|
13 |
+
|
14 |
+
So, the program 0,1,2,3 would run the instruction whose opcode is 0 and pass it the operand 1, then run the instruction having opcode 2 and pass it the operand 3, then halt.
|
15 |
+
|
16 |
+
There are two types of operands; each instruction specifies the type of its operand. The value of a literal operand is the operand itself. For example, the value of the literal operand 7 is the number 7. The value of a combo operand can be found as follows:
|
17 |
+
|
18 |
+
Combo operands 0 through 3 represent literal values 0 through 3.
|
19 |
+
Combo operand 4 represents the value of register A.
|
20 |
+
Combo operand 5 represents the value of register B.
|
21 |
+
Combo operand 6 represents the value of register C.
|
22 |
+
Combo operand 7 is reserved and will not appear in valid programs.
|
23 |
+
The eight instructions are as follows:
|
24 |
+
|
25 |
+
The adv instruction (opcode 0) performs division. The numerator is the value in the A register. The denominator is found by raising 2 to the power of the instruction's combo operand. (So, an operand of 2 would divide A by 4 (2^2); an operand of 5 would divide A by 2^B.) The result of the division operation is truncated to an integer and then written to the A register.
|
26 |
+
|
27 |
+
The bxl instruction (opcode 1) calculates the bitwise XOR of register B and the instruction's literal operand, then stores the result in register B.
|
28 |
+
|
29 |
+
The bst instruction (opcode 2) calculates the value of its combo operand modulo 8 (thereby keeping only its lowest 3 bits), then writes that value to the B register.
|
30 |
+
|
31 |
+
The jnz instruction (opcode 3) does nothing if the A register is 0. However, if the A register is not zero, it jumps by setting the instruction pointer to the value of its literal operand; if this instruction jumps, the instruction pointer is not increased by 2 after this instruction.
|
32 |
+
|
33 |
+
The bxc instruction (opcode 4) calculates the bitwise XOR of register B and register C, then stores the result in register B. (For legacy reasons, this instruction reads an operand but ignores it.)
|
34 |
+
|
35 |
+
The out instruction (opcode 5) calculates the value of its combo operand modulo 8, then outputs that value. (If a program outputs multiple values, they are separated by commas.)
|
36 |
+
|
37 |
+
The bdv instruction (opcode 6) works exactly like the adv instruction except that the result is stored in the B register. (The numerator is still read from the A register.)
|
38 |
+
|
39 |
+
The cdv instruction (opcode 7) works exactly like the adv instruction except that the result is stored in the C register. (The numerator is still read from the A register.)
|
40 |
+
|
41 |
+
Here are some examples of instruction operation:
|
42 |
+
|
43 |
+
If register C contains 9, the program 2,6 would set register B to 1.
|
44 |
+
If register A contains 10, the program 5,0,5,1,5,4 would output 0,1,2.
|
45 |
+
If register A contains 2024, the program 0,1,5,4,3,0 would output 4,2,5,6,7,7,7,7,3,1,0 and leave 0 in register A.
|
46 |
+
If register B contains 29, the program 1,7 would set register B to 26.
|
47 |
+
If register B contains 2024 and register C contains 43690, the program 4,0 would set register B to 44354.
|
48 |
+
The Historians' strange device has finished initializing its debugger and is displaying some information about the program it is trying to run (your puzzle input). For example:
|
49 |
+
|
50 |
+
Register A: 729
|
51 |
+
Register B: 0
|
52 |
+
Register C: 0
|
53 |
+
|
54 |
+
Program: 0,1,5,4,3,0
|
55 |
+
Your first task is to determine what the program is trying to output. To do this, initialize the registers to the given values, then run the given program, collecting any output produced by out instructions. (Always join the values produced by out instructions with commas.) After the above program halts, its final output will be 4,6,3,5,6,3,5,2,1,0.
|
56 |
+
|
57 |
+
Using the information provided by the debugger, initialize the registers to the given values, then run the program. Once it halts, what do you get if you use commas to join the values it output into a single string?
|
58 |
+
|
59 |
+
The first half of this puzzle is complete! It provides one gold star: *
|
60 |
+
|
61 |
+
--- Part Two ---
|
62 |
+
Digging deeper in the device's manual, you discover the problem: this program is supposed to output another copy of the program! Unfortunately, the value in register A seems to have been corrupted. You'll need to find a new value to which you can initialize register A so that the program's output instructions produce an exact copy of the program itself.
|
63 |
+
|
64 |
+
For example:
|
65 |
+
|
66 |
+
Register A: 2024
|
67 |
+
Register B: 0
|
68 |
+
Register C: 0
|
69 |
+
|
70 |
+
Program: 0,3,5,4,3,0
|
71 |
+
This program outputs a copy of itself if register A is instead initialized to 117440. (The original initial value of register A, 2024, is ignored.)
|
72 |
+
|
73 |
+
What is the lowest positive initial value for register A that causes the program to output a copy of itself?
|
74 |
+
|
day18/problem.txt
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 18: RAM Run ---
|
2 |
+
You and The Historians look a lot more pixelated than you remember. You're inside a computer at the North Pole!
|
3 |
+
|
4 |
+
Just as you're about to check out your surroundings, a program runs up to you. "This region of memory isn't safe! The User misunderstood what a pushdown automaton is and their algorithm is pushing whole bytes down on top of us! Run!"
|
5 |
+
|
6 |
+
The algorithm is fast - it's going to cause a byte to fall into your memory space once every nanosecond! Fortunately, you're faster, and by quickly scanning the algorithm, you create a list of which bytes will fall (your puzzle input) in the order they'll land in your memory space.
|
7 |
+
|
8 |
+
Your memory space is a two-dimensional grid with coordinates that range from 0 to 70 both horizontally and vertically. However, for the sake of example, suppose you're on a smaller grid with coordinates that range from 0 to 6 and the following list of incoming byte positions:
|
9 |
+
|
10 |
+
5,4
|
11 |
+
4,2
|
12 |
+
4,5
|
13 |
+
3,0
|
14 |
+
2,1
|
15 |
+
6,3
|
16 |
+
2,4
|
17 |
+
1,5
|
18 |
+
0,6
|
19 |
+
3,3
|
20 |
+
2,6
|
21 |
+
5,1
|
22 |
+
1,2
|
23 |
+
5,5
|
24 |
+
2,5
|
25 |
+
6,5
|
26 |
+
1,4
|
27 |
+
0,4
|
28 |
+
6,4
|
29 |
+
1,1
|
30 |
+
6,1
|
31 |
+
1,0
|
32 |
+
0,5
|
33 |
+
1,6
|
34 |
+
2,0
|
35 |
+
Each byte position is given as an X,Y coordinate, where X is the distance from the left edge of your memory space and Y is the distance from the top edge of your memory space.
|
36 |
+
|
37 |
+
You and The Historians are currently in the top left corner of the memory space (at 0,0) and need to reach the exit in the bottom right corner (at 70,70 in your memory space, but at 6,6 in this example). You'll need to simulate the falling bytes to plan out where it will be safe to run; for now, simulate just the first few bytes falling into your memory space.
|
38 |
+
|
39 |
+
As bytes fall into your memory space, they make that coordinate corrupted. Corrupted memory coordinates cannot be entered by you or The Historians, so you'll need to plan your route carefully. You also cannot leave the boundaries of the memory space; your only hope is to reach the exit.
|
40 |
+
|
41 |
+
In the above example, if you were to draw the memory space after the first 12 bytes have fallen (using . for safe and # for corrupted), it would look like this:
|
42 |
+
|
43 |
+
...#...
|
44 |
+
..#..#.
|
45 |
+
....#..
|
46 |
+
...#..#
|
47 |
+
..#..#.
|
48 |
+
.#..#..
|
49 |
+
#.#....
|
50 |
+
You can take steps up, down, left, or right. After just 12 bytes have corrupted locations in your memory space, the shortest path from the top left corner to the exit would take 22 steps. Here (marked with O) is one such path:
|
51 |
+
|
52 |
+
OO.#OOO
|
53 |
+
.O#OO#O
|
54 |
+
.OOO#OO
|
55 |
+
...#OO#
|
56 |
+
..#OO#.
|
57 |
+
.#.O#..
|
58 |
+
#.#OOOO
|
59 |
+
Simulate the first kilobyte (1024 bytes) falling onto your memory space. Afterward, what is the minimum number of steps needed to reach the exit?
|
60 |
+
|
61 |
+
|
62 |
+
--- Part Two ---
|
63 |
+
The Historians aren't as used to moving around in this pixelated universe as you are. You're afraid they're not going to be fast enough to make it to the exit before the path is completely blocked.
|
64 |
+
|
65 |
+
To determine how fast everyone needs to go, you need to determine the first byte that will cut off the path to the exit.
|
66 |
+
|
67 |
+
In the above example, after the byte at 1,1 falls, there is still a path to the exit:
|
68 |
+
|
69 |
+
O..#OOO
|
70 |
+
O##OO#O
|
71 |
+
O#OO#OO
|
72 |
+
OOO#OO#
|
73 |
+
###OO##
|
74 |
+
.##O###
|
75 |
+
#.#OOOO
|
76 |
+
However, after adding the very next byte (at 6,1), there is no longer a path to the exit:
|
77 |
+
|
78 |
+
...#...
|
79 |
+
.##..##
|
80 |
+
.#..#..
|
81 |
+
...#..#
|
82 |
+
###..##
|
83 |
+
.##.###
|
84 |
+
#.#....
|
85 |
+
So, in this example, the coordinates of the first byte that prevents the exit from being reachable are 6,1.
|
86 |
+
|
87 |
+
Simulate more of the bytes that are about to corrupt your memory space. What are the coordinates of the first byte that will prevent the exit from being reachable from your starting position? (Provide the answer as two integers separated by a comma with no other characters.)
|
day19/problem.txt
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 19: Linen Layout ---
|
2 |
+
Today, The Historians take you up to the hot springs on Gear Island! Very suspiciously, absolutely nothing goes wrong as they begin their careful search of the vast field of helixes.
|
3 |
+
|
4 |
+
Could this finally be your chance to visit the onsen next door? Only one way to find out.
|
5 |
+
|
6 |
+
After a brief conversation with the reception staff at the onsen front desk, you discover that you don't have the right kind of money to pay the admission fee. However, before you can leave, the staff get your attention. Apparently, they've heard about how you helped at the hot springs, and they're willing to make a deal: if you can simply help them arrange their towels, they'll let you in for free!
|
7 |
+
|
8 |
+
Every towel at this onsen is marked with a pattern of colored stripes. There are only a few patterns, but for any particular pattern, the staff can get you as many towels with that pattern as you need. Each stripe can be white (w), blue (u), black (b), red (r), or green (g). So, a towel with the pattern ggr would have a green stripe, a green stripe, and then a red stripe, in that order. (You can't reverse a pattern by flipping a towel upside-down, as that would cause the onsen logo to face the wrong way.)
|
9 |
+
|
10 |
+
The Official Onsen Branding Expert has produced a list of designs - each a long sequence of stripe colors - that they would like to be able to display. You can use any towels you want, but all of the towels' stripes must exactly match the desired design. So, to display the design rgrgr, you could use two rg towels and then an r towel, an rgr towel and then a gr towel, or even a single massive rgrgr towel (assuming such towel patterns were actually available).
|
11 |
+
|
12 |
+
To start, collect together all of the available towel patterns and the list of desired designs (your puzzle input). For example:
|
13 |
+
|
14 |
+
r, wr, b, g, bwu, rb, gb, br
|
15 |
+
|
16 |
+
brwrr
|
17 |
+
bggr
|
18 |
+
gbbr
|
19 |
+
rrbgbr
|
20 |
+
ubwu
|
21 |
+
bwurrg
|
22 |
+
brgr
|
23 |
+
bbrgwb
|
24 |
+
The first line indicates the available towel patterns; in this example, the onsen has unlimited towels with a single red stripe (r), unlimited towels with a white stripe and then a red stripe (wr), and so on.
|
25 |
+
|
26 |
+
After the blank line, the remaining lines each describe a design the onsen would like to be able to display. In this example, the first design (brwrr) indicates that the onsen would like to be able to display a black stripe, a red stripe, a white stripe, and then two red stripes, in that order.
|
27 |
+
|
28 |
+
Not all designs will be possible with the available towels. In the above example, the designs are possible or impossible as follows:
|
29 |
+
|
30 |
+
brwrr can be made with a br towel, then a wr towel, and then finally an r towel.
|
31 |
+
bggr can be made with a b towel, two g towels, and then an r towel.
|
32 |
+
gbbr can be made with a gb towel and then a br towel.
|
33 |
+
rrbgbr can be made with r, rb, g, and br.
|
34 |
+
ubwu is impossible.
|
35 |
+
bwurrg can be made with bwu, r, r, and g.
|
36 |
+
brgr can be made with br, g, and r.
|
37 |
+
bbrgwb is impossible.
|
38 |
+
In this example, 6 of the eight designs are possible with the available towel patterns.
|
39 |
+
|
40 |
+
To get into the onsen as soon as possible, consult your list of towel patterns and desired designs carefully. How many designs are possible?
|
41 |
+
|
42 |
+
The first half of this puzzle is complete! It provides one gold star: *
|
43 |
+
|
44 |
+
--- Part Two ---
|
45 |
+
The staff don't really like some of the towel arrangements you came up with. To avoid an endless cycle of towel rearrangement, maybe you should just give them every possible option.
|
46 |
+
|
47 |
+
Here are all of the different ways the above example's designs can be made:
|
48 |
+
|
49 |
+
brwrr can be made in two different ways: b, r, wr, r or br, wr, r.
|
50 |
+
|
51 |
+
bggr can only be made with b, g, g, and r.
|
52 |
+
|
53 |
+
gbbr can be made 4 different ways:
|
54 |
+
|
55 |
+
g, b, b, r
|
56 |
+
g, b, br
|
57 |
+
gb, b, r
|
58 |
+
gb, br
|
59 |
+
rrbgbr can be made 6 different ways:
|
60 |
+
|
61 |
+
r, r, b, g, b, r
|
62 |
+
r, r, b, g, br
|
63 |
+
r, r, b, gb, r
|
64 |
+
r, rb, g, b, r
|
65 |
+
r, rb, g, br
|
66 |
+
r, rb, gb, r
|
67 |
+
bwurrg can only be made with bwu, r, r, and g.
|
68 |
+
|
69 |
+
brgr can be made in two different ways: b, r, g, r or br, g, r.
|
70 |
+
|
71 |
+
ubwu and bbrgwb are still impossible.
|
72 |
+
|
73 |
+
Adding up all of the ways the towels in this example could be arranged into the desired designs yields 16 (2 + 1 + 4 + 6 + 1 + 2).
|
74 |
+
|
75 |
+
They'll let you into the onsen as soon as you have the list. What do you get if you add up the number of different ways you could make each design?
|
76 |
+
|
day20/problem.txt
ADDED
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 20: Race Condition ---
|
2 |
+
The Historians are quite pixelated again. This time, a massive, black building looms over you - you're right outside the CPU!
|
3 |
+
|
4 |
+
While The Historians get to work, a nearby program sees that you're idle and challenges you to a race. Apparently, you've arrived just in time for the frequently-held race condition festival!
|
5 |
+
|
6 |
+
The race takes place on a particularly long and twisting code path; programs compete to see who can finish in the fewest picoseconds. The winner even gets their very own mutex!
|
7 |
+
|
8 |
+
They hand you a map of the racetrack (your puzzle input). For example:
|
9 |
+
|
10 |
+
###############
|
11 |
+
#...#...#.....#
|
12 |
+
#.#.#.#.#.###.#
|
13 |
+
#S#...#.#.#...#
|
14 |
+
#######.#.#.###
|
15 |
+
#######.#.#...#
|
16 |
+
#######.#.###.#
|
17 |
+
###..E#...#...#
|
18 |
+
###.#######.###
|
19 |
+
#...###...#...#
|
20 |
+
#.#####.#.###.#
|
21 |
+
#.#...#.#.#...#
|
22 |
+
#.#.#.#.#.#.###
|
23 |
+
#...#...#...###
|
24 |
+
###############
|
25 |
+
The map consists of track (.) - including the start (S) and end (E) positions (both of which also count as track) - and walls (#).
|
26 |
+
|
27 |
+
When a program runs through the racetrack, it starts at the start position. Then, it is allowed to move up, down, left, or right; each such move takes 1 picosecond. The goal is to reach the end position as quickly as possible. In this example racetrack, the fastest time is 84 picoseconds.
|
28 |
+
|
29 |
+
Because there is only a single path from the start to the end and the programs all go the same speed, the races used to be pretty boring. To make things more interesting, they introduced a new rule to the races: programs are allowed to cheat.
|
30 |
+
|
31 |
+
The rules for cheating are very strict. Exactly once during a race, a program may disable collision for up to 2 picoseconds. This allows the program to pass through walls as if they were regular track. At the end of the cheat, the program must be back on normal track again; otherwise, it will receive a segmentation fault and get disqualified.
|
32 |
+
|
33 |
+
So, a program could complete the course in 72 picoseconds (saving 12 picoseconds) by cheating for the two moves marked 1 and 2:
|
34 |
+
|
35 |
+
###############
|
36 |
+
#...#...12....#
|
37 |
+
#.#.#.#.#.###.#
|
38 |
+
#S#...#.#.#...#
|
39 |
+
#######.#.#.###
|
40 |
+
#######.#.#...#
|
41 |
+
#######.#.###.#
|
42 |
+
###..E#...#...#
|
43 |
+
###.#######.###
|
44 |
+
#...###...#...#
|
45 |
+
#.#####.#.###.#
|
46 |
+
#.#...#.#.#...#
|
47 |
+
#.#.#.#.#.#.###
|
48 |
+
#...#...#...###
|
49 |
+
###############
|
50 |
+
Or, a program could complete the course in 64 picoseconds (saving 20 picoseconds) by cheating for the two moves marked 1 and 2:
|
51 |
+
|
52 |
+
###############
|
53 |
+
#...#...#.....#
|
54 |
+
#.#.#.#.#.###.#
|
55 |
+
#S#...#.#.#...#
|
56 |
+
#######.#.#.###
|
57 |
+
#######.#.#...#
|
58 |
+
#######.#.###.#
|
59 |
+
###..E#...12..#
|
60 |
+
###.#######.###
|
61 |
+
#...###...#...#
|
62 |
+
#.#####.#.###.#
|
63 |
+
#.#...#.#.#...#
|
64 |
+
#.#.#.#.#.#.###
|
65 |
+
#...#...#...###
|
66 |
+
###############
|
67 |
+
This cheat saves 38 picoseconds:
|
68 |
+
|
69 |
+
###############
|
70 |
+
#...#...#.....#
|
71 |
+
#.#.#.#.#.###.#
|
72 |
+
#S#...#.#.#...#
|
73 |
+
#######.#.#.###
|
74 |
+
#######.#.#...#
|
75 |
+
#######.#.###.#
|
76 |
+
###..E#...#...#
|
77 |
+
###.####1##.###
|
78 |
+
#...###.2.#...#
|
79 |
+
#.#####.#.###.#
|
80 |
+
#.#...#.#.#...#
|
81 |
+
#.#.#.#.#.#.###
|
82 |
+
#...#...#...###
|
83 |
+
###############
|
84 |
+
This cheat saves 64 picoseconds and takes the program directly to the end:
|
85 |
+
|
86 |
+
###############
|
87 |
+
#...#...#.....#
|
88 |
+
#.#.#.#.#.###.#
|
89 |
+
#S#...#.#.#...#
|
90 |
+
#######.#.#.###
|
91 |
+
#######.#.#...#
|
92 |
+
#######.#.###.#
|
93 |
+
###..21...#...#
|
94 |
+
###.#######.###
|
95 |
+
#...###...#...#
|
96 |
+
#.#####.#.###.#
|
97 |
+
#.#...#.#.#...#
|
98 |
+
#.#.#.#.#.#.###
|
99 |
+
#...#...#...###
|
100 |
+
###############
|
101 |
+
Each cheat has a distinct start position (the position where the cheat is activated, just before the first move that is allowed to go through walls) and end position; cheats are uniquely identified by their start position and end position.
|
102 |
+
|
103 |
+
In this example, the total number of cheats (grouped by the amount of time they save) are as follows:
|
104 |
+
|
105 |
+
There are 14 cheats that save 2 picoseconds.
|
106 |
+
There are 14 cheats that save 4 picoseconds.
|
107 |
+
There are 2 cheats that save 6 picoseconds.
|
108 |
+
There are 4 cheats that save 8 picoseconds.
|
109 |
+
There are 2 cheats that save 10 picoseconds.
|
110 |
+
There are 3 cheats that save 12 picoseconds.
|
111 |
+
There is one cheat that saves 20 picoseconds.
|
112 |
+
There is one cheat that saves 36 picoseconds.
|
113 |
+
There is one cheat that saves 38 picoseconds.
|
114 |
+
There is one cheat that saves 40 picoseconds.
|
115 |
+
There is one cheat that saves 64 picoseconds.
|
116 |
+
You aren't sure what the conditions of the racetrack will be like, so to give yourself as many options as possible, you'll need a list of the best cheats. How many cheats would save you at least 100 picoseconds?
|
117 |
+
|
118 |
+
The first half of this puzzle is complete! It provides one gold star: *
|
119 |
+
|
120 |
+
--- Part Two ---
|
121 |
+
The programs seem perplexed by your list of cheats. Apparently, the two-picosecond cheating rule was deprecated several milliseconds ago! The latest version of the cheating rule permits a single cheat that instead lasts at most 20 picoseconds.
|
122 |
+
|
123 |
+
Now, in addition to all the cheats that were possible in just two picoseconds, many more cheats are possible. This six-picosecond cheat saves 76 picoseconds:
|
124 |
+
|
125 |
+
###############
|
126 |
+
#...#...#.....#
|
127 |
+
#.#.#.#.#.###.#
|
128 |
+
#S#...#.#.#...#
|
129 |
+
#1#####.#.#.###
|
130 |
+
#2#####.#.#...#
|
131 |
+
#3#####.#.###.#
|
132 |
+
#456.E#...#...#
|
133 |
+
###.#######.###
|
134 |
+
#...###...#...#
|
135 |
+
#.#####.#.###.#
|
136 |
+
#.#...#.#.#...#
|
137 |
+
#.#.#.#.#.#.###
|
138 |
+
#...#...#...###
|
139 |
+
###############
|
140 |
+
Because this cheat has the same start and end positions as the one above, it's the same cheat, even though the path taken during the cheat is different:
|
141 |
+
|
142 |
+
###############
|
143 |
+
#...#...#.....#
|
144 |
+
#.#.#.#.#.###.#
|
145 |
+
#S12..#.#.#...#
|
146 |
+
###3###.#.#.###
|
147 |
+
###4###.#.#...#
|
148 |
+
###5###.#.###.#
|
149 |
+
###6.E#...#...#
|
150 |
+
###.#######.###
|
151 |
+
#...###...#...#
|
152 |
+
#.#####.#.###.#
|
153 |
+
#.#...#.#.#...#
|
154 |
+
#.#.#.#.#.#.###
|
155 |
+
#...#...#...###
|
156 |
+
###############
|
157 |
+
Cheats don't need to use all 20 picoseconds; cheats can last any amount of time up to and including 20 picoseconds (but can still only end when the program is on normal track). Any cheat time not used is lost; it can't be saved for another cheat later.
|
158 |
+
|
159 |
+
You'll still need a list of the best cheats, but now there are even more to choose between. Here are the quantities of cheats in this example that save 50 picoseconds or more:
|
160 |
+
|
161 |
+
There are 32 cheats that save 50 picoseconds.
|
162 |
+
There are 31 cheats that save 52 picoseconds.
|
163 |
+
There are 29 cheats that save 54 picoseconds.
|
164 |
+
There are 39 cheats that save 56 picoseconds.
|
165 |
+
There are 25 cheats that save 58 picoseconds.
|
166 |
+
There are 23 cheats that save 60 picoseconds.
|
167 |
+
There are 20 cheats that save 62 picoseconds.
|
168 |
+
There are 19 cheats that save 64 picoseconds.
|
169 |
+
There are 12 cheats that save 66 picoseconds.
|
170 |
+
There are 14 cheats that save 68 picoseconds.
|
171 |
+
There are 12 cheats that save 70 picoseconds.
|
172 |
+
There are 22 cheats that save 72 picoseconds.
|
173 |
+
There are 4 cheats that save 74 picoseconds.
|
174 |
+
There are 3 cheats that save 76 picoseconds.
|
175 |
+
Find the best cheats using the updated cheating rules. How many cheats would save you at least 100 picoseconds?
|
176 |
+
|
day21/problem.txt
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 21: Keypad Conundrum ---
|
2 |
+
As you teleport onto Santa's Reindeer-class starship, The Historians begin to panic: someone from their search party is missing. A quick life-form scan by the ship's computer reveals that when the missing Historian teleported, he arrived in another part of the ship.
|
3 |
+
|
4 |
+
The door to that area is locked, but the computer can't open it; it can only be opened by physically typing the door codes (your puzzle input) on the numeric keypad on the door.
|
5 |
+
|
6 |
+
The numeric keypad has four rows of buttons: 789, 456, 123, and finally an empty gap followed by 0A. Visually, they are arranged like this:
|
7 |
+
|
8 |
+
+---+---+---+
|
9 |
+
| 7 | 8 | 9 |
|
10 |
+
+---+---+---+
|
11 |
+
| 4 | 5 | 6 |
|
12 |
+
+---+---+---+
|
13 |
+
| 1 | 2 | 3 |
|
14 |
+
+---+---+---+
|
15 |
+
| 0 | A |
|
16 |
+
+---+---+
|
17 |
+
Unfortunately, the area outside the door is currently depressurized and nobody can go near the door. A robot needs to be sent instead.
|
18 |
+
|
19 |
+
The robot has no problem navigating the ship and finding the numeric keypad, but it's not designed for button pushing: it can't be told to push a specific button directly. Instead, it has a robotic arm that can be controlled remotely via a directional keypad.
|
20 |
+
|
21 |
+
The directional keypad has two rows of buttons: a gap / ^ (up) / A (activate) on the first row and < (left) / v (down) / > (right) on the second row. Visually, they are arranged like this:
|
22 |
+
|
23 |
+
+---+---+
|
24 |
+
| ^ | A |
|
25 |
+
+---+---+---+
|
26 |
+
| < | v | > |
|
27 |
+
+---+---+---+
|
28 |
+
When the robot arrives at the numeric keypad, its robotic arm is pointed at the A button in the bottom right corner. After that, this directional keypad remote control must be used to maneuver the robotic arm: the up / down / left / right buttons cause it to move its arm one button in that direction, and the A button causes the robot to briefly move forward, pressing the button being aimed at by the robotic arm.
|
29 |
+
|
30 |
+
For example, to make the robot type 029A on the numeric keypad, one sequence of inputs on the directional keypad you could use is:
|
31 |
+
|
32 |
+
< to move the arm from A (its initial position) to 0.
|
33 |
+
A to push the 0 button.
|
34 |
+
^A to move the arm to the 2 button and push it.
|
35 |
+
>^^A to move the arm to the 9 button and push it.
|
36 |
+
vvvA to move the arm to the A button and push it.
|
37 |
+
In total, there are three shortest possible sequences of button presses on this directional keypad that would cause the robot to type 029A: <A^A>^^AvvvA, <A^A^>^AvvvA, and <A^A^^>AvvvA.
|
38 |
+
|
39 |
+
Unfortunately, the area containing this directional keypad remote control is currently experiencing high levels of radiation and nobody can go near it. A robot needs to be sent instead.
|
40 |
+
|
41 |
+
When the robot arrives at the directional keypad, its robot arm is pointed at the A button in the upper right corner. After that, a second, different directional keypad remote control is used to control this robot (in the same way as the first robot, except that this one is typing on a directional keypad instead of a numeric keypad).
|
42 |
+
|
43 |
+
There are multiple shortest possible sequences of directional keypad button presses that would cause this robot to tell the first robot to type 029A on the door. One such sequence is v<<A>>^A<A>AvA<^AA>A<vAAA>^A.
|
44 |
+
|
45 |
+
Unfortunately, the area containing this second directional keypad remote control is currently -40 degrees! Another robot will need to be sent to type on that directional keypad, too.
|
46 |
+
|
47 |
+
There are many shortest possible sequences of directional keypad button presses that would cause this robot to tell the second robot to tell the first robot to eventually type 029A on the door. One such sequence is <vA<AA>>^AvAA<^A>A<v<A>>^AvA^A<vA>^A<v<A>^A>AAvA^A<v<A>A>^AAAvA<^A>A.
|
48 |
+
|
49 |
+
Unfortunately, the area containing this third directional keypad remote control is currently full of Historians, so no robots can find a clear path there. Instead, you will have to type this sequence yourself.
|
50 |
+
|
51 |
+
Were you to choose this sequence of button presses, here are all of the buttons that would be pressed on your directional keypad, the two robots' directional keypads, and the numeric keypad:
|
52 |
+
|
53 |
+
<vA<AA>>^AvAA<^A>A<v<A>>^AvA^A<vA>^A<v<A>^A>AAvA^A<v<A>A>^AAAvA<^A>A
|
54 |
+
v<<A>>^A<A>AvA<^AA>A<vAAA>^A
|
55 |
+
<A^A>^^AvvvA
|
56 |
+
029A
|
57 |
+
In summary, there are the following keypads:
|
58 |
+
|
59 |
+
One directional keypad that you are using.
|
60 |
+
Two directional keypads that robots are using.
|
61 |
+
One numeric keypad (on a door) that a robot is using.
|
62 |
+
It is important to remember that these robots are not designed for button pushing. In particular, if a robot arm is ever aimed at a gap where no button is present on the keypad, even for an instant, the robot will panic unrecoverably. So, don't do that. All robots will initially aim at the keypad's A key, wherever it is.
|
63 |
+
|
64 |
+
To unlock the door, five codes will need to be typed on its numeric keypad. For example:
|
65 |
+
|
66 |
+
029A
|
67 |
+
980A
|
68 |
+
179A
|
69 |
+
456A
|
70 |
+
379A
|
71 |
+
For each of these, here is a shortest sequence of button presses you could type to cause the desired code to be typed on the numeric keypad:
|
72 |
+
|
73 |
+
029A: <vA<AA>>^AvAA<^A>A<v<A>>^AvA^A<vA>^A<v<A>^A>AAvA^A<v<A>A>^AAAvA<^A>A
|
74 |
+
980A: <v<A>>^AAAvA^A<vA<AA>>^AvAA<^A>A<v<A>A>^AAAvA<^A>A<vA>^A<A>A
|
75 |
+
179A: <v<A>>^A<vA<A>>^AAvAA<^A>A<v<A>>^AAvA^A<vA>^AA<A>A<v<A>A>^AAAvA<^A>A
|
76 |
+
456A: <v<A>>^AA<vA<A>>^AAvAA<^A>A<vA>^A<A>A<vA>^A<A>A<v<A>A>^AAvA<^A>A
|
77 |
+
379A: <v<A>>^AvA^A<vA<AA>>^AAvA<^A>AAvA^A<vA>^AA<A>A<v<A>A>^AAAvA<^A>A
|
78 |
+
The Historians are getting nervous; the ship computer doesn't remember whether the missing Historian is trapped in the area containing a giant electromagnet or molten lava. You'll need to make sure that for each of the five codes, you find the shortest sequence of button presses necessary.
|
79 |
+
|
80 |
+
The complexity of a single code (like 029A) is equal to the result of multiplying these two values:
|
81 |
+
|
82 |
+
The length of the shortest sequence of button presses you need to type on your directional keypad in order to cause the code to be typed on the numeric keypad; for 029A, this would be 68.
|
83 |
+
The numeric part of the code (ignoring leading zeroes); for 029A, this would be 29.
|
84 |
+
In the above example, complexity of the five codes can be found by calculating 68 * 29, 60 * 980, 68 * 179, 64 * 456, and 64 * 379. Adding these together produces 126384.
|
85 |
+
|
86 |
+
Find the fewest number of button presses you'll need to perform in order to cause the robot in front of the door to type each code. What is the sum of the complexities of the five codes on your list?
|
87 |
+
|
88 |
+
The first half of this puzzle is complete! It provides one gold star: *
|
89 |
+
|
90 |
+
--- Part Two ---
|
91 |
+
Just as the missing Historian is released, The Historians realize that a second member of their search party has also been missing this entire time!
|
92 |
+
|
93 |
+
A quick life-form scan reveals the Historian is also trapped in a locked area of the ship. Due to a variety of hazards, robots are once again dispatched, forming another chain of remote control keypads managing robotic-arm-wielding robots.
|
94 |
+
|
95 |
+
This time, many more robots are involved. In summary, there are the following keypads:
|
96 |
+
|
97 |
+
One directional keypad that you are using.
|
98 |
+
25 directional keypads that robots are using.
|
99 |
+
One numeric keypad (on a door) that a robot is using.
|
100 |
+
The keypads form a chain, just like before: your directional keypad controls a robot which is typing on a directional keypad which controls a robot which is typing on a directional keypad... and so on, ending with the robot which is typing on the numeric keypad.
|
101 |
+
|
102 |
+
The door codes are the same this time around; only the number of robots and directional keypads has changed.
|
103 |
+
|
104 |
+
Find the fewest number of button presses you'll need to perform in order to cause the robot in front of the door to type each code. What is the sum of the complexities of the five codes on your list?
|
105 |
+
|
day22/problem.txt
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 22: Monkey Market ---
|
2 |
+
As you're all teleported deep into the jungle, a monkey steals The Historians' device! You'll need to get it back while The Historians are looking for the Chief.
|
3 |
+
|
4 |
+
The monkey that stole the device seems willing to trade it, but only in exchange for an absurd number of bananas. Your only option is to buy bananas on the Monkey Exchange Market.
|
5 |
+
|
6 |
+
You aren't sure how the Monkey Exchange Market works, but one of The Historians senses trouble and comes over to help. Apparently, they've been studying these monkeys for a while and have deciphered their secrets.
|
7 |
+
|
8 |
+
Today, the Market is full of monkeys buying good hiding spots. Fortunately, because of the time you recently spent in this jungle, you know lots of good hiding spots you can sell! If you sell enough hiding spots, you should be able to get enough bananas to buy the device back.
|
9 |
+
|
10 |
+
On the Market, the buyers seem to use random prices, but their prices are actually only pseudorandom! If you know the secret of how they pick their prices, you can wait for the perfect time to sell.
|
11 |
+
|
12 |
+
The part about secrets is literal, the Historian explains. Each buyer produces a pseudorandom sequence of secret numbers where each secret is derived from the previous.
|
13 |
+
|
14 |
+
In particular, each buyer's secret number evolves into the next secret number in the sequence via the following process:
|
15 |
+
|
16 |
+
Calculate the result of multiplying the secret number by 64. Then, mix this result into the secret number. Finally, prune the secret number.
|
17 |
+
Calculate the result of dividing the secret number by 32. Round the result down to the nearest integer. Then, mix this result into the secret number. Finally, prune the secret number.
|
18 |
+
Calculate the result of multiplying the secret number by 2048. Then, mix this result into the secret number. Finally, prune the secret number.
|
19 |
+
Each step of the above process involves mixing and pruning:
|
20 |
+
|
21 |
+
To mix a value into the secret number, calculate the bitwise XOR of the given value and the secret number. Then, the secret number becomes the result of that operation. (If the secret number is 42 and you were to mix 15 into the secret number, the secret number would become 37.)
|
22 |
+
To prune the secret number, calculate the value of the secret number modulo 16777216. Then, the secret number becomes the result of that operation. (If the secret number is 100000000 and you were to prune the secret number, the secret number would become 16113920.)
|
23 |
+
After this process completes, the buyer is left with the next secret number in the sequence. The buyer can repeat this process as many times as necessary to produce more secret numbers.
|
24 |
+
|
25 |
+
So, if a buyer had a secret number of 123, that buyer's next ten secret numbers would be:
|
26 |
+
|
27 |
+
15887950
|
28 |
+
16495136
|
29 |
+
527345
|
30 |
+
704524
|
31 |
+
1553684
|
32 |
+
12683156
|
33 |
+
11100544
|
34 |
+
12249484
|
35 |
+
7753432
|
36 |
+
5908254
|
37 |
+
Each buyer uses their own secret number when choosing their price, so it's important to be able to predict the sequence of secret numbers for each buyer. Fortunately, the Historian's research has uncovered the initial secret number of each buyer (your puzzle input). For example:
|
38 |
+
|
39 |
+
1
|
40 |
+
10
|
41 |
+
100
|
42 |
+
2024
|
43 |
+
This list describes the initial secret number of four different secret-hiding-spot-buyers on the Monkey Exchange Market. If you can simulate secret numbers from each buyer, you'll be able to predict all of their future prices.
|
44 |
+
|
45 |
+
In a single day, buyers each have time to generate 2000 new secret numbers. In this example, for each buyer, their initial secret number and the 2000th new secret number they would generate are:
|
46 |
+
|
47 |
+
1: 8685429
|
48 |
+
10: 4700978
|
49 |
+
100: 15273692
|
50 |
+
2024: 8667524
|
51 |
+
Adding up the 2000th new secret number for each buyer produces 37327623.
|
52 |
+
|
53 |
+
For each buyer, simulate the creation of 2000 new secret numbers. What is the sum of the 2000th secret number generated by each buyer?
|
54 |
+
|
55 |
+
|
56 |
+
--- Part Two ---
|
57 |
+
Of course, the secret numbers aren't the prices each buyer is offering! That would be ridiculous. Instead, the prices the buyer offers are just the ones digit of each of their secret numbers.
|
58 |
+
|
59 |
+
So, if a buyer starts with a secret number of 123, that buyer's first ten prices would be:
|
60 |
+
|
61 |
+
3 (from 123)
|
62 |
+
0 (from 15887950)
|
63 |
+
6 (from 16495136)
|
64 |
+
5 (etc.)
|
65 |
+
4
|
66 |
+
4
|
67 |
+
6
|
68 |
+
4
|
69 |
+
4
|
70 |
+
2
|
71 |
+
This price is the number of bananas that buyer is offering in exchange for your information about a new hiding spot. However, you still don't speak monkey, so you can't negotiate with the buyers directly. The Historian speaks a little, but not enough to negotiate; instead, he can ask another monkey to negotiate on your behalf.
|
72 |
+
|
73 |
+
Unfortunately, the monkey only knows how to decide when to sell by looking at the changes in price. Specifically, the monkey will only look for a specific sequence of four consecutive changes in price, then immediately sell when it sees that sequence.
|
74 |
+
|
75 |
+
So, if a buyer starts with a secret number of 123, that buyer's first ten secret numbers, prices, and the associated changes would be:
|
76 |
+
|
77 |
+
123: 3
|
78 |
+
15887950: 0 (-3)
|
79 |
+
16495136: 6 (6)
|
80 |
+
527345: 5 (-1)
|
81 |
+
704524: 4 (-1)
|
82 |
+
1553684: 4 (0)
|
83 |
+
12683156: 6 (2)
|
84 |
+
11100544: 4 (-2)
|
85 |
+
12249484: 4 (0)
|
86 |
+
7753432: 2 (-2)
|
87 |
+
Note that the first price has no associated change because there was no previous price to compare it with.
|
88 |
+
|
89 |
+
In this short example, within just these first few prices, the highest price will be 6, so it would be nice to give the monkey instructions that would make it sell at that time. The first 6 occurs after only two changes, so there's no way to instruct the monkey to sell then, but the second 6 occurs after the changes -1,-1,0,2. So, if you gave the monkey that sequence of changes, it would wait until the first time it sees that sequence and then immediately sell your hiding spot information at the current price, winning you 6 bananas.
|
90 |
+
|
91 |
+
Each buyer only wants to buy one hiding spot, so after the hiding spot is sold, the monkey will move on to the next buyer. If the monkey never hears that sequence of price changes from a buyer, the monkey will never sell, and will instead just move on to the next buyer.
|
92 |
+
|
93 |
+
Worse, you can only give the monkey a single sequence of four price changes to look for. You can't change the sequence between buyers.
|
94 |
+
|
95 |
+
You're going to need as many bananas as possible, so you'll need to determine which sequence of four price changes will cause the monkey to get you the most bananas overall. Each buyer is going to generate 2000 secret numbers after their initial secret number, so, for each buyer, you'll have 2000 price changes in which your sequence can occur.
|
96 |
+
|
97 |
+
Suppose the initial secret number of each buyer is:
|
98 |
+
|
99 |
+
1
|
100 |
+
2
|
101 |
+
3
|
102 |
+
2024
|
103 |
+
There are many sequences of four price changes you could tell the monkey, but for these four buyers, the sequence that will get you the most bananas is -2,1,-1,3. Using that sequence, the monkey will make the following sales:
|
104 |
+
|
105 |
+
For the buyer with an initial secret number of 1, changes -2,1,-1,3 first occur when the price is 7.
|
106 |
+
For the buyer with initial secret 2, changes -2,1,-1,3 first occur when the price is 7.
|
107 |
+
For the buyer with initial secret 3, the change sequence -2,1,-1,3 does not occur in the first 2000 changes.
|
108 |
+
For the buyer starting with 2024, changes -2,1,-1,3 first occur when the price is 9.
|
109 |
+
So, by asking the monkey to sell the first time each buyer's prices go down 2, then up 1, then down 1, then up 3, you would get 23 (7 + 7 + 9) bananas!
|
110 |
+
|
111 |
+
Figure out the best sequence to tell the monkey so that by looking for that same sequence of changes in every buyer's future prices, you get the most bananas in total. What is the most bananas you can get?
|
day23/problem.txt
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 23: LAN Party ---
|
2 |
+
As The Historians wander around a secure area at Easter Bunny HQ, you come across posters for a LAN party scheduled for today! Maybe you can find it; you connect to a nearby datalink port and download a map of the local network (your puzzle input).
|
3 |
+
|
4 |
+
The network map provides a list of every connection between two computers. For example:
|
5 |
+
|
6 |
+
kh-tc
|
7 |
+
qp-kh
|
8 |
+
de-cg
|
9 |
+
ka-co
|
10 |
+
yn-aq
|
11 |
+
qp-ub
|
12 |
+
cg-tb
|
13 |
+
vc-aq
|
14 |
+
tb-ka
|
15 |
+
wh-tc
|
16 |
+
yn-cg
|
17 |
+
kh-ub
|
18 |
+
ta-co
|
19 |
+
de-co
|
20 |
+
tc-td
|
21 |
+
tb-wq
|
22 |
+
wh-td
|
23 |
+
ta-ka
|
24 |
+
td-qp
|
25 |
+
aq-cg
|
26 |
+
wq-ub
|
27 |
+
ub-vc
|
28 |
+
de-ta
|
29 |
+
wq-aq
|
30 |
+
wq-vc
|
31 |
+
wh-yn
|
32 |
+
ka-de
|
33 |
+
kh-ta
|
34 |
+
co-tc
|
35 |
+
wh-qp
|
36 |
+
tb-vc
|
37 |
+
td-yn
|
38 |
+
Each line of text in the network map represents a single connection; the line kh-tc represents a connection between the computer named kh and the computer named tc. Connections aren't directional; tc-kh would mean exactly the same thing.
|
39 |
+
|
40 |
+
LAN parties typically involve multiplayer games, so maybe you can locate it by finding groups of connected computers. Start by looking for sets of three computers where each computer in the set is connected to the other two computers.
|
41 |
+
|
42 |
+
In this example, there are 12 such sets of three inter-connected computers:
|
43 |
+
|
44 |
+
aq,cg,yn
|
45 |
+
aq,vc,wq
|
46 |
+
co,de,ka
|
47 |
+
co,de,ta
|
48 |
+
co,ka,ta
|
49 |
+
de,ka,ta
|
50 |
+
kh,qp,ub
|
51 |
+
qp,td,wh
|
52 |
+
tb,vc,wq
|
53 |
+
tc,td,wh
|
54 |
+
td,wh,yn
|
55 |
+
ub,vc,wq
|
56 |
+
If the Chief Historian is here, and he's at the LAN party, it would be best to know that right away. You're pretty sure his computer's name starts with t, so consider only sets of three computers where at least one computer's name starts with t. That narrows the list down to 7 sets of three inter-connected computers:
|
57 |
+
|
58 |
+
co,de,ta
|
59 |
+
co,ka,ta
|
60 |
+
de,ka,ta
|
61 |
+
qp,td,wh
|
62 |
+
tb,vc,wq
|
63 |
+
tc,td,wh
|
64 |
+
td,wh,yn
|
65 |
+
Find all the sets of three inter-connected computers. How many contain at least one computer with a name that starts with t?
|
66 |
+
|
67 |
+
|
68 |
+
--- Part Two ---
|
69 |
+
There are still way too many results to go through them all. You'll have to find the LAN party another way and go there yourself.
|
70 |
+
|
71 |
+
Since it doesn't seem like any employees are around, you figure they must all be at the LAN party. If that's true, the LAN party will be the largest set of computers that are all connected to each other. That is, for each computer at the LAN party, that computer will have a connection to every other computer at the LAN party.
|
72 |
+
|
73 |
+
In the above example, the largest set of computers that are all connected to each other is made up of co, de, ka, and ta. Each computer in this set has a connection to every other computer in the set:
|
74 |
+
|
75 |
+
ka-co
|
76 |
+
ta-co
|
77 |
+
de-co
|
78 |
+
ta-ka
|
79 |
+
de-ta
|
80 |
+
ka-de
|
81 |
+
The LAN party posters say that the password to get into the LAN party is the name of every computer at the LAN party, sorted alphabetically, then joined together with commas. (The people running the LAN party are clearly a bunch of nerds.) In this example, the password would be co,de,ka,ta.
|
82 |
+
|
83 |
+
What is the password to get into the LAN party?
|
day24/problem.txt
ADDED
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 24: Crossed Wires ---
|
2 |
+
You and The Historians arrive at the edge of a large grove somewhere in the jungle. After the last incident, the Elves installed a small device that monitors the fruit. While The Historians search the grove, one of them asks if you can take a look at the monitoring device; apparently, it's been malfunctioning recently.
|
3 |
+
|
4 |
+
The device seems to be trying to produce a number through some boolean logic gates. Each gate has two inputs and one output. The gates all operate on values that are either true (1) or false (0).
|
5 |
+
|
6 |
+
AND gates output 1 if both inputs are 1; if either input is 0, these gates output 0.
|
7 |
+
OR gates output 1 if one or both inputs is 1; if both inputs are 0, these gates output 0.
|
8 |
+
XOR gates output 1 if the inputs are different; if the inputs are the same, these gates output 0.
|
9 |
+
Gates wait until both inputs are received before producing output; wires can carry 0, 1 or no value at all. There are no loops; once a gate has determined its output, the output will not change until the whole system is reset. Each wire is connected to at most one gate output, but can be connected to many gate inputs.
|
10 |
+
|
11 |
+
Rather than risk getting shocked while tinkering with the live system, you write down all of the gate connections and initial wire values (your puzzle input) so you can consider them in relative safety. For example:
|
12 |
+
|
13 |
+
x00: 1
|
14 |
+
x01: 1
|
15 |
+
x02: 1
|
16 |
+
y00: 0
|
17 |
+
y01: 1
|
18 |
+
y02: 0
|
19 |
+
|
20 |
+
x00 AND y00 -> z00
|
21 |
+
x01 XOR y01 -> z01
|
22 |
+
x02 OR y02 -> z02
|
23 |
+
Because gates wait for input, some wires need to start with a value (as inputs to the entire system). The first section specifies these values. For example, x00: 1 means that the wire named x00 starts with the value 1 (as if a gate is already outputting that value onto that wire).
|
24 |
+
|
25 |
+
The second section lists all of the gates and the wires connected to them. For example, x00 AND y00 -> z00 describes an instance of an AND gate which has wires x00 and y00 connected to its inputs and which will write its output to wire z00.
|
26 |
+
|
27 |
+
In this example, simulating these gates eventually causes 0 to appear on wire z00, 0 to appear on wire z01, and 1 to appear on wire z02.
|
28 |
+
|
29 |
+
Ultimately, the system is trying to produce a number by combining the bits on all wires starting with z. z00 is the least significant bit, then z01, then z02, and so on.
|
30 |
+
|
31 |
+
In this example, the three output bits form the binary number 100 which is equal to the decimal number 4.
|
32 |
+
|
33 |
+
Here's a larger example:
|
34 |
+
|
35 |
+
x00: 1
|
36 |
+
x01: 0
|
37 |
+
x02: 1
|
38 |
+
x03: 1
|
39 |
+
x04: 0
|
40 |
+
y00: 1
|
41 |
+
y01: 1
|
42 |
+
y02: 1
|
43 |
+
y03: 1
|
44 |
+
y04: 1
|
45 |
+
|
46 |
+
ntg XOR fgs -> mjb
|
47 |
+
y02 OR x01 -> tnw
|
48 |
+
kwq OR kpj -> z05
|
49 |
+
x00 OR x03 -> fst
|
50 |
+
tgd XOR rvg -> z01
|
51 |
+
vdt OR tnw -> bfw
|
52 |
+
bfw AND frj -> z10
|
53 |
+
ffh OR nrd -> bqk
|
54 |
+
y00 AND y03 -> djm
|
55 |
+
y03 OR y00 -> psh
|
56 |
+
bqk OR frj -> z08
|
57 |
+
tnw OR fst -> frj
|
58 |
+
gnj AND tgd -> z11
|
59 |
+
bfw XOR mjb -> z00
|
60 |
+
x03 OR x00 -> vdt
|
61 |
+
gnj AND wpb -> z02
|
62 |
+
x04 AND y00 -> kjc
|
63 |
+
djm OR pbm -> qhw
|
64 |
+
nrd AND vdt -> hwm
|
65 |
+
kjc AND fst -> rvg
|
66 |
+
y04 OR y02 -> fgs
|
67 |
+
y01 AND x02 -> pbm
|
68 |
+
ntg OR kjc -> kwq
|
69 |
+
psh XOR fgs -> tgd
|
70 |
+
qhw XOR tgd -> z09
|
71 |
+
pbm OR djm -> kpj
|
72 |
+
x03 XOR y03 -> ffh
|
73 |
+
x00 XOR y04 -> ntg
|
74 |
+
bfw OR bqk -> z06
|
75 |
+
nrd XOR fgs -> wpb
|
76 |
+
frj XOR qhw -> z04
|
77 |
+
bqk OR frj -> z07
|
78 |
+
y03 OR x01 -> nrd
|
79 |
+
hwm AND bqk -> z03
|
80 |
+
tgd XOR rvg -> z12
|
81 |
+
tnw OR pbm -> gnj
|
82 |
+
After waiting for values on all wires starting with z, the wires in this system have the following values:
|
83 |
+
|
84 |
+
bfw: 1
|
85 |
+
bqk: 1
|
86 |
+
djm: 1
|
87 |
+
ffh: 0
|
88 |
+
fgs: 1
|
89 |
+
frj: 1
|
90 |
+
fst: 1
|
91 |
+
gnj: 1
|
92 |
+
hwm: 1
|
93 |
+
kjc: 0
|
94 |
+
kpj: 1
|
95 |
+
kwq: 0
|
96 |
+
mjb: 1
|
97 |
+
nrd: 1
|
98 |
+
ntg: 0
|
99 |
+
pbm: 1
|
100 |
+
psh: 1
|
101 |
+
qhw: 1
|
102 |
+
rvg: 0
|
103 |
+
tgd: 0
|
104 |
+
tnw: 1
|
105 |
+
vdt: 1
|
106 |
+
wpb: 0
|
107 |
+
z00: 0
|
108 |
+
z01: 0
|
109 |
+
z02: 0
|
110 |
+
z03: 1
|
111 |
+
z04: 0
|
112 |
+
z05: 1
|
113 |
+
z06: 1
|
114 |
+
z07: 1
|
115 |
+
z08: 1
|
116 |
+
z09: 1
|
117 |
+
z10: 1
|
118 |
+
z11: 0
|
119 |
+
z12: 0
|
120 |
+
Combining the bits from all wires starting with z produces the binary number 0011111101000. Converting this number to decimal produces 2024.
|
121 |
+
|
122 |
+
Simulate the system of gates and wires. What decimal number does it output on the wires starting with z?
|
123 |
+
|
124 |
+
|
125 |
+
The first half of this puzzle is complete! It provides one gold star: *
|
126 |
+
|
127 |
+
--- Part Two ---
|
128 |
+
After inspecting the monitoring device more closely, you determine that the system you're simulating is trying to add two binary numbers.
|
129 |
+
|
130 |
+
Specifically, it is treating the bits on wires starting with x as one binary number, treating the bits on wires starting with y as a second binary number, and then attempting to add those two numbers together. The output of this operation is produced as a binary number on the wires starting with z. (In all three cases, wire 00 is the least significant bit, then 01, then 02, and so on.)
|
131 |
+
|
132 |
+
The initial values for the wires in your puzzle input represent just one instance of a pair of numbers that sum to the wrong value. Ultimately, any two binary numbers provided as input should be handled correctly. That is, for any combination of bits on wires starting with x and wires starting with y, the sum of the two numbers those bits represent should be produced as a binary number on the wires starting with z.
|
133 |
+
|
134 |
+
For example, if you have an addition system with four x wires, four y wires, and five z wires, you should be able to supply any four-bit number on the x wires, any four-bit number on the y numbers, and eventually find the sum of those two numbers as a five-bit number on the z wires. One of the many ways you could provide numbers to such a system would be to pass 11 on the x wires (1011 in binary) and 13 on the y wires (1101 in binary):
|
135 |
+
|
136 |
+
x00: 1
|
137 |
+
x01: 1
|
138 |
+
x02: 0
|
139 |
+
x03: 1
|
140 |
+
y00: 1
|
141 |
+
y01: 0
|
142 |
+
y02: 1
|
143 |
+
y03: 1
|
144 |
+
If the system were working correctly, then after all gates are finished processing, you should find 24 (11+13) on the z wires as the five-bit binary number 11000:
|
145 |
+
|
146 |
+
z00: 0
|
147 |
+
z01: 0
|
148 |
+
z02: 0
|
149 |
+
z03: 1
|
150 |
+
z04: 1
|
151 |
+
Unfortunately, your actual system needs to add numbers with many more bits and therefore has many more wires.
|
152 |
+
|
153 |
+
Based on forensic analysis of scuff marks and scratches on the device, you can tell that there are exactly four pairs of gates whose output wires have been swapped. (A gate can only be in at most one such pair; no gate's output was swapped multiple times.)
|
154 |
+
|
155 |
+
For example, the system below is supposed to find the bitwise AND of the six-bit number on x00 through x05 and the six-bit number on y00 through y05 and then write the result as a six-bit number on z00 through z05:
|
156 |
+
|
157 |
+
x00: 0
|
158 |
+
x01: 1
|
159 |
+
x02: 0
|
160 |
+
x03: 1
|
161 |
+
x04: 0
|
162 |
+
x05: 1
|
163 |
+
y00: 0
|
164 |
+
y01: 0
|
165 |
+
y02: 1
|
166 |
+
y03: 1
|
167 |
+
y04: 0
|
168 |
+
y05: 1
|
169 |
+
|
170 |
+
x00 AND y00 -> z05
|
171 |
+
x01 AND y01 -> z02
|
172 |
+
x02 AND y02 -> z01
|
173 |
+
x03 AND y03 -> z03
|
174 |
+
x04 AND y04 -> z04
|
175 |
+
x05 AND y05 -> z00
|
176 |
+
However, in this example, two pairs of gates have had their output wires swapped, causing the system to produce wrong answers. The first pair of gates with swapped outputs is x00 AND y00 -> z05 and x05 AND y05 -> z00; the second pair of gates is x01 AND y01 -> z02 and x02 AND y02 -> z01. Correcting these two swaps results in this system that works as intended for any set of initial values on wires that start with x or y:
|
177 |
+
|
178 |
+
x00 AND y00 -> z00
|
179 |
+
x01 AND y01 -> z01
|
180 |
+
x02 AND y02 -> z02
|
181 |
+
x03 AND y03 -> z03
|
182 |
+
x04 AND y04 -> z04
|
183 |
+
x05 AND y05 -> z05
|
184 |
+
In this example, two pairs of gates have outputs that are involved in a swap. By sorting their output wires' names and joining them with commas, the list of wires involved in swaps is z00,z01,z02,z05.
|
185 |
+
|
186 |
+
Of course, your actual system is much more complex than this, and the gates that need their outputs swapped could be anywhere, not just attached to a wire starting with z. If you were to determine that you need to swap output wires aaa with eee, ooo with z99, bbb with ccc, and aoc with z24, your answer would be aaa,aoc,bbb,ccc,eee,ooo,z24,z99.
|
187 |
+
|
188 |
+
Your system of gates and wires has four pairs of gates which need their output wires swapped - eight wires in total. Determine which four pairs of gates need their outputs swapped so that your system correctly performs addition; what do you get if you sort the names of the eight wires involved in a swap and then join those names with commas?
|
189 |
+
|
day25/problem.txt
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--- Day 25: Code Chronicle ---
|
2 |
+
Out of ideas and time, The Historians agree that they should go back to check the Chief Historian's office one last time, just in case he went back there without you noticing.
|
3 |
+
|
4 |
+
When you get there, you are surprised to discover that the door to his office is locked! You can hear someone inside, but knocking yields no response. The locks on this floor are all fancy, expensive, virtual versions of five-pin tumbler locks, so you contact North Pole security to see if they can help open the door.
|
5 |
+
|
6 |
+
Unfortunately, they've lost track of which locks are installed and which keys go with them, so the best they can do is send over schematics of every lock and every key for the floor you're on (your puzzle input).
|
7 |
+
|
8 |
+
The schematics are in a cryptic file format, but they do contain manufacturer information, so you look up their support number.
|
9 |
+
|
10 |
+
"Our Virtual Five-Pin Tumbler product? That's our most expensive model! Way more secure than--" You explain that you need to open a door and don't have a lot of time.
|
11 |
+
|
12 |
+
"Well, you can't know whether a key opens a lock without actually trying the key in the lock (due to quantum hidden variables), but you can rule out some of the key/lock combinations."
|
13 |
+
|
14 |
+
"The virtual system is complicated, but part of it really is a crude simulation of a five-pin tumbler lock, mostly for marketing reasons. If you look at the schematics, you can figure out whether a key could possibly fit in a lock."
|
15 |
+
|
16 |
+
He transmits you some example schematics:
|
17 |
+
|
18 |
+
#####
|
19 |
+
.####
|
20 |
+
.####
|
21 |
+
.####
|
22 |
+
.#.#.
|
23 |
+
.#...
|
24 |
+
.....
|
25 |
+
|
26 |
+
#####
|
27 |
+
##.##
|
28 |
+
.#.##
|
29 |
+
...##
|
30 |
+
...#.
|
31 |
+
...#.
|
32 |
+
.....
|
33 |
+
|
34 |
+
.....
|
35 |
+
#....
|
36 |
+
#....
|
37 |
+
#...#
|
38 |
+
#.#.#
|
39 |
+
#.###
|
40 |
+
#####
|
41 |
+
|
42 |
+
.....
|
43 |
+
.....
|
44 |
+
#.#..
|
45 |
+
###..
|
46 |
+
###.#
|
47 |
+
###.#
|
48 |
+
#####
|
49 |
+
|
50 |
+
.....
|
51 |
+
.....
|
52 |
+
.....
|
53 |
+
#....
|
54 |
+
#.#..
|
55 |
+
#.#.#
|
56 |
+
#####
|
57 |
+
"The locks are schematics that have the top row filled (#) and the bottom row empty (.); the keys have the top row empty and the bottom row filled. If you look closely, you'll see that each schematic is actually a set of columns of various heights, either extending downward from the top (for locks) or upward from the bottom (for keys)."
|
58 |
+
|
59 |
+
"For locks, those are the pins themselves; you can convert the pins in schematics to a list of heights, one per column. For keys, the columns make up the shape of the key where it aligns with pins; those can also be converted to a list of heights."
|
60 |
+
|
61 |
+
"So, you could say the first lock has pin heights 0,5,3,4,3:"
|
62 |
+
|
63 |
+
#####
|
64 |
+
.####
|
65 |
+
.####
|
66 |
+
.####
|
67 |
+
.#.#.
|
68 |
+
.#...
|
69 |
+
.....
|
70 |
+
"Or, that the first key has heights 5,0,2,1,3:"
|
71 |
+
|
72 |
+
.....
|
73 |
+
#....
|
74 |
+
#....
|
75 |
+
#...#
|
76 |
+
#.#.#
|
77 |
+
#.###
|
78 |
+
#####
|
79 |
+
"These seem like they should fit together; in the first four columns, the pins and key don't overlap. However, this key cannot be for this lock: in the rightmost column, the lock's pin overlaps with the key, which you know because in that column the sum of the lock height and key height is more than the available space."
|
80 |
+
|
81 |
+
"So anyway, you can narrow down the keys you'd need to try by just testing each key with each lock, which means you would have to check... wait, you have how many locks? But the only installation that size is at the North--" You disconnect the call.
|
82 |
+
|
83 |
+
In this example, converting both locks to pin heights produces:
|
84 |
+
|
85 |
+
0,5,3,4,3
|
86 |
+
1,2,0,5,3
|
87 |
+
Converting all three keys to heights produces:
|
88 |
+
|
89 |
+
5,0,2,1,3
|
90 |
+
4,3,4,0,2
|
91 |
+
3,0,2,0,1
|
92 |
+
Then, you can try every key with every lock:
|
93 |
+
|
94 |
+
Lock 0,5,3,4,3 and key 5,0,2,1,3: overlap in the last column.
|
95 |
+
Lock 0,5,3,4,3 and key 4,3,4,0,2: overlap in the second column.
|
96 |
+
Lock 0,5,3,4,3 and key 3,0,2,0,1: all columns fit!
|
97 |
+
Lock 1,2,0,5,3 and key 5,0,2,1,3: overlap in the first column.
|
98 |
+
Lock 1,2,0,5,3 and key 4,3,4,0,2: all columns fit!
|
99 |
+
Lock 1,2,0,5,3 and key 3,0,2,0,1: all columns fit!
|
100 |
+
So, in this example, the number of unique lock/key pairs that fit together without overlapping in any column is 3.
|
101 |
+
|
102 |
+
Analyze your lock and key schematics. How many unique lock/key pairs fit together without overlapping in any column?
|
103 |
+
|
104 |
+
Your puzzle answer was 3690.
|
105 |
+
|
106 |
+
The first half of this puzzle is complete! It provides one gold star: *
|
107 |
+
|
108 |
+
--- Part Two ---
|
109 |
+
You and The Historians crowd into the office, startling the Chief Historian awake! The Historians all take turns looking confused until one asks where he's been for the last few months.
|
110 |
+
|
111 |
+
"I've been right here, working on this high-priority request from Santa! I think the only time I even stepped away was about a month ago when I went to grab a cup of coffee..."
|
112 |
+
|
113 |
+
Just then, the Chief notices the time. "Oh no! I'm going to be late! I must have fallen asleep trying to put the finishing touches on this chronicle Santa requested, but now I don't have enough time to go visit the last 50 places on my list and complete the chronicle before Santa leaves! He said he needed it before tonight's sleigh launch."
|
114 |
+
|
115 |
+
One of The Historians holds up the list they've been using this whole time to keep track of where they've been searching. Next to each place you all visited, they checked off that place with a star. Other Historians hold up their own notes they took on the journey; as The Historians, how could they resist writing everything down while visiting all those historically significant places?
|
116 |
+
|
117 |
+
The Chief's eyes get wide. "With all this, we might just have enough time to finish the chronicle! Santa said he wanted it wrapped up with a bow, so I'll call down to the wrapping department and... hey, could you bring it up to Santa? I'll need to be in my seat to watch the sleigh launch by then."
|
118 |
+
|
119 |
+
You nod, and The Historians quickly work to collect their notes into the final set of pages for the chronicle.
|
120 |
+
|