Cleanup
This commit is contained in:
parent
2091f6c894
commit
130904c604
119
2024/day07/problem
Normal file
119
2024/day07/problem
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
--- Day 7: Bridge Repair ---
|
||||||
|
|
||||||
|
The Historians take you to a familiar [16]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?
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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).
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
190: 10 19
|
||||||
|
3267: 81 40 27
|
||||||
|
83: 17 5
|
||||||
|
156: 15 6
|
||||||
|
7290: 6 8 6 15
|
||||||
|
161011: 16 10 13
|
||||||
|
192: 17 8 14
|
||||||
|
21037: 9 7 18 13
|
||||||
|
292: 11 6 16 20
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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 (*).
|
||||||
|
|
||||||
|
Only three of the above equations can be made true by inserting operators:
|
||||||
|
|
||||||
|
• 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).
|
||||||
|
• 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)!
|
||||||
|
• 292: 11 6 16 20 can be solved in exactly one way: 11 + 6 * 16 + 20.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Determine which equations could possibly be true. What is their total
|
||||||
|
calibration result?
|
||||||
|
|
||||||
|
Your puzzle answer was 5030892084481.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
The [17]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.
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
• 156: 15 6 can be made true through a single concatenation: 15 || 6 =
|
||||||
|
156.
|
||||||
|
• 7290: 6 8 6 15 can be made true using 6 * 8 || 6 * 15.
|
||||||
|
• 192: 17 8 14 can be made true using 17 || 8 + 14.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Using your new knowledge of elephant hiding spots, determine which
|
||||||
|
equations could possibly be true. What is their total calibration result?
|
||||||
|
|
||||||
|
Your puzzle answer was 91377448644679.
|
||||||
|
|
||||||
|
Both parts of this puzzle are complete! They provide two gold stars: **
|
||||||
|
|
||||||
|
At this point, you should [18]return to your Advent calendar and try
|
||||||
|
another puzzle.
|
||||||
|
|
||||||
|
If you still want to see it, you can [19]get your puzzle input.
|
||||||
|
|
||||||
|
You can also [Shareon [20]Bluesky [21]Twitter [22]Mastodon] this puzzle.
|
||||||
|
|
||||||
|
References
|
||||||
|
|
||||||
|
Visible links
|
||||||
|
1. https://adventofcode.com/
|
||||||
|
2. https://adventofcode.com/2024/about
|
||||||
|
3. https://adventofcode.com/2024/events
|
||||||
|
4. https://cottonbureau.com/people/advent-of-code
|
||||||
|
5. https://adventofcode.com/2024/settings
|
||||||
|
6. https://adventofcode.com/2024/auth/logout
|
||||||
|
7. Advent of Code Supporter
|
||||||
|
https://adventofcode.com/2024/support
|
||||||
|
8. https://adventofcode.com/2024
|
||||||
|
9. https://adventofcode.com/2024
|
||||||
|
10. https://adventofcode.com/2024/support
|
||||||
|
12. https://adventofcode.com/2024/leaderboard
|
||||||
|
13. https://adventofcode.com/2024/stats
|
||||||
|
16. https://adventofcode.com/2022/day/9
|
||||||
|
17. https://en.wikipedia.org/wiki/Concatenation
|
||||||
|
18. https://adventofcode.com/2024
|
||||||
|
19. https://adventofcode.com/2024/day/7/input
|
186
2024/day08/problem
Normal file
186
2024/day08/problem
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
--- Day 8: Resonant Collinearity ---
|
||||||
|
|
||||||
|
You find yourselves on the [16]roof of a top-secret Easter Bunny
|
||||||
|
installation.
|
||||||
|
|
||||||
|
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!
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
............
|
||||||
|
........0...
|
||||||
|
.....0......
|
||||||
|
.......0....
|
||||||
|
....0.......
|
||||||
|
......A.....
|
||||||
|
............
|
||||||
|
............
|
||||||
|
........A...
|
||||||
|
.........A..
|
||||||
|
............
|
||||||
|
............
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
So, for these two antennas with frequency a, they create the two antinodes
|
||||||
|
marked with #:
|
||||||
|
|
||||||
|
..........
|
||||||
|
...#......
|
||||||
|
..........
|
||||||
|
....a.....
|
||||||
|
..........
|
||||||
|
.....a....
|
||||||
|
..........
|
||||||
|
......#...
|
||||||
|
..........
|
||||||
|
..........
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
..........
|
||||||
|
...#......
|
||||||
|
#.........
|
||||||
|
....a.....
|
||||||
|
........a.
|
||||||
|
.....a....
|
||||||
|
..#.......
|
||||||
|
......#...
|
||||||
|
..........
|
||||||
|
..........
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
..........
|
||||||
|
...#......
|
||||||
|
#.........
|
||||||
|
....a.....
|
||||||
|
........a.
|
||||||
|
.....a....
|
||||||
|
..#.......
|
||||||
|
......A...
|
||||||
|
..........
|
||||||
|
..........
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
......#....#
|
||||||
|
...#....0...
|
||||||
|
....#0....#.
|
||||||
|
..#....0....
|
||||||
|
....0....#..
|
||||||
|
.#....A.....
|
||||||
|
...#........
|
||||||
|
#......#....
|
||||||
|
........A...
|
||||||
|
.........A..
|
||||||
|
..........#.
|
||||||
|
..........#.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Calculate the impact of the signal. How many unique locations within the
|
||||||
|
bounds of the map contain an antinode?
|
||||||
|
|
||||||
|
Your puzzle answer was 311.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
Watching over your shoulder as you work, one of The Historians asks if you
|
||||||
|
took the effects of resonant harmonics into your calculations.
|
||||||
|
|
||||||
|
Whoops!
|
||||||
|
|
||||||
|
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).
|
||||||
|
|
||||||
|
So, these three T-frequency antennas now create many antinodes:
|
||||||
|
|
||||||
|
T....#....
|
||||||
|
...T......
|
||||||
|
.T....#...
|
||||||
|
.........#
|
||||||
|
..#.......
|
||||||
|
..........
|
||||||
|
...#......
|
||||||
|
..........
|
||||||
|
....#.....
|
||||||
|
..........
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
The original example now has 34 antinodes, including the antinodes that
|
||||||
|
appear on every antenna:
|
||||||
|
|
||||||
|
##....#....#
|
||||||
|
.#.#....0...
|
||||||
|
..#.#0....#.
|
||||||
|
..##...0....
|
||||||
|
....0....#..
|
||||||
|
.#...#A....#
|
||||||
|
...#..#.....
|
||||||
|
#....#.#....
|
||||||
|
..#.....A...
|
||||||
|
....#....A..
|
||||||
|
.#........#.
|
||||||
|
...#......##
|
||||||
|
|
||||||
|
Calculate the impact of the signal using this updated model. How many
|
||||||
|
unique locations within the bounds of the map contain an antinode?
|
||||||
|
|
||||||
|
Your puzzle answer was 1115.
|
||||||
|
|
||||||
|
Both parts of this puzzle are complete! They provide two gold stars: **
|
||||||
|
|
||||||
|
At this point, you should [17]return to your Advent calendar and try
|
||||||
|
another puzzle.
|
||||||
|
|
||||||
|
If you still want to see it, you can [18]get your puzzle input.
|
||||||
|
|
||||||
|
References
|
||||||
|
|
||||||
|
Visible links
|
||||||
|
1. https://adventofcode.com/
|
||||||
|
2. https://adventofcode.com/2024/about
|
||||||
|
3. https://adventofcode.com/2024/events
|
||||||
|
4. https://cottonbureau.com/people/advent-of-code
|
||||||
|
5. https://adventofcode.com/2024/settings
|
||||||
|
6. https://adventofcode.com/2024/auth/logout
|
||||||
|
7. Advent of Code Supporter
|
||||||
|
https://adventofcode.com/2024/support
|
||||||
|
8. https://adventofcode.com/2024
|
||||||
|
9. https://adventofcode.com/2024
|
||||||
|
10. https://adventofcode.com/2024/support
|
||||||
|
12. https://adventofcode.com/2024/leaderboard
|
||||||
|
13. https://adventofcode.com/2024/stats
|
||||||
|
16. https://adventofcode.com/2016/day/25
|
||||||
|
17. https://adventofcode.com/2024
|
||||||
|
18. https://adventofcode.com/2024/day/8/input
|
146
2024/day09/problem
Normal file
146
2024/day09/problem
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
--- Day 9: Disk Fragmenter ---
|
||||||
|
|
||||||
|
Another push of the button leaves you in the familiar hallways of some
|
||||||
|
friendly [16]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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
He shows you the disk map (your puzzle input) he's already generated. For
|
||||||
|
example:
|
||||||
|
|
||||||
|
2333133121414131402
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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).
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
0..111....22222
|
||||||
|
|
||||||
|
The first example above, 2333133121414131402, represents these individual
|
||||||
|
blocks:
|
||||||
|
|
||||||
|
00...111...2...333.44.5555.6666.777.888899
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
0..111....22222
|
||||||
|
02.111....2222.
|
||||||
|
022111....222..
|
||||||
|
0221112...22...
|
||||||
|
02211122..2....
|
||||||
|
022111222......
|
||||||
|
|
||||||
|
The first example requires a few more steps:
|
||||||
|
|
||||||
|
00...111...2...333.44.5555.6666.777.888899
|
||||||
|
009..111...2...333.44.5555.6666.777.88889.
|
||||||
|
0099.111...2...333.44.5555.6666.777.8888..
|
||||||
|
00998111...2...333.44.5555.6666.777.888...
|
||||||
|
009981118..2...333.44.5555.6666.777.88....
|
||||||
|
0099811188.2...333.44.5555.6666.777.8.....
|
||||||
|
009981118882...333.44.5555.6666.777.......
|
||||||
|
0099811188827..333.44.5555.6666.77........
|
||||||
|
00998111888277.333.44.5555.6666.7.........
|
||||||
|
009981118882777333.44.5555.6666...........
|
||||||
|
009981118882777333644.5555.666............
|
||||||
|
00998111888277733364465555.66.............
|
||||||
|
0099811188827773336446555566..............
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.)
|
||||||
|
|
||||||
|
Your puzzle answer was 6211348208140.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
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 [17]file system fragmentation was a bad idea?
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
The first example from above now proceeds differently:
|
||||||
|
|
||||||
|
00...111...2...333.44.5555.6666.777.888899
|
||||||
|
0099.111...2...333.44.5555.6666.777.8888..
|
||||||
|
0099.1117772...333.44.5555.6666.....8888..
|
||||||
|
0099.111777244.333....5555.6666.....8888..
|
||||||
|
00992111777.44.333....5555.6666.....8888..
|
||||||
|
|
||||||
|
The process of updating the filesystem checksum is the same; now, this
|
||||||
|
example's checksum would be 2858.
|
||||||
|
|
||||||
|
Start over, now compacting the amphipod's hard drive using this new method
|
||||||
|
instead. What is the resulting filesystem checksum?
|
||||||
|
|
||||||
|
Your puzzle answer was 6239783302560.
|
||||||
|
|
||||||
|
Both parts of this puzzle are complete! They provide two gold stars: **
|
||||||
|
|
||||||
|
At this point, you should [18]return to your Advent calendar and try
|
||||||
|
another puzzle.
|
||||||
|
|
||||||
|
If you still want to see it, you can [19]get your puzzle input.
|
||||||
|
|
||||||
|
References
|
||||||
|
|
||||||
|
Visible links
|
||||||
|
1. https://adventofcode.com/
|
||||||
|
2. https://adventofcode.com/2024/about
|
||||||
|
3. https://adventofcode.com/2024/events
|
||||||
|
4. https://cottonbureau.com/people/advent-of-code
|
||||||
|
5. https://adventofcode.com/2024/settings
|
||||||
|
6. https://adventofcode.com/2024/auth/logout
|
||||||
|
7. Advent of Code Supporter
|
||||||
|
https://adventofcode.com/2024/support
|
||||||
|
8. https://adventofcode.com/2024
|
||||||
|
9. https://adventofcode.com/2024
|
||||||
|
10. https://adventofcode.com/2024/support
|
||||||
|
12. https://adventofcode.com/2024/leaderboard
|
||||||
|
13. https://adventofcode.com/2024/stats
|
||||||
|
16. https://adventofcode.com/2021/day/23
|
||||||
|
17. https://en.wikipedia.org/wiki/File_system_fragmentation
|
||||||
|
18. https://adventofcode.com/2024
|
||||||
|
19. https://adventofcode.com/2024/day/9/input
|
198
2024/day10/problem
Normal file
198
2024/day10/problem
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
--- Day 10: Hoof It ---
|
||||||
|
|
||||||
|
You all arrive at a [16]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.
|
||||||
|
|
||||||
|
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 [17]topographic map of the surrounding area (your
|
||||||
|
puzzle input) and looks up at you excitedly.
|
||||||
|
|
||||||
|
Perhaps you can help fill in the missing hiking trails?
|
||||||
|
|
||||||
|
The topographic map indicates the height at each position using a scale
|
||||||
|
from 0 (lowest) to 9 (highest). For example:
|
||||||
|
|
||||||
|
0123
|
||||||
|
1234
|
||||||
|
8765
|
||||||
|
9876
|
||||||
|
|
||||||
|
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).
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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).
|
||||||
|
|
||||||
|
This trailhead has a score of 2:
|
||||||
|
|
||||||
|
...0...
|
||||||
|
...1...
|
||||||
|
...2...
|
||||||
|
6543456
|
||||||
|
7.....7
|
||||||
|
8.....8
|
||||||
|
9.....9
|
||||||
|
|
||||||
|
(The positions marked . are impassable tiles to simplify these examples;
|
||||||
|
they do not appear on your actual topographic map.)
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
..90..9
|
||||||
|
...1.98
|
||||||
|
...2..7
|
||||||
|
6543456
|
||||||
|
765.987
|
||||||
|
876....
|
||||||
|
987....
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
10..9..
|
||||||
|
2...8..
|
||||||
|
3...7..
|
||||||
|
4567654
|
||||||
|
...8..3
|
||||||
|
...9..2
|
||||||
|
.....01
|
||||||
|
|
||||||
|
Here's a larger example:
|
||||||
|
|
||||||
|
89010123
|
||||||
|
78121874
|
||||||
|
87430965
|
||||||
|
96549874
|
||||||
|
45678903
|
||||||
|
32019012
|
||||||
|
01329801
|
||||||
|
10456732
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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?
|
||||||
|
|
||||||
|
Your puzzle answer was 744.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
.....0.
|
||||||
|
..4321.
|
||||||
|
..5..2.
|
||||||
|
..6543.
|
||||||
|
..7..4.
|
||||||
|
..8765.
|
||||||
|
..9....
|
||||||
|
|
||||||
|
The above map has a single trailhead; its rating is 3 because there are
|
||||||
|
exactly three distinct hiking trails which begin at that position:
|
||||||
|
|
||||||
|
.....0. .....0. .....0.
|
||||||
|
..4321. .....1. .....1.
|
||||||
|
..5.... .....2. .....2.
|
||||||
|
..6.... ..6543. .....3.
|
||||||
|
..7.... ..7.... .....4.
|
||||||
|
..8.... ..8.... ..8765.
|
||||||
|
..9.... ..9.... ..9....
|
||||||
|
|
||||||
|
Here is a map containing a single trailhead with rating 13:
|
||||||
|
|
||||||
|
..90..9
|
||||||
|
...1.98
|
||||||
|
...2..7
|
||||||
|
6543456
|
||||||
|
765.987
|
||||||
|
876....
|
||||||
|
987....
|
||||||
|
|
||||||
|
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):
|
||||||
|
|
||||||
|
012345
|
||||||
|
123456
|
||||||
|
234567
|
||||||
|
345678
|
||||||
|
4.6789
|
||||||
|
56789.
|
||||||
|
|
||||||
|
Here's the larger example from before:
|
||||||
|
|
||||||
|
89010123
|
||||||
|
78121874
|
||||||
|
87430965
|
||||||
|
96549874
|
||||||
|
45678903
|
||||||
|
32019012
|
||||||
|
01329801
|
||||||
|
10456732
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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?
|
||||||
|
|
||||||
|
Your puzzle answer was 1651.
|
||||||
|
|
||||||
|
Both parts of this puzzle are complete! They provide two gold stars: **
|
||||||
|
|
||||||
|
At this point, you should [18]return to your Advent calendar and try
|
||||||
|
another puzzle.
|
||||||
|
|
||||||
|
If you still want to see it, you can [19]get your puzzle input.
|
||||||
|
|
||||||
|
References
|
||||||
|
|
||||||
|
Visible links
|
||||||
|
1. https://adventofcode.com/
|
||||||
|
2. https://adventofcode.com/2024/about
|
||||||
|
3. https://adventofcode.com/2024/events
|
||||||
|
4. https://cottonbureau.com/people/advent-of-code
|
||||||
|
5. https://adventofcode.com/2024/settings
|
||||||
|
6. https://adventofcode.com/2024/auth/logout
|
||||||
|
7. Advent of Code Supporter
|
||||||
|
https://adventofcode.com/2024/support
|
||||||
|
8. https://adventofcode.com/2024
|
||||||
|
9. https://adventofcode.com/2024
|
||||||
|
10. https://adventofcode.com/2024/support
|
||||||
|
12. https://adventofcode.com/2024/leaderboard
|
||||||
|
13. https://adventofcode.com/2024/stats
|
||||||
|
16. https://adventofcode.com/2023/day/15
|
||||||
|
17. https://en.wikipedia.org/wiki/Topographic_map
|
||||||
|
18. https://adventofcode.com/2024
|
||||||
|
19. https://adventofcode.com/2024/day/10/input
|
117
2024/day11/problem
Normal file
117
2024/day11/problem
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
--- Day 11: Plutonian Pebbles ---
|
||||||
|
|
||||||
|
The ancient civilization on [16]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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
The strange part is that every time you blink, the stones change.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
• If the stone is engraved with the number 0, it is replaced by a stone
|
||||||
|
engraved with the number 1.
|
||||||
|
• 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.)
|
||||||
|
• 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.
|
||||||
|
|
||||||
|
No matter how the stones change, their order is preserved, and they stay
|
||||||
|
on their perfectly straight line.
|
||||||
|
|
||||||
|
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).
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
• The first stone, 0, becomes a stone marked 1.
|
||||||
|
• The second stone, 1, is multiplied by 2024 to become 2024.
|
||||||
|
• The third stone, 10, is split into a stone marked 1 followed by a
|
||||||
|
stone marked 0.
|
||||||
|
• The fourth stone, 99, is split into two stones marked 9.
|
||||||
|
• The fifth stone, 999, is replaced by a stone marked 2021976.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Here is a longer example:
|
||||||
|
|
||||||
|
Initial arrangement:
|
||||||
|
125 17
|
||||||
|
|
||||||
|
After 1 blink:
|
||||||
|
253000 1 7
|
||||||
|
|
||||||
|
After 2 blinks:
|
||||||
|
253 0 2024 14168
|
||||||
|
|
||||||
|
After 3 blinks:
|
||||||
|
512072 1 20 24 28676032
|
||||||
|
|
||||||
|
After 4 blinks:
|
||||||
|
512 72 2024 2 0 2 4 2867 6032
|
||||||
|
|
||||||
|
After 5 blinks:
|
||||||
|
1036288 7 2 20 24 4048 1 4048 8096 28 67 60 32
|
||||||
|
|
||||||
|
After 6 blinks:
|
||||||
|
2097446912 14168 4048 2 0 2 4 40 48 2024 40 48 80 96 2 8 6 7 6 0 3 2
|
||||||
|
|
||||||
|
In this example, after blinking six times, you would have 22 stones. After
|
||||||
|
blinking 25 times, you would have 55312 stones!
|
||||||
|
|
||||||
|
Consider the arrangement of stones in front of you. How many stones will
|
||||||
|
you have after blinking 25 times?
|
||||||
|
|
||||||
|
Your puzzle answer was 231278.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
The Historians sure are taking a long time. To be fair, the infinite
|
||||||
|
corridors are very large.
|
||||||
|
|
||||||
|
How many stones would you have after blinking a total of 75 times?
|
||||||
|
|
||||||
|
Your puzzle answer was 274229228071551.
|
||||||
|
|
||||||
|
Both parts of this puzzle are complete! They provide two gold stars: **
|
||||||
|
|
||||||
|
At this point, you should [17]return to your Advent calendar and try
|
||||||
|
another puzzle.
|
||||||
|
|
||||||
|
If you still want to see it, you can [18]get your puzzle input.
|
||||||
|
|
||||||
|
References
|
||||||
|
|
||||||
|
Visible links
|
||||||
|
1. https://adventofcode.com/
|
||||||
|
2. https://adventofcode.com/2024/about
|
||||||
|
3. https://adventofcode.com/2024/events
|
||||||
|
4. https://cottonbureau.com/people/advent-of-code
|
||||||
|
5. https://adventofcode.com/2024/settings
|
||||||
|
6. https://adventofcode.com/2024/auth/logout
|
||||||
|
7. Advent of Code Supporter
|
||||||
|
https://adventofcode.com/2024/support
|
||||||
|
8. https://adventofcode.com/2024
|
||||||
|
9. https://adventofcode.com/2024
|
||||||
|
10. https://adventofcode.com/2024/support
|
||||||
|
12. https://adventofcode.com/2024/leaderboard
|
||||||
|
13. https://adventofcode.com/2024/stats
|
||||||
|
16. https://adventofcode.com/2019/day/20
|
||||||
|
17. https://adventofcode.com/2024
|
||||||
|
18. https://adventofcode.com/2024/day/11/input
|
228
2024/day12/problem
Normal file
228
2024/day12/problem
Normal file
@ -0,0 +1,228 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
--- Day 12: Garden Groups ---
|
||||||
|
|
||||||
|
Why not search for the Chief Historian near the [16]gardener and his
|
||||||
|
[17]massive farm? There's plenty of food, so The Historians grab something
|
||||||
|
to eat while they search.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
AAAA
|
||||||
|
BBCD
|
||||||
|
BBCC
|
||||||
|
EEEC
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
In order to accurately calculate the cost of the fence around a single
|
||||||
|
region, you need to know that region's area and perimeter.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
+-+-+-+-+
|
||||||
|
|A A A A|
|
||||||
|
+-+-+-+-+ +-+
|
||||||
|
|D|
|
||||||
|
+-+-+ +-+ +-+
|
||||||
|
|B B| |C|
|
||||||
|
+ + + +-+
|
||||||
|
|B B| |C C|
|
||||||
|
+-+-+ +-+ +
|
||||||
|
|C|
|
||||||
|
+-+-+-+ +-+
|
||||||
|
|E E E|
|
||||||
|
+-+-+-+
|
||||||
|
|
||||||
|
Plants of the same type can appear in multiple separate regions, and
|
||||||
|
regions can even appear within other regions. For example:
|
||||||
|
|
||||||
|
OOOOO
|
||||||
|
OXOXO
|
||||||
|
OOOOO
|
||||||
|
OXOXO
|
||||||
|
OOOOO
|
||||||
|
|
||||||
|
The above map contains five regions, one containing all of the O garden
|
||||||
|
plots, and the other four each containing a single X plot.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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).
|
||||||
|
|
||||||
|
Here's a larger example:
|
||||||
|
|
||||||
|
RRRRIICCFF
|
||||||
|
RRRRIICCCF
|
||||||
|
VVRRRCCFFF
|
||||||
|
VVRCCCJFFF
|
||||||
|
VVVVCJJCFE
|
||||||
|
VVIVCCJJEE
|
||||||
|
VVIIICJJEE
|
||||||
|
MIIIIIJJEE
|
||||||
|
MIIISIJEEE
|
||||||
|
MMMISSJEEE
|
||||||
|
|
||||||
|
It contains:
|
||||||
|
|
||||||
|
• A region of R plants with price 12 * 18 = 216.
|
||||||
|
• A region of I plants with price 4 * 8 = 32.
|
||||||
|
• A region of C plants with price 14 * 28 = 392.
|
||||||
|
• A region of F plants with price 10 * 18 = 180.
|
||||||
|
• A region of V plants with price 13 * 20 = 260.
|
||||||
|
• A region of J plants with price 11 * 20 = 220.
|
||||||
|
• A region of C plants with price 1 * 4 = 4.
|
||||||
|
• A region of E plants with price 13 * 18 = 234.
|
||||||
|
• A region of I plants with price 14 * 22 = 308.
|
||||||
|
• A region of M plants with price 5 * 12 = 60.
|
||||||
|
• A region of S plants with price 3 * 8 = 24.
|
||||||
|
|
||||||
|
So, it has a total price of 1930.
|
||||||
|
|
||||||
|
What is the total price of fencing all regions on your map?
|
||||||
|
|
||||||
|
Your puzzle answer was 1522850.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
Fortunately, the Elves are trying to order so much fence that they qualify
|
||||||
|
for a bulk discount!
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Consider this example again:
|
||||||
|
|
||||||
|
AAAA
|
||||||
|
BBCD
|
||||||
|
BBCC
|
||||||
|
EEEC
|
||||||
|
|
||||||
|
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!
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
The second example above (full of type X and O plants) would have a total
|
||||||
|
price of 436.
|
||||||
|
|
||||||
|
Here's a map that includes an E-shaped region full of type E plants:
|
||||||
|
|
||||||
|
EEEEE
|
||||||
|
EXXXX
|
||||||
|
EEEEE
|
||||||
|
EXXXX
|
||||||
|
EEEEE
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
This map has a total price of 368:
|
||||||
|
|
||||||
|
AAAAAA
|
||||||
|
AAABBA
|
||||||
|
AAABBA
|
||||||
|
ABBAAA
|
||||||
|
ABBAAA
|
||||||
|
AAAAAA
|
||||||
|
|
||||||
|
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.)
|
||||||
|
|
||||||
|
The larger example from before now has the following updated prices:
|
||||||
|
|
||||||
|
• A region of R plants with price 12 * 10 = 120.
|
||||||
|
• A region of I plants with price 4 * 4 = 16.
|
||||||
|
• A region of C plants with price 14 * 22 = 308.
|
||||||
|
• A region of F plants with price 10 * 12 = 120.
|
||||||
|
• A region of V plants with price 13 * 10 = 130.
|
||||||
|
• A region of J plants with price 11 * 12 = 132.
|
||||||
|
• A region of C plants with price 1 * 4 = 4.
|
||||||
|
• A region of E plants with price 13 * 8 = 104.
|
||||||
|
• A region of I plants with price 14 * 16 = 224.
|
||||||
|
• A region of M plants with price 5 * 6 = 30.
|
||||||
|
• A region of S plants with price 3 * 6 = 18.
|
||||||
|
|
||||||
|
Adding these together produces its new total price of 1206.
|
||||||
|
|
||||||
|
What is the new total price of fencing all regions on your map?
|
||||||
|
|
||||||
|
Your puzzle answer was 953738.
|
||||||
|
|
||||||
|
Both parts of this puzzle are complete! They provide two gold stars: **
|
||||||
|
|
||||||
|
At this point, you should [18]return to your Advent calendar and try
|
||||||
|
another puzzle.
|
||||||
|
|
||||||
|
If you still want to see it, you can [19]get your puzzle input.
|
||||||
|
|
||||||
|
References
|
||||||
|
|
||||||
|
Visible links
|
||||||
|
1. https://adventofcode.com/
|
||||||
|
2. https://adventofcode.com/2024/about
|
||||||
|
3. https://adventofcode.com/2024/events
|
||||||
|
4. https://cottonbureau.com/people/advent-of-code
|
||||||
|
5. https://adventofcode.com/2024/settings
|
||||||
|
6. https://adventofcode.com/2024/auth/logout
|
||||||
|
7. Advent of Code Supporter
|
||||||
|
https://adventofcode.com/2024/support
|
||||||
|
8. https://adventofcode.com/2024
|
||||||
|
9. https://adventofcode.com/2024
|
||||||
|
10. https://adventofcode.com/2024/support
|
||||||
|
12. https://adventofcode.com/2024/leaderboard
|
||||||
|
13. https://adventofcode.com/2024/stats
|
||||||
|
16. https://adventofcode.com/2023/day/5
|
||||||
|
17. https://adventofcode.com/2023/day/21
|
||||||
|
18. https://adventofcode.com/2024
|
||||||
|
19. https://adventofcode.com/2024/day/12/input
|
145
2024/day13/problem
Normal file
145
2024/day13/problem
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
--- Day 13: Claw Contraption ---
|
||||||
|
|
||||||
|
Next up: the [16]lobby of a resort on a tropical island. The Historians
|
||||||
|
take a moment to admire the hexagonal floor tiles before spreading out.
|
||||||
|
|
||||||
|
Fortunately, it looks like the resort has a new [17]arcade! Maybe you can
|
||||||
|
win some prizes from the [18]claw machines?
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
Button A: X+94, Y+34
|
||||||
|
Button B: X+22, Y+67
|
||||||
|
Prize: X=8400, Y=5400
|
||||||
|
|
||||||
|
Button A: X+26, Y+66
|
||||||
|
Button B: X+67, Y+21
|
||||||
|
Prize: X=12748, Y=12176
|
||||||
|
|
||||||
|
Button A: X+17, Y+86
|
||||||
|
Button B: X+84, Y+37
|
||||||
|
Prize: X=7870, Y=6450
|
||||||
|
|
||||||
|
Button A: X+69, Y+23
|
||||||
|
Button B: X+27, Y+71
|
||||||
|
Prize: X=18641, Y=10279
|
||||||
|
|
||||||
|
This list describes the button configuration and prize location of four
|
||||||
|
different claw machines.
|
||||||
|
|
||||||
|
For now, consider just the first claw machine in the list:
|
||||||
|
|
||||||
|
• Pushing the machine's A button would move the claw 94 units along the
|
||||||
|
X axis and 34 units along the Y axis.
|
||||||
|
• Pushing the B button would move the claw 22 units along the X axis and
|
||||||
|
67 units along the Y axis.
|
||||||
|
• 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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
For the second and fourth claw machines, there is no combination of A and
|
||||||
|
B presses that will ever win a prize.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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?
|
||||||
|
|
||||||
|
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?
|
||||||
|
|
||||||
|
Your puzzle answer was 30973.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
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!
|
||||||
|
|
||||||
|
Add 10000000000000 to the X and Y position of every prize. After making
|
||||||
|
this change, the example above would now look like this:
|
||||||
|
|
||||||
|
Button A: X+94, Y+34
|
||||||
|
Button B: X+22, Y+67
|
||||||
|
Prize: X=10000000008400, Y=10000000005400
|
||||||
|
|
||||||
|
Button A: X+26, Y+66
|
||||||
|
Button B: X+67, Y+21
|
||||||
|
Prize: X=10000000012748, Y=10000000012176
|
||||||
|
|
||||||
|
Button A: X+17, Y+86
|
||||||
|
Button B: X+84, Y+37
|
||||||
|
Prize: X=10000000007870, Y=10000000006450
|
||||||
|
|
||||||
|
Button A: X+69, Y+23
|
||||||
|
Button B: X+27, Y+71
|
||||||
|
Prize: X=10000000018641, Y=10000000010279
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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?
|
||||||
|
|
||||||
|
Your puzzle answer was 95688837203288.
|
||||||
|
|
||||||
|
Both parts of this puzzle are complete! They provide two gold stars: **
|
||||||
|
|
||||||
|
At this point, you should [19]return to your Advent calendar and try
|
||||||
|
another puzzle.
|
||||||
|
|
||||||
|
If you still want to see it, you can [20]get your puzzle input.
|
||||||
|
|
||||||
|
References
|
||||||
|
|
||||||
|
Visible links
|
||||||
|
1. https://adventofcode.com/
|
||||||
|
2. https://adventofcode.com/2024/about
|
||||||
|
3. https://adventofcode.com/2024/events
|
||||||
|
4. https://cottonbureau.com/people/advent-of-code
|
||||||
|
5. https://adventofcode.com/2024/settings
|
||||||
|
6. https://adventofcode.com/2024/auth/logout
|
||||||
|
7. Advent of Code Supporter
|
||||||
|
https://adventofcode.com/2024/support
|
||||||
|
8. https://adventofcode.com/2024
|
||||||
|
9. https://adventofcode.com/2024
|
||||||
|
10. https://adventofcode.com/2024/support
|
||||||
|
11. https://adventofcode.com/2024/sponsors
|
||||||
|
12. https://adventofcode.com/2024/leaderboard
|
||||||
|
13. https://adventofcode.com/2024/stats
|
||||||
|
16. https://adventofcode.com/2020/day/24
|
||||||
|
17. https://en.wikipedia.org/wiki/Amusement_arcade
|
||||||
|
18. https://en.wikipedia.org/wiki/Claw_machine
|
||||||
|
19. https://adventofcode.com/2024
|
||||||
|
20. https://adventofcode.com/2024/day/13/input
|
193
2024/day14/problem
Normal file
193
2024/day14/problem
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
--- Day 14: Restroom Redoubt ---
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Unfortunately, EBHQ seems to have "improved" bathroom security again after
|
||||||
|
your last [16]visit. The area outside the bathroom is swarming with
|
||||||
|
robots!
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
You make a list (your puzzle input) of all of the robots' current
|
||||||
|
positions (p) and velocities (v), one robot per line. For example:
|
||||||
|
|
||||||
|
p=0,4 v=3,-3
|
||||||
|
p=6,3 v=-1,-3
|
||||||
|
p=10,3 v=-1,2
|
||||||
|
p=2,0 v=2,-1
|
||||||
|
p=0,0 v=1,3
|
||||||
|
p=3,0 v=-2,-2
|
||||||
|
p=7,6 v=-1,-3
|
||||||
|
p=3,0 v=-1,-2
|
||||||
|
p=9,3 v=2,3
|
||||||
|
p=7,3 v=-1,2
|
||||||
|
p=2,4 v=2,-3
|
||||||
|
p=9,5 v=-3,-3
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
1.12.......
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
......11.11
|
||||||
|
1.1........
|
||||||
|
.........1.
|
||||||
|
.......1...
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
Initial state:
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
..1........
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
|
||||||
|
After 1 second:
|
||||||
|
...........
|
||||||
|
....1......
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
|
||||||
|
After 2 seconds:
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
......1....
|
||||||
|
...........
|
||||||
|
|
||||||
|
After 3 seconds:
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
........1..
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
|
||||||
|
After 4 seconds:
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
..........1
|
||||||
|
|
||||||
|
After 5 seconds:
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
.1.........
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
...........
|
||||||
|
|
||||||
|
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?
|
||||||
|
|
||||||
|
In the above example, the number of robots on each tile after 100 seconds
|
||||||
|
has elapsed looks like this:
|
||||||
|
|
||||||
|
......2..1.
|
||||||
|
...........
|
||||||
|
1..........
|
||||||
|
.11........
|
||||||
|
.....1.....
|
||||||
|
...12......
|
||||||
|
.1....1....
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
..... 2..1.
|
||||||
|
..... .....
|
||||||
|
1.... .....
|
||||||
|
|
||||||
|
..... .....
|
||||||
|
...12 .....
|
||||||
|
.1... 1....
|
||||||
|
|
||||||
|
In this example, the quadrants contain 1, 3, 4, and 1 robot. Multiplying
|
||||||
|
these together gives a total safety factor of 12.
|
||||||
|
|
||||||
|
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?
|
||||||
|
|
||||||
|
Your puzzle answer was 218965032.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
What is the fewest number of seconds that must elapse for the robots to
|
||||||
|
display the Easter egg?
|
||||||
|
|
||||||
|
Your puzzle answer was 7037.
|
||||||
|
|
||||||
|
Both parts of this puzzle are complete! They provide two gold stars: **
|
||||||
|
|
||||||
|
At this point, you should [17]return to your Advent calendar and try
|
||||||
|
another puzzle.
|
||||||
|
|
||||||
|
If you still want to see it, you can [18]get your puzzle input.
|
||||||
|
|
||||||
|
References
|
||||||
|
|
||||||
|
Visible links
|
||||||
|
1. https://adventofcode.com/
|
||||||
|
2. https://adventofcode.com/2024/about
|
||||||
|
3. https://adventofcode.com/2024/events
|
||||||
|
4. https://cottonbureau.com/people/advent-of-code
|
||||||
|
5. https://adventofcode.com/2024/settings
|
||||||
|
6. https://adventofcode.com/2024/auth/logout
|
||||||
|
7. Advent of Code Supporter
|
||||||
|
https://adventofcode.com/2024/support
|
||||||
|
8. https://adventofcode.com/2024
|
||||||
|
9. https://adventofcode.com/2024
|
||||||
|
10. https://adventofcode.com/2024/support
|
||||||
|
12. https://adventofcode.com/2024/leaderboard
|
||||||
|
13. https://adventofcode.com/2024/stats
|
||||||
|
16. https://adventofcode.com/2016/day/2
|
||||||
|
17. https://adventofcode.com/2024
|
||||||
|
18. https://adventofcode.com/2024/day/14/input
|
498
2024/day15/problem
Normal file
498
2024/day15/problem
Normal file
@ -0,0 +1,498 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
--- Day 15: Warehouse Woes ---
|
||||||
|
|
||||||
|
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?
|
||||||
|
|
||||||
|
You look up to see a vast school of [16]lanternfish swimming past you. On
|
||||||
|
closer inspection, they seem quite anxious, so you drive your mini
|
||||||
|
submarine over to see if you can help.
|
||||||
|
|
||||||
|
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!
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
##########
|
||||||
|
#..O..O.O#
|
||||||
|
#......O.#
|
||||||
|
#.OO..O.O#
|
||||||
|
#..O@..O.#
|
||||||
|
#O#..O...#
|
||||||
|
#O..O..O.#
|
||||||
|
#.OO.O.OO#
|
||||||
|
#....O...#
|
||||||
|
##########
|
||||||
|
|
||||||
|
<vv>^<v^>v>^vv^v>v<>v^v<v<^vv<<<^><<><>>v<vvv<>^v^>^<<<><<v<<<v^vv^v>^
|
||||||
|
vvv<<^>^v^^><<>>><>^<<><^vv^^<>vvv<>><^^v>^>vv<>v<<<<v<^v>^<^^>>>^<v<v
|
||||||
|
><>vv>v^v^<>><>>>><^^>vv>v<^^^>>v^v^<^^>v^^>v^<^v>v<>>v^v^<v>v^^<^^vv<
|
||||||
|
<<v<^>>^^^^>>>v^<>vvv^><v<<<>^^^vv^<vvv>^>v<^^^^v<>^>vvvv><>>v^<<^^^^^
|
||||||
|
^><^><>>><>^^<<^^v>>><^<v>^<vv>>v>>>^v><>^v><<<<v>>v<v<v>vvv>^<><<>^><
|
||||||
|
^>><>^v<><^vvv<^^<><v<<<<<><^v<<<><<<^^<v<^^^><^>>^<v^><<<^>>^v<v^v<v^
|
||||||
|
>^>>^v>vv>^<<^v<>><<><<v<<v><>v<^vv<<<>^^v^>^^>>><<^v>>v^v><^^>>^<>vv^
|
||||||
|
<><^^>^^^<><vvvvv^v<v<<>^v<v>v<<^><<><<><<<^^<<<^<<>><<><^^^>^^<>^>v<>
|
||||||
|
^^>vv<^v^v<vv>^<><v<^v>^^^>>>^^vvv^>vvv<>>>^<^>>>>>^<<^v>^vvv<>^<><<v>
|
||||||
|
v^^>>><<^^<>>^v^<v^vv<>v^<<>^<^v^v><^<<<><<^<v><v<>vv>>v><v^<vv<>v^<<^
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.)
|
||||||
|
|
||||||
|
Here is a smaller example to get started:
|
||||||
|
|
||||||
|
########
|
||||||
|
#..O.O.#
|
||||||
|
##@.O..#
|
||||||
|
#...O..#
|
||||||
|
#.#.O..#
|
||||||
|
#...O..#
|
||||||
|
#......#
|
||||||
|
########
|
||||||
|
|
||||||
|
<^^>>>vv<v>>v<<
|
||||||
|
|
||||||
|
Were the robot to attempt the given sequence of moves, it would push
|
||||||
|
around the boxes as follows:
|
||||||
|
|
||||||
|
Initial state:
|
||||||
|
########
|
||||||
|
#..O.O.#
|
||||||
|
##@.O..#
|
||||||
|
#...O..#
|
||||||
|
#.#.O..#
|
||||||
|
#...O..#
|
||||||
|
#......#
|
||||||
|
########
|
||||||
|
|
||||||
|
Move <:
|
||||||
|
########
|
||||||
|
#..O.O.#
|
||||||
|
##@.O..#
|
||||||
|
#...O..#
|
||||||
|
#.#.O..#
|
||||||
|
#...O..#
|
||||||
|
#......#
|
||||||
|
########
|
||||||
|
|
||||||
|
Move ^:
|
||||||
|
########
|
||||||
|
#.@O.O.#
|
||||||
|
##..O..#
|
||||||
|
#...O..#
|
||||||
|
#.#.O..#
|
||||||
|
#...O..#
|
||||||
|
#......#
|
||||||
|
########
|
||||||
|
|
||||||
|
Move ^:
|
||||||
|
########
|
||||||
|
#.@O.O.#
|
||||||
|
##..O..#
|
||||||
|
#...O..#
|
||||||
|
#.#.O..#
|
||||||
|
#...O..#
|
||||||
|
#......#
|
||||||
|
########
|
||||||
|
|
||||||
|
Move >:
|
||||||
|
########
|
||||||
|
#..@OO.#
|
||||||
|
##..O..#
|
||||||
|
#...O..#
|
||||||
|
#.#.O..#
|
||||||
|
#...O..#
|
||||||
|
#......#
|
||||||
|
########
|
||||||
|
|
||||||
|
Move >:
|
||||||
|
########
|
||||||
|
#...@OO#
|
||||||
|
##..O..#
|
||||||
|
#...O..#
|
||||||
|
#.#.O..#
|
||||||
|
#...O..#
|
||||||
|
#......#
|
||||||
|
########
|
||||||
|
|
||||||
|
Move >:
|
||||||
|
########
|
||||||
|
#...@OO#
|
||||||
|
##..O..#
|
||||||
|
#...O..#
|
||||||
|
#.#.O..#
|
||||||
|
#...O..#
|
||||||
|
#......#
|
||||||
|
########
|
||||||
|
|
||||||
|
Move v:
|
||||||
|
########
|
||||||
|
#....OO#
|
||||||
|
##..@..#
|
||||||
|
#...O..#
|
||||||
|
#.#.O..#
|
||||||
|
#...O..#
|
||||||
|
#...O..#
|
||||||
|
########
|
||||||
|
|
||||||
|
Move v:
|
||||||
|
########
|
||||||
|
#....OO#
|
||||||
|
##..@..#
|
||||||
|
#...O..#
|
||||||
|
#.#.O..#
|
||||||
|
#...O..#
|
||||||
|
#...O..#
|
||||||
|
########
|
||||||
|
|
||||||
|
Move <:
|
||||||
|
########
|
||||||
|
#....OO#
|
||||||
|
##.@...#
|
||||||
|
#...O..#
|
||||||
|
#.#.O..#
|
||||||
|
#...O..#
|
||||||
|
#...O..#
|
||||||
|
########
|
||||||
|
|
||||||
|
Move v:
|
||||||
|
########
|
||||||
|
#....OO#
|
||||||
|
##.....#
|
||||||
|
#..@O..#
|
||||||
|
#.#.O..#
|
||||||
|
#...O..#
|
||||||
|
#...O..#
|
||||||
|
########
|
||||||
|
|
||||||
|
Move >:
|
||||||
|
########
|
||||||
|
#....OO#
|
||||||
|
##.....#
|
||||||
|
#...@O.#
|
||||||
|
#.#.O..#
|
||||||
|
#...O..#
|
||||||
|
#...O..#
|
||||||
|
########
|
||||||
|
|
||||||
|
Move >:
|
||||||
|
########
|
||||||
|
#....OO#
|
||||||
|
##.....#
|
||||||
|
#....@O#
|
||||||
|
#.#.O..#
|
||||||
|
#...O..#
|
||||||
|
#...O..#
|
||||||
|
########
|
||||||
|
|
||||||
|
Move v:
|
||||||
|
########
|
||||||
|
#....OO#
|
||||||
|
##.....#
|
||||||
|
#.....O#
|
||||||
|
#.#.O@.#
|
||||||
|
#...O..#
|
||||||
|
#...O..#
|
||||||
|
########
|
||||||
|
|
||||||
|
Move <:
|
||||||
|
########
|
||||||
|
#....OO#
|
||||||
|
##.....#
|
||||||
|
#.....O#
|
||||||
|
#.#O@..#
|
||||||
|
#...O..#
|
||||||
|
#...O..#
|
||||||
|
########
|
||||||
|
|
||||||
|
Move <:
|
||||||
|
########
|
||||||
|
#....OO#
|
||||||
|
##.....#
|
||||||
|
#.....O#
|
||||||
|
#.#O@..#
|
||||||
|
#...O..#
|
||||||
|
#...O..#
|
||||||
|
########
|
||||||
|
|
||||||
|
The larger example has many more moves; after the robot has finished those
|
||||||
|
moves, the warehouse would look like this:
|
||||||
|
|
||||||
|
##########
|
||||||
|
#.O.O.OOO#
|
||||||
|
#........#
|
||||||
|
#OO......#
|
||||||
|
#OO@.....#
|
||||||
|
#O#.....O#
|
||||||
|
#O.....OO#
|
||||||
|
#O.....OO#
|
||||||
|
#OO....OO#
|
||||||
|
##########
|
||||||
|
|
||||||
|
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.)
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
#######
|
||||||
|
#...O..
|
||||||
|
#......
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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?
|
||||||
|
|
||||||
|
Your puzzle answer was 1527563.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
To get the wider warehouse's map, start with your original map and, for
|
||||||
|
each tile, make the following changes:
|
||||||
|
|
||||||
|
• If the tile is #, the new map contains ## instead.
|
||||||
|
• If the tile is O, the new map contains [] instead.
|
||||||
|
• If the tile is ., the new map contains .. instead.
|
||||||
|
• If the tile is @, the new map contains @. instead.
|
||||||
|
|
||||||
|
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.)
|
||||||
|
|
||||||
|
The larger example from before would now look like this:
|
||||||
|
|
||||||
|
####################
|
||||||
|
##....[]....[]..[]##
|
||||||
|
##............[]..##
|
||||||
|
##..[][]....[]..[]##
|
||||||
|
##....[]@.....[]..##
|
||||||
|
##[]##....[]......##
|
||||||
|
##[]....[]....[]..##
|
||||||
|
##..[][]..[]..[][]##
|
||||||
|
##........[]......##
|
||||||
|
####################
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
#######
|
||||||
|
#...#.#
|
||||||
|
#.....#
|
||||||
|
#..OO@#
|
||||||
|
#..O..#
|
||||||
|
#.....#
|
||||||
|
#######
|
||||||
|
|
||||||
|
<vv<<^^<<^^
|
||||||
|
|
||||||
|
After appropriately resizing this map, the robot would push around these
|
||||||
|
boxes as follows:
|
||||||
|
|
||||||
|
Initial state:
|
||||||
|
##############
|
||||||
|
##......##..##
|
||||||
|
##..........##
|
||||||
|
##....[][]@.##
|
||||||
|
##....[]....##
|
||||||
|
##..........##
|
||||||
|
##############
|
||||||
|
|
||||||
|
Move <:
|
||||||
|
##############
|
||||||
|
##......##..##
|
||||||
|
##..........##
|
||||||
|
##...[][]@..##
|
||||||
|
##....[]....##
|
||||||
|
##..........##
|
||||||
|
##############
|
||||||
|
|
||||||
|
Move v:
|
||||||
|
##############
|
||||||
|
##......##..##
|
||||||
|
##..........##
|
||||||
|
##...[][]...##
|
||||||
|
##....[].@..##
|
||||||
|
##..........##
|
||||||
|
##############
|
||||||
|
|
||||||
|
Move v:
|
||||||
|
##############
|
||||||
|
##......##..##
|
||||||
|
##..........##
|
||||||
|
##...[][]...##
|
||||||
|
##....[]....##
|
||||||
|
##.......@..##
|
||||||
|
##############
|
||||||
|
|
||||||
|
Move <:
|
||||||
|
##############
|
||||||
|
##......##..##
|
||||||
|
##..........##
|
||||||
|
##...[][]...##
|
||||||
|
##....[]....##
|
||||||
|
##......@...##
|
||||||
|
##############
|
||||||
|
|
||||||
|
Move <:
|
||||||
|
##############
|
||||||
|
##......##..##
|
||||||
|
##..........##
|
||||||
|
##...[][]...##
|
||||||
|
##....[]....##
|
||||||
|
##.....@....##
|
||||||
|
##############
|
||||||
|
|
||||||
|
Move ^:
|
||||||
|
##############
|
||||||
|
##......##..##
|
||||||
|
##...[][]...##
|
||||||
|
##....[]....##
|
||||||
|
##.....@....##
|
||||||
|
##..........##
|
||||||
|
##############
|
||||||
|
|
||||||
|
Move ^:
|
||||||
|
##############
|
||||||
|
##......##..##
|
||||||
|
##...[][]...##
|
||||||
|
##....[]....##
|
||||||
|
##.....@....##
|
||||||
|
##..........##
|
||||||
|
##############
|
||||||
|
|
||||||
|
Move <:
|
||||||
|
##############
|
||||||
|
##......##..##
|
||||||
|
##...[][]...##
|
||||||
|
##....[]....##
|
||||||
|
##....@.....##
|
||||||
|
##..........##
|
||||||
|
##############
|
||||||
|
|
||||||
|
Move <:
|
||||||
|
##############
|
||||||
|
##......##..##
|
||||||
|
##...[][]...##
|
||||||
|
##....[]....##
|
||||||
|
##...@......##
|
||||||
|
##..........##
|
||||||
|
##############
|
||||||
|
|
||||||
|
Move ^:
|
||||||
|
##############
|
||||||
|
##......##..##
|
||||||
|
##...[][]...##
|
||||||
|
##...@[]....##
|
||||||
|
##..........##
|
||||||
|
##..........##
|
||||||
|
##############
|
||||||
|
|
||||||
|
Move ^:
|
||||||
|
##############
|
||||||
|
##...[].##..##
|
||||||
|
##...@.[]...##
|
||||||
|
##....[]....##
|
||||||
|
##..........##
|
||||||
|
##..........##
|
||||||
|
##############
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
##########
|
||||||
|
##...[]...
|
||||||
|
##........
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
####################
|
||||||
|
##[].......[].[][]##
|
||||||
|
##[]...........[].##
|
||||||
|
##[]........[][][]##
|
||||||
|
##[]......[]....[]##
|
||||||
|
##..##......[]....##
|
||||||
|
##..[]............##
|
||||||
|
##..@......[].[][]##
|
||||||
|
##......[][]..[]..##
|
||||||
|
####################
|
||||||
|
|
||||||
|
The sum of these boxes' GPS coordinates is 9021.
|
||||||
|
|
||||||
|
Predict the motion of the robot and boxes in this new, scaled-up
|
||||||
|
warehouse. What is the sum of all boxes' final GPS coordinates?
|
||||||
|
|
||||||
|
Your puzzle answer was 1521635.
|
||||||
|
|
||||||
|
Both parts of this puzzle are complete! They provide two gold stars: **
|
||||||
|
|
||||||
|
At this point, you should [17]return to your Advent calendar and try
|
||||||
|
another puzzle.
|
||||||
|
|
||||||
|
If you still want to see it, you can [18]get your puzzle input.
|
||||||
|
|
||||||
|
References
|
||||||
|
|
||||||
|
Visible links
|
||||||
|
1. https://adventofcode.com/
|
||||||
|
2. https://adventofcode.com/2024/about
|
||||||
|
3. https://adventofcode.com/2024/events
|
||||||
|
4. https://cottonbureau.com/people/advent-of-code
|
||||||
|
5. https://adventofcode.com/2024/settings
|
||||||
|
6. https://adventofcode.com/2024/auth/logout
|
||||||
|
7. Advent of Code Supporter
|
||||||
|
https://adventofcode.com/2024/support
|
||||||
|
8. https://adventofcode.com/2024
|
||||||
|
9. https://adventofcode.com/2024
|
||||||
|
10. https://adventofcode.com/2024/support
|
||||||
|
11. https://adventofcode.com/2024/sponsors
|
||||||
|
12. https://adventofcode.com/2024/leaderboard
|
||||||
|
13. https://adventofcode.com/2024/stats
|
||||||
|
16. https://adventofcode.com/2021/day/6
|
||||||
|
17. https://adventofcode.com/2024
|
||||||
|
18. https://adventofcode.com/2024/day/15/input
|
@ -1,276 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
h "git.bullercodeworks.com/brian/adventofcode/helpers"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
inp := h.StdinToStringSlice()
|
|
||||||
part1(inp)
|
|
||||||
// fmt.Println()
|
|
||||||
// part2(inp)
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
N = h.Coordinate{X: 0, Y: -1}
|
|
||||||
E = h.Coordinate{X: 1, Y: 0}
|
|
||||||
S = h.Coordinate{X: 0, Y: 1}
|
|
||||||
W = h.Coordinate{X: -1, Y: 0}
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
scoreTrack map[h.Coordinate]int
|
|
||||||
bestCostToEnd map[h.Coordinate]int
|
|
||||||
)
|
|
||||||
|
|
||||||
func part1(inpS []string) {
|
|
||||||
inp := h.StringSliceToCoordByteMap(inpS)
|
|
||||||
scoreTrack = make(map[h.Coordinate]int)
|
|
||||||
bestCostToEnd = make(map[h.Coordinate]int)
|
|
||||||
|
|
||||||
start, _ := inp.FindFirst('S')
|
|
||||||
end, _ := inp.FindFirst('E')
|
|
||||||
inp.Put(start, '.')
|
|
||||||
bestCostToEnd[end] = 0
|
|
||||||
|
|
||||||
cd := CD{c: start, d: E}
|
|
||||||
solve(inp, cd, end, 0, []h.Coordinate{cd.c})
|
|
||||||
best, ok := scoreTrack[end]
|
|
||||||
if !ok {
|
|
||||||
panic(errors.New("no path to end found"))
|
|
||||||
}
|
|
||||||
fmt.Println("Best Score:", best)
|
|
||||||
|
|
||||||
bestSeats := make(map[h.Coordinate]byte)
|
|
||||||
for i := range bestPaths {
|
|
||||||
for j := range bestPaths[i] {
|
|
||||||
bestSeats[bestPaths[i][j]] = byte('0' + i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printBestSeats(inp, bestSeats)
|
|
||||||
fmt.Println("Seats:", len(bestSeats))
|
|
||||||
}
|
|
||||||
|
|
||||||
var bestPaths [][]h.Coordinate
|
|
||||||
|
|
||||||
func solve(inp h.CoordByteMap, start CD, end h.Coordinate, score int, currPath []h.Coordinate) int {
|
|
||||||
// tryMove takes the cd that we're moving to and the cost to move there
|
|
||||||
// and returns the cost to get from that cd to the end
|
|
||||||
tryMove := func(c CD, cost int) int {
|
|
||||||
if inp.ContainsCoord(c.c) && inp.Get(c.c) != '#' {
|
|
||||||
// printPathMap(inp, c, end, currPath)
|
|
||||||
// poi := h.Coordinate{X: 3, Y: 10}
|
|
||||||
// time.Sleep(time.Second / 20)
|
|
||||||
nextScore := score + cost
|
|
||||||
v, ok := bestCostToEnd[c.c]
|
|
||||||
//if c.c.Equals(poi) {
|
|
||||||
// fmt.Println("Current Scoretrack[poi] =", v)
|
|
||||||
// fmt.Println("Next Score =", nextScore)
|
|
||||||
// time.Sleep(time.Second * 5)
|
|
||||||
//}
|
|
||||||
if !ok || v >= nextScore {
|
|
||||||
nxtPath := make([]h.Coordinate, len(currPath))
|
|
||||||
copy(nxtPath, currPath)
|
|
||||||
nxtPath = append(nxtPath, c.c)
|
|
||||||
|
|
||||||
// Check end conditions
|
|
||||||
if c.c.Equals(end) {
|
|
||||||
if !ok || v > nextScore { // New Best
|
|
||||||
fmt.Println("New Best Path")
|
|
||||||
scoreTrack[end] = nextScore
|
|
||||||
bestPaths = [][]h.Coordinate{nxtPath}
|
|
||||||
} else if v == nextScore { // Another Best Path
|
|
||||||
fmt.Println("Adding path to best paths")
|
|
||||||
bestPaths = append(bestPaths, nxtPath)
|
|
||||||
}
|
|
||||||
return cost
|
|
||||||
}
|
|
||||||
// Not the end, but keep going
|
|
||||||
scoreTrack[c.c] = nextScore
|
|
||||||
solve(inp, c, end, nextScore, nxtPath)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return h.MAX_INT
|
|
||||||
}
|
|
||||||
// Test forward
|
|
||||||
cost := tryMove(start.move(), 1)
|
|
||||||
// Test CW
|
|
||||||
if wrk := tryMove(start.turnCW().move(), 1001); wrk < cost {
|
|
||||||
cost = wrk
|
|
||||||
}
|
|
||||||
// Test CCW
|
|
||||||
if wrk := tryMove(start.turnCCW().move(), 1001); wrk < cost {
|
|
||||||
cost = wrk
|
|
||||||
}
|
|
||||||
bestCostToEnd[start.c] = cost
|
|
||||||
return cost
|
|
||||||
}
|
|
||||||
|
|
||||||
func printPathMap(inp h.CoordByteMap, loc CD, end h.Coordinate, path []h.Coordinate) {
|
|
||||||
fmt.Print(h.CLEAR_SCREEN)
|
|
||||||
wrk := inp.Copy()
|
|
||||||
wrk.ReplaceAll('.', ' ')
|
|
||||||
for i := range path {
|
|
||||||
wrk.Put(path[i], 'o')
|
|
||||||
}
|
|
||||||
wrk.Put(loc.c, loc.Byte())
|
|
||||||
fmt.Println(wrk)
|
|
||||||
if v, ok := scoreTrack[end]; ok {
|
|
||||||
fmt.Printf("Best Score: %v (Paths: %d)\n", v, len(bestPaths))
|
|
||||||
} else {
|
|
||||||
fmt.Println("Waiting on best score...")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func printBestSeats(inp h.CoordByteMap, seats map[h.Coordinate]byte) {
|
|
||||||
fmt.Print(h.CLEAR_SCREEN)
|
|
||||||
wrk := inp.Copy()
|
|
||||||
wrk.ReplaceAll('.', ' ')
|
|
||||||
for k, v := range seats {
|
|
||||||
wrk.Put(k, byte(0+v))
|
|
||||||
}
|
|
||||||
fmt.Println(wrk)
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
func part2(inpS []string) {
|
|
||||||
inp := h.StringSliceToCoordByteMap(inpS)
|
|
||||||
scoreTrack = make(map[h.Coordinate]int)
|
|
||||||
start, _ := inp.FindFirst('S')
|
|
||||||
end, _ := inp.FindFirst('E')
|
|
||||||
inp.Put(start, '.')
|
|
||||||
cd := CD{c: start, d: E}
|
|
||||||
lookForSeats(inp, cd, end, 0, []h.Coordinate{cd.c})
|
|
||||||
_, ok := scoreTrack[end]
|
|
||||||
if !ok {
|
|
||||||
panic(errors.New("no path to end found"))
|
|
||||||
}
|
|
||||||
bestSeats := make(map[h.Coordinate]int)
|
|
||||||
for i := range bestPaths {
|
|
||||||
for j := range bestPaths[i] {
|
|
||||||
bestSeats[bestPaths[i][j]] = i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fmt.Println("Number of Seats:", len(bestSeats))
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func coordInPath(c h.Coordinate, path []h.Coordinate) bool {
|
|
||||||
for i := range path {
|
|
||||||
if path[i].Equals(c) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func lookForSeats(inp h.CoordByteMap, start CD, end h.Coordinate, score int, path []h.Coordinate) int {
|
|
||||||
// Check for finished:
|
|
||||||
if start.c.Equals(end) {
|
|
||||||
v, ok := scoreTrack[end]
|
|
||||||
if !ok || v > score {
|
|
||||||
// We have a new best path
|
|
||||||
bestPaths = [][]h.Coordinate{path}
|
|
||||||
scoreTrack[end] = score
|
|
||||||
} else if scoreTrack[end] == score {
|
|
||||||
bestPaths = append(bestPaths, path)
|
|
||||||
}
|
|
||||||
return score
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper func
|
|
||||||
canMoveTo := func(p h.Coordinate) bool {
|
|
||||||
return inp.ContainsCoord(p) && inp.Get(p) != '#'
|
|
||||||
}
|
|
||||||
// Keep moving:
|
|
||||||
tryMove := func(c CD, cost int) {
|
|
||||||
if canMoveTo(c.c) {
|
|
||||||
// Check if this path has alread gone through this spot
|
|
||||||
nxtPath := make([]h.Coordinate, len(path))
|
|
||||||
copy(nxtPath, path)
|
|
||||||
if coordInPath(c.c, nxtPath) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// Ok, now what's the best score we end up if we make this move?
|
|
||||||
nextScore := score + cost
|
|
||||||
n, ok := scoreTrack[c.c]
|
|
||||||
if !ok || n > nextScore {
|
|
||||||
lookForSeats(inp, c, end, nextScore, append(nxtPath, c.c))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Test forward
|
|
||||||
tryMove(start.move(), 1)
|
|
||||||
// Test CW
|
|
||||||
tryMove(start.turnCW().move(), 1001)
|
|
||||||
// Test CCW
|
|
||||||
tryMove(start.turnCCW().move(), 1001)
|
|
||||||
return scoreTrack[start.c]
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
type CD struct {
|
|
||||||
c h.Coordinate
|
|
||||||
d h.Coordinate
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cd CD) move() CD {
|
|
||||||
return CD{
|
|
||||||
c: cd.c.Add(cd.d),
|
|
||||||
d: cd.d,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cd CD) turnCW() CD {
|
|
||||||
var newD h.Coordinate
|
|
||||||
switch cd.d {
|
|
||||||
case N:
|
|
||||||
newD = E
|
|
||||||
case E:
|
|
||||||
newD = S
|
|
||||||
case S:
|
|
||||||
newD = W
|
|
||||||
case W:
|
|
||||||
newD = N
|
|
||||||
}
|
|
||||||
return CD{
|
|
||||||
c: cd.c,
|
|
||||||
d: newD,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cd CD) turnCCW() CD {
|
|
||||||
var newD h.Coordinate
|
|
||||||
switch cd.d {
|
|
||||||
case N:
|
|
||||||
newD = W
|
|
||||||
case E:
|
|
||||||
newD = N
|
|
||||||
case S:
|
|
||||||
newD = E
|
|
||||||
case W:
|
|
||||||
newD = S
|
|
||||||
}
|
|
||||||
return CD{
|
|
||||||
c: cd.c,
|
|
||||||
d: newD,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cd CD) Byte() byte {
|
|
||||||
switch cd.d {
|
|
||||||
case N:
|
|
||||||
return '^'
|
|
||||||
case E:
|
|
||||||
return '>'
|
|
||||||
case S:
|
|
||||||
return 'v'
|
|
||||||
case W:
|
|
||||||
return '<'
|
|
||||||
}
|
|
||||||
return '?'
|
|
||||||
}
|
|
190
2024/day16/problem
Normal file
190
2024/day16/problem
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
--- Day 16: Reindeer Maze ---
|
||||||
|
|
||||||
|
It's time again for the [16]Reindeer Olympics! This year, the big event is
|
||||||
|
the Reindeer Maze, where the Reindeer compete for the lowest score.
|
||||||
|
|
||||||
|
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?
|
||||||
|
|
||||||
|
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).
|
||||||
|
|
||||||
|
To figure out the best place to sit, you start by grabbing a map (your
|
||||||
|
puzzle input) from a nearby kiosk. For example:
|
||||||
|
|
||||||
|
###############
|
||||||
|
#.......#....E#
|
||||||
|
#.#.###.#.###.#
|
||||||
|
#.....#.#...#.#
|
||||||
|
#.###.#####.#.#
|
||||||
|
#.#.#.......#.#
|
||||||
|
#.#.#####.###.#
|
||||||
|
#...........#.#
|
||||||
|
###.#.#####.#.#
|
||||||
|
#...#.....#.#.#
|
||||||
|
#.#.#.###.#.#.#
|
||||||
|
#.....#...#.#.#
|
||||||
|
#.###.#.#.#.#.#
|
||||||
|
#S..#.....#...#
|
||||||
|
###############
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
###############
|
||||||
|
#.......#....E#
|
||||||
|
#.#.###.#.###^#
|
||||||
|
#.....#.#...#^#
|
||||||
|
#.###.#####.#^#
|
||||||
|
#.#.#.......#^#
|
||||||
|
#.#.#####.###^#
|
||||||
|
#..>>>>>>>>v#^#
|
||||||
|
###^#.#####v#^#
|
||||||
|
#>>^#.....#v#^#
|
||||||
|
#^#.#.###.#v#^#
|
||||||
|
#^....#...#v#^#
|
||||||
|
#^###.#.#.#v#^#
|
||||||
|
#S..#.....#>>^#
|
||||||
|
###############
|
||||||
|
|
||||||
|
Here's a second example:
|
||||||
|
|
||||||
|
#################
|
||||||
|
#...#...#...#..E#
|
||||||
|
#.#.#.#.#.#.#.#.#
|
||||||
|
#.#.#.#...#...#.#
|
||||||
|
#.#.#.#.###.#.#.#
|
||||||
|
#...#.#.#.....#.#
|
||||||
|
#.#.#.#.#.#####.#
|
||||||
|
#.#...#.#.#.....#
|
||||||
|
#.#.#####.#.###.#
|
||||||
|
#.#.#.......#...#
|
||||||
|
#.#.###.#####.###
|
||||||
|
#.#.#...#.....#.#
|
||||||
|
#.#.#.#####.###.#
|
||||||
|
#.#.#.........#.#
|
||||||
|
#.#.#.#########.#
|
||||||
|
#S#.............#
|
||||||
|
#################
|
||||||
|
|
||||||
|
In this maze, the best paths cost 11048 points; following one such path
|
||||||
|
would look like this:
|
||||||
|
|
||||||
|
#################
|
||||||
|
#...#...#...#..E#
|
||||||
|
#.#.#.#.#.#.#.#^#
|
||||||
|
#.#.#.#...#...#^#
|
||||||
|
#.#.#.#.###.#.#^#
|
||||||
|
#>>v#.#.#.....#^#
|
||||||
|
#^#v#.#.#.#####^#
|
||||||
|
#^#v..#.#.#>>>>^#
|
||||||
|
#^#v#####.#^###.#
|
||||||
|
#^#v#..>>>>^#...#
|
||||||
|
#^#v###^#####.###
|
||||||
|
#^#v#>>^#.....#.#
|
||||||
|
#^#v#^#####.###.#
|
||||||
|
#^#v#^........#.#
|
||||||
|
#^#v#^#########.#
|
||||||
|
#S#>>^..........#
|
||||||
|
#################
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Analyze your map carefully. What is the lowest score a Reindeer could
|
||||||
|
possibly get?
|
||||||
|
|
||||||
|
Your puzzle answer was 72400.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
Now that you know what the best paths look like, you can figure out the
|
||||||
|
best spot to sit.
|
||||||
|
|
||||||
|
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!
|
||||||
|
|
||||||
|
So, you'll need to determine which tiles are part of any best path through
|
||||||
|
the maze, including the S and E tiles.
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
###############
|
||||||
|
#.......#....O#
|
||||||
|
#.#.###.#.###O#
|
||||||
|
#.....#.#...#O#
|
||||||
|
#.###.#####.#O#
|
||||||
|
#.#.#.......#O#
|
||||||
|
#.#.#####.###O#
|
||||||
|
#..OOOOOOOOO#O#
|
||||||
|
###O#O#####O#O#
|
||||||
|
#OOO#O....#O#O#
|
||||||
|
#O#O#O###.#O#O#
|
||||||
|
#OOOOO#...#O#O#
|
||||||
|
#O###.#.#.#O#O#
|
||||||
|
#O..#.....#OOO#
|
||||||
|
###############
|
||||||
|
|
||||||
|
In the second example, there are 64 tiles that are part of at least one of
|
||||||
|
the best paths:
|
||||||
|
|
||||||
|
#################
|
||||||
|
#...#...#...#..O#
|
||||||
|
#.#.#.#.#.#.#.#O#
|
||||||
|
#.#.#.#...#...#O#
|
||||||
|
#.#.#.#.###.#.#O#
|
||||||
|
#OOO#.#.#.....#O#
|
||||||
|
#O#O#.#.#.#####O#
|
||||||
|
#O#O..#.#.#OOOOO#
|
||||||
|
#O#O#####.#O###O#
|
||||||
|
#O#O#..OOOOO#OOO#
|
||||||
|
#O#O###O#####O###
|
||||||
|
#O#O#OOO#..OOO#.#
|
||||||
|
#O#O#O#####O###.#
|
||||||
|
#O#O#OOOOOOO..#.#
|
||||||
|
#O#O#O#########.#
|
||||||
|
#O#OOO..........#
|
||||||
|
#################
|
||||||
|
|
||||||
|
Analyze your map further. How many tiles are part of at least one of the
|
||||||
|
best paths through the maze?
|
||||||
|
|
||||||
|
Your puzzle answer was 435.
|
||||||
|
|
||||||
|
Both parts of this puzzle are complete! They provide two gold stars: **
|
||||||
|
|
||||||
|
At this point, you should [17]return to your Advent calendar and try
|
||||||
|
another puzzle.
|
||||||
|
|
||||||
|
If you still want to see it, you can [18]get your puzzle input.
|
||||||
|
|
||||||
|
References
|
||||||
|
|
||||||
|
Visible links
|
||||||
|
1. https://adventofcode.com/
|
||||||
|
2. https://adventofcode.com/2024/about
|
||||||
|
3. https://adventofcode.com/2024/events
|
||||||
|
5. https://adventofcode.com/2024/settings
|
||||||
|
6. https://adventofcode.com/2024/auth/logout
|
||||||
|
7. Advent of Code Supporter
|
||||||
|
https://adventofcode.com/2024/support
|
||||||
|
8. https://adventofcode.com/2024
|
||||||
|
9. https://adventofcode.com/2024
|
||||||
|
10. https://adventofcode.com/2024/support
|
||||||
|
12. https://adventofcode.com/2024/leaderboard
|
||||||
|
13. https://adventofcode.com/2024/stats
|
||||||
|
16. https://adventofcode.com/2015/day/14
|
||||||
|
17. https://adventofcode.com/2024
|
||||||
|
18. https://adventofcode.com/2024/day/16/input
|
168
2024/day17/problem
Normal file
168
2024/day17/problem
Normal file
@ -0,0 +1,168 @@
|
|||||||
|
Advent of Code
|
||||||
|
|
||||||
|
--- Day 17: Chronospatial Computer ---
|
||||||
|
|
||||||
|
The Historians push the button on their strange device, but this time, you
|
||||||
|
all just feel like you're [16]falling.
|
||||||
|
|
||||||
|
"Situation critical", the device announces in a familiar voice.
|
||||||
|
"Bootstrapping process failed. Initializing debugger...."
|
||||||
|
|
||||||
|
The small handheld device suddenly unfolds into an entire computer! The
|
||||||
|
Historians look around nervously before one of them tosses it to you.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
• Combo operands 0 through 3 represent literal values 0 through 3.
|
||||||
|
• Combo operand 4 represents the value of register A.
|
||||||
|
• Combo operand 5 represents the value of register B.
|
||||||
|
• Combo operand 6 represents the value of register C.
|
||||||
|
• Combo operand 7 is reserved and will not appear in valid programs.
|
||||||
|
|
||||||
|
The eight instructions are as follows:
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
The bxl instruction (opcode 1) calculates the [17]bitwise XOR of register
|
||||||
|
B and the instruction's literal operand, then stores the result in
|
||||||
|
register B.
|
||||||
|
|
||||||
|
The bst instruction (opcode 2) calculates the value of its combo operand
|
||||||
|
[18]modulo 8 (thereby keeping only its lowest 3 bits), then writes that
|
||||||
|
value to the B register.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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.)
|
||||||
|
|
||||||
|
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.)
|
||||||
|
|
||||||
|
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.)
|
||||||
|
|
||||||
|
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.)
|
||||||
|
|
||||||
|
Here are some examples of instruction operation:
|
||||||
|
|
||||||
|
• If register C contains 9, the program 2,6 would set register B to 1.
|
||||||
|
• If register A contains 10, the program 5,0,5,1,5,4 would output 0,1,2.
|
||||||
|
• 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.
|
||||||
|
• If register B contains 29, the program 1,7 would set register B to 26.
|
||||||
|
• If register B contains 2024 and register C contains 43690, the program
|
||||||
|
4,0 would set register B to 44354.
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
Register A: 729
|
||||||
|
Register B: 0
|
||||||
|
Register C: 0
|
||||||
|
|
||||||
|
Program: 0,1,5,4,3,0
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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?
|
||||||
|
|
||||||
|
Your puzzle answer was 2,7,6,5,6,0,2,3,1.
|
||||||
|
|
||||||
|
--- Part Two ---
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
Register A: 2024
|
||||||
|
Register B: 0
|
||||||
|
Register C: 0
|
||||||
|
|
||||||
|
Program: 0,3,5,4,3,0
|
||||||
|
|
||||||
|
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.)
|
||||||
|
|
||||||
|
What is the lowest positive initial value for register A that causes the
|
||||||
|
program to output a copy of itself?
|
||||||
|
|
||||||
|
Your puzzle answer was 107416870455451.
|
||||||
|
|
||||||
|
Both parts of this puzzle are complete! They provide two gold stars: **
|
||||||
|
|
||||||
|
At this point, you should [19]return to your Advent calendar and try
|
||||||
|
another puzzle.
|
||||||
|
|
||||||
|
If you still want to see it, you can [20]get your puzzle input.
|
||||||
|
|
||||||
|
References
|
||||||
|
|
||||||
|
Visible links
|
||||||
|
1. https://adventofcode.com/
|
||||||
|
2. https://adventofcode.com/2024/about
|
||||||
|
3. https://adventofcode.com/2024/events
|
||||||
|
4. https://cottonbureau.com/people/advent-of-code
|
||||||
|
5. https://adventofcode.com/2024/settings
|
||||||
|
6. https://adventofcode.com/2024/auth/logout
|
||||||
|
7. Advent of Code Supporter
|
||||||
|
https://adventofcode.com/2024/support
|
||||||
|
8. https://adventofcode.com/2024
|
||||||
|
9. https://adventofcode.com/2024
|
||||||
|
10. https://adventofcode.com/2024/support
|
||||||
|
11. https://adventofcode.com/2024/sponsors
|
||||||
|
12. https://adventofcode.com/2024/leaderboard
|
||||||
|
13. https://adventofcode.com/2024/stats
|
||||||
|
16. https://adventofcode.com/2018/day/6
|
||||||
|
17. https://en.wikipedia.org/wiki/Bitwise_operation#XOR
|
||||||
|
18. https://en.wikipedia.org/wiki/Modulo
|
||||||
|
19. https://adventofcode.com/2024
|
||||||
|
20. https://adventofcode.com/2024/day/17/input
|
Loading…
Reference in New Issue
Block a user