Add problems to the days

This commit is contained in:
Brian Buller 2019-12-12 14:06:45 -06:00
parent 1400400fe0
commit bb20738fcc
8 changed files with 1204 additions and 0 deletions

189
2019/day05/problem Normal file
View File

@ -0,0 +1,189 @@
Advent of Code
--- Day 5: Sunny with a Chance of Asteroids ---
You're starting to sweat as the ship makes its way toward Mercury. The Elves
suggest that you get the air conditioner working by upgrading your ship
computer to support the Thermal Environment Supervision Terminal.
The Thermal Environment Supervision Terminal (TEST) starts by running a
diagnostic program (your puzzle input). The TEST diagnostic program will run
on your existing Intcode computer after a few modifications:
First, you'll need to add two new instructions:
 Opcode 3 takes a single integer as input and saves it to the position
given by its only parameter. For example, the instruction 3,50 would take
an input value and store it at address 50. • Opcode 4 outputs the value of
its only parameter. For example, the instruction 4,50 would output the
value at address 50.
Programs that use these instructions will come with documentation that
explains what should be connected to the input and output. The program
3,0,4,0,99 outputs whatever it gets as input, then halts.
Second, you'll need to add support for parameter modes:
Each parameter of an instruction is handled based on its parameter mode.
Right now, your ship computer already understands parameter mode 0, position
mode, which causes the parameter to be interpreted as a position - if the
parameter is 50, its value is the value stored at address 50 in memory.
Until now, all parameters have been in position mode.
Now, your ship computer will also need to handle parameters in mode 1,
immediate mode. In immediate mode, a parameter is interpreted as a value -
if the parameter is 50, its value is simply 50.
Parameter modes are stored in the same value as the instruction's opcode.
The opcode is a two-digit number based only on the ones and tens digit of
the value, that is, the opcode is the rightmost two digits of the first
value in an instruction. Parameter modes are single digits, one per
parameter, read right-to-left from the opcode: the first parameter's mode is
in the hundreds digit, the second parameter's mode is in the thousands
digit, the third parameter's mode is in the ten-thousands digit, and so on.
Any missing modes are 0.
For example, consider the program 1002,4,3,4,33.
The first instruction, 1002,4,3,4, is a multiply instruction - the rightmost
two digits of the first value, 02, indicate opcode 2, multiplication. Then,
going right to left, the parameter modes are 0 (hundreds digit), 1
(thousands digit), and 0 (ten-thousands digit, not present and therefore
zero):
ABCDE 1002
DE - two-digit opcode, 02 == opcode 2 C - mode of 1st parameter, 0 ==
position mode B - mode of 2nd parameter, 1 == immediate mode A - mode of 3rd
parameter, 0 == position mode, omitted due to being a leading zero
This instruction multiplies its first two parameters. The first parameter, 4
in position mode, works like it did before - its value is the value stored
at address 4 (33). The second parameter, 3 in immediate mode, simply has
value 3. The result of this operation, 33 * 3 = 99, is written according to
the third parameter, 4 in position mode, which also works like it did before
- 99 is written to address 4.
Parameters that an instruction writes to will never be in immediate mode.
Finally, some notes:
 It is important to remember that the instruction pointer should increase
by the number of values in the instruction after the instruction finishes.
Because of the new instructions, this amount is no longer always 4.
 Integers can be negative: 1101,100,-1,4,0 is a valid program (find 100 +
-1, store the result in position 4).
The TEST diagnostic program will start by requesting from the user the ID of
the system to test by running an input instruction - provide it 1, the ID
for the ship's air conditioner unit.
It will then perform a series of diagnostic tests confirming that various
parts of the Intcode computer, like parameter modes, function correctly. For
each test, it will run an output instruction indicating how far the result
of the test was from the expected value, where 0 means the test was
successful. Non-zero outputs mean that a function is not working correctly;
check the instructions that were run before the output instruction to see
which one failed.
Finally, the program will output a diagnostic code and immediately halt.
This final output isn't an error; an output followed immediately by a halt
means the program finished. If all outputs were zero except the diagnostic
code, the diagnostic program ran successfully.
After providing 1 to the only input instruction and passing all the tests,
what diagnostic code does the program produce?
Your puzzle answer was 16489636.
--- Part Two ---
The air conditioner comes online! Its cold air feels good for a while, but
then the TEST alarms start to go off. Since the air conditioner can't vent
its heat anywhere but back into the spacecraft, it's actually making the air
inside the ship warmer.
Instead, you'll need to use the TEST to extend the thermal radiators.
Fortunately, the diagnostic program (your puzzle input) is already equipped
for this. Unfortunately, your Intcode computer is not.
Your computer is only missing a few opcodes:
 Opcode 5 is jump-if-true: if the first parameter is non-zero, it sets
the instruction pointer to the value from the second parameter. Otherwise,
it does nothing. • Opcode 6 is jump-if-false: if the first parameter is
zero, it sets the instruction pointer to the value from the second
parameter. Otherwise, it does nothing. • Opcode 7 is less than: if the
first parameter is less than the second parameter, it stores 1 in the
position given by the third parameter. Otherwise, it stores 0. • Opcode 8
is equals: if the first parameter is equal to the second parameter, it
stores 1 in the position given by the third parameter. Otherwise, it
stores 0.
Like all instructions, these instructions need to support parameter modes as
described above.
Normally, after an instruction is finished, the instruction pointer
increases by the number of values in that instruction. However, if the
instruction modifies the instruction pointer, that value is used and the
instruction pointer is not automatically increased.
For example, here are several programs that take one input, compare it to
the value 8, and then produce one output:
 3,9,8,9,10,9,4,9,99,-1,8 - Using position mode, consider whether the
input is equal to 8; output 1 (if it is) or 0 (if it is not).
 3,9,7,9,10,9,4,9,99,-1,8 - Using position mode, consider whether the
input is less than 8; output 1 (if it is) or 0 (if it is not).
 3,3,1108,-1,8,3,4,3,99 - Using immediate mode, consider whether the
input is equal to 8; output 1 (if it is) or 0 (if it is not).
 3,3,1107,-1,8,3,4,3,99 - Using immediate mode, consider whether the
input is less than 8; output 1 (if it is) or 0 (if it is not).
Here are some jump tests that take an input, then output 0 if the input was
zero or 1 if the input was non-zero:
 3,12,6,12,15,1,13,14,13,4,13,99,-1,0,1,9 (using position mode)
 3,3,1105,-1,9,1101,0,0,12,4,12,99,1 (using immediate mode)
Here's a larger example:
3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31,
1106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104,
999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99
The above example program uses an input instruction to ask for a single
number. The program will then output 999 if the input value is below 8,
output 1000 if the input value is equal to 8, or output 1001 if the input
value is greater than 8.
This time, when the TEST diagnostic program runs its input instruction to
get the ID of the system to test, provide it 5, the ID for the ship's
thermal radiator controller. This diagnostic test suite only outputs one
number, the diagnostic code.
What is the diagnostic code for system ID 5?
Your puzzle answer was 9386583.
Both parts of this puzzle are complete! They provide two gold stars: **
At this point, you should return to your Advent calendar and try another
puzzle.
If you still want to see it, you can get your puzzle input.
References
Visible links . https://adventofcode.com/ .
https://adventofcode.com/2019/about . https://adventofcode.com/2019/events .
https://adventofcode.com/2019/settings .
https://adventofcode.com/2019/auth/logout . Advent of Code Supporter
https://adventofcode.com/2019/support . https://adventofcode.com/2019 .
https://adventofcode.com/2019 . https://adventofcode.com/2019/support .
https://adventofcode.com/2019/sponsors .
https://adventofcode.com/2019/leaderboard .
https://adventofcode.com/2019/stats . https://adventofcode.com/2019/sponsors
https://adventofcode.com/2019/day/2 .
https://en.wikipedia.org/wiki/Spacecraft_thermal_control .
https://adventofcode.com/2019 . https://adventofcode.com/2019/day/5/input .

139
2019/day06/problem Normal file
View File

@ -0,0 +1,139 @@
Advent of Code
--- Day 6: Universal Orbit Map ---
You've landed at the Universal Orbit Map facility on Mercury. Because navigation in space often involves transferring between orbits, the orbit maps here are useful for finding efficient routes between, for example, you and Santa. You download a map of the local orbits (your puzzle input).
Except for the universal Center of Mass (COM), every object in space is in orbit around exactly one other object. An orbit looks roughly like this:
\
\
|
|
AAA--> o o <--BBB
|
|
/
/
In this diagram, the object BBB is in orbit around AAA. The path that BBB takes around AAA (drawn with lines) is only partly shown. In the map data, this orbital relationship is written AAA)BBB, which means "BBB is in orbit around AAA".
Before you use your map data to plot a course, you need to make sure it wasn't corrupted during the download. To verify maps, the Universal Orbit Map facility uses orbit count checksums - the total number of direct orbits (like the one shown above) and indirect orbits.
Whenever A orbits B and B orbits C, then A indirectly orbits C. This chain can be any number of objects long: if A orbits B, B orbits C, and C orbits D, then A indirectly orbits D.
For example, suppose you have the following map:
COM)B
B)C
C)D
D)E
E)F
B)G
G)H
D)I
E)J
J)K
K)L
Visually, the above map of orbits looks like this:
G - H J - K - L
/ /
COM - B - C - D - E - F
\
I
In this visual representation, when two objects are connected by a line, the one on the right directly orbits the one on the left.
Here, we can count the total number of orbits as follows:
 D directly orbits C and indirectly orbits B and COM, a total of 3 orbits.
 L directly orbits K and indirectly orbits J, E, D, C, B, and COM, a total of 7 orbits.
 COM orbits nothing.
The total number of direct and indirect orbits in this example is 42.
What is the total number of direct and indirect orbits in your map data?
Your puzzle answer was 106065.
--- Part Two ---
Now, you just need to figure out how many orbital transfers you (YOU) need to take to get to Santa (SAN).
You start at the object YOU are orbiting; your destination is the object SAN is orbiting. An orbital transfer lets you move from any object to an object orbiting or orbited by that object.
For example, suppose you have the following map:
COM)B
B)C
C)D
D)E
E)F
B)G
G)H
D)I
E)J
J)K
K)L
K)YOU
I)SAN
Visually, the above map of orbits looks like this:
YOU
/
G - H J - K - L
/ /
COM - B - C - D - E - F
\
I - SAN
In this example, YOU are in orbit around K, and SAN is in orbit around I. To move from K to I, a minimum of 4 orbital transfers are required:
 K to J
 J to E
 E to D
 D to I
Afterward, the map of orbits looks like this:
G - H J - K - L
/ /
COM - B - C - D - E - F
\
I - SAN
\
YOU
What is the minimum number of orbital transfers required to move from the object YOU are orbiting to the object SAN is orbiting? (Between the objects they are orbiting - not between YOU and SAN.)
Your puzzle answer was 253.
Both parts of this puzzle are complete! They provide two gold stars: **
At this point, you should return to your Advent calendar and try another puzzle.
If you still want to see it, you can get your puzzle input.
References
Visible links
. https://adventofcode.com/
. https://adventofcode.com/2019/about
. https://adventofcode.com/2019/events
. https://adventofcode.com/2019/settings
. https://adventofcode.com/2019/auth/logout
. Advent of Code Supporter
https://adventofcode.com/2019/support
. https://adventofcode.com/2019
. https://adventofcode.com/2019
. https://adventofcode.com/2019/support
. https://adventofcode.com/2019/sponsors
. https://adventofcode.com/2019/leaderboard
. https://adventofcode.com/2019/stats
. https://adventofcode.com/2019/sponsors
. https://en.wikipedia.org/wiki/Orbit
. https://adventofcode.com/2019
. https://adventofcode.com/2019/day/6/input

121
2019/day07/problem Normal file
View File

@ -0,0 +1,121 @@
Advent of Code
--- Day 7: Amplification Circuit ---
Based on the navigational maps, you're going to need to send more power to your ship's thrusters to reach Santa in time. To do this, you'll need to configure a series of amplifiers already installed on the ship.
There are five amplifiers connected in series; each one receives an input signal and produces an output signal. They are connected such that the first amplifier's output leads to the second amplifier's input, the second amplifier's output leads to the third amplifier's input, and so on. The first amplifier's
input value is 0, and the last amplifier's output leads to your ship's thrusters.
O-------O O-------O O-------O O-------O O-------O
0 ->| Amp A |->| Amp B |->| Amp C |->| Amp D |->| Amp E |-> (to thrusters)
O-------O O-------O O-------O O-------O O-------O
The Elves have sent you some Amplifier Controller Software (your puzzle input), a program that should run on your existing Intcode computer. Each amplifier will need to run a copy of the program.
When a copy of the program starts running on an amplifier, it will first use an input instruction to ask the amplifier for its current phase setting (an integer from 0 to 4). Each phase setting is used exactly once, but the Elves can't remember which amplifier needs which phase setting.
The program will then call another input instruction to get the amplifier's input signal, compute the correct output signal, and supply it back to the amplifier with an output instruction. (If the amplifier has not yet received an input signal, it waits until one arrives.)
Your job is to find the largest output signal that can be sent to the thrusters by trying every possible combination of phase settings on the amplifiers. Make sure that memory is not shared or reused between copies of the program.
For example, suppose you want to try the phase setting sequence 3,1,2,4,0, which would mean setting amplifier A to phase setting 3, amplifier B to setting 1, C to 2, D to 4, and E to 0. Then, you could determine the output signal that gets sent from amplifier E to the thrusters with the following steps:
 Start the copy of the amplifier controller software that will run on amplifier A. At its first input instruction, provide it the amplifier's phase setting, 3. At its second input instruction, provide it the input signal, 0. After some calculations, it will use an output instruction to indicate the
amplifier's output signal.
 Start the software for amplifier B. Provide it the phase setting (1) and then whatever output signal was produced from amplifier A. It will then produce a new output signal destined for amplifier C.
 Start the software for amplifier C, provide the phase setting (2) and the value from amplifier B, then collect its output signal.
 Run amplifier D's software, provide the phase setting (4) and input value, and collect its output signal.
 Run amplifier E's software, provide the phase setting (0) and input value, and collect its output signal.
The final output signal from amplifier E would be sent to the thrusters. However, this phase setting sequence may not have been the best one; another sequence might have sent a higher signal to the thrusters.
Here are some example programs:
 Max thruster signal 43210 (from phase setting sequence 4,3,2,1,0):
3,15,3,16,1002,16,10,16,1,16,15,15,4,15,99,0,0
 Max thruster signal 54321 (from phase setting sequence 0,1,2,3,4):
3,23,3,24,1002,24,10,24,1002,23,-1,23,
101,5,23,23,1,24,23,23,4,23,99,0,0
 Max thruster signal 65210 (from phase setting sequence 1,0,4,3,2):
3,31,3,32,1002,32,10,32,1001,31,-2,31,1007,31,0,33,
1002,33,7,33,1,33,31,31,1,32,31,31,4,31,99,0,0,0
Try every combination of phase settings on the amplifiers. What is the highest signal that can be sent to the thrusters?
Your puzzle answer was 17790.
--- Part Two ---
It's no good - in this configuration, the amplifiers can't generate a large enough output signal to produce the thrust you'll need. The Elves quickly talk you through rewiring the amplifiers into a feedback loop:
O-------O O-------O O-------O O-------O O-------O
0 -+->| Amp A |->| Amp B |->| Amp C |->| Amp D |->| Amp E |-.
| O-------O O-------O O-------O O-------O O-------O |
| |
'--------------------------------------------------------+
|
v
(to thrusters)
Most of the amplifiers are connected as they were before; amplifier A's output is connected to amplifier B's input, and so on. However, the output from amplifier E is now connected into amplifier A's input. This creates the feedback loop: the signal will be sent through the amplifiers many times.
In feedback loop mode, the amplifiers need totally different phase settings: integers from 5 to 9, again each used exactly once. These settings will cause the Amplifier Controller Software to repeatedly take input and produce output many times before halting. Provide each amplifier its phase setting at its
first input instruction; all further input/output instructions are for signals.
Don't restart the Amplifier Controller Software on any amplifier during this process. Each one should continue receiving and sending signals until it halts.
All signals sent or received in this process will be between pairs of amplifiers except the very first signal and the very last signal. To start the process, a 0 signal is sent to amplifier A's input exactly once.
Eventually, the software on the amplifiers will halt after they have processed the final loop. When this happens, the last output signal from amplifier E is sent to the thrusters. Your job is to find the largest output signal that can be sent to the thrusters using the new phase settings and feedback loop
arrangement.
Here are some example programs:
 Max thruster signal 139629729 (from phase setting sequence 9,8,7,6,5):
3,26,1001,26,-4,26,3,27,1002,27,2,27,1,27,26,
27,4,27,1001,28,-1,28,1005,28,6,99,0,0,5
 Max thruster signal 18216 (from phase setting sequence 9,7,8,5,6):
3,52,1001,52,-5,52,3,53,1,52,56,54,1007,54,5,55,1005,55,26,1001,54,
-5,54,1105,1,12,1,53,54,53,1008,54,0,55,1001,55,1,55,2,53,55,53,4,
53,1001,56,-1,56,1005,56,6,99,0,0,0,0,10
Try every combination of the new phase settings on the amplifier feedback loop. What is the highest signal that can be sent to the thrusters?
Your puzzle answer was 19384820.
Both parts of this puzzle are complete! They provide two gold stars: **
At this point, you should return to your Advent calendar and try another puzzle.
If you still want to see it, you can get your puzzle input.
References
Visible links
. https://adventofcode.com/
. https://adventofcode.com/2019/about
. https://adventofcode.com/2019/events
. https://adventofcode.com/2019/settings
. https://adventofcode.com/2019/auth/logout
. Advent of Code Supporter
https://adventofcode.com/2019/support
. https://adventofcode.com/2019
. https://adventofcode.com/2019
. https://adventofcode.com/2019/support
. https://adventofcode.com/2019/sponsors
. https://adventofcode.com/2019/leaderboard
. https://adventofcode.com/2019/stats
. https://adventofcode.com/2019/sponsors
. https://en.wikipedia.org/wiki/Amplifier
. https://adventofcode.com/2019/day/5
. https://adventofcode.com/2019
. https://adventofcode.com/2019/day/7/input

91
2019/day08/problem Normal file
View File

@ -0,0 +1,91 @@
Advent of Code
--- Day 8: Space Image Format ---
The Elves' spirits are lifted when they realize you have an opportunity to reboot one of their Mars rovers, and so they are curious if you would spend a brief sojourn on Mars. You land your ship near the rover.
When you reach the rover, you discover that it's already in the process of rebooting! It's just waiting for someone to enter a BIOS password. The Elf responsible for the rover takes a picture of the password (your puzzle input) and sends it to you via the Digital Sending Network.
Unfortunately, images sent via the Digital Sending Network aren't encoded with any normal encoding; instead, they're encoded in a special Space Image Format. None of the Elves seem to remember why this is the case. They send you the instructions to decode it.
Images are sent as a series of digits that each represent the color of a single pixel. The digits fill each row of the image left-to-right, then move downward to the next row, filling rows top-to-bottom until every pixel of the image is filled.
Each image actually consists of a series of identically-sized layers that are filled in this way. So, the first digit corresponds to the top-left pixel of the first layer, the second digit corresponds to the pixel to the right of that on the same layer, and so on until the last digit, which corresponds to the
bottom-right pixel of the last layer.
For example, given an image 3 pixels wide and 2 pixels tall, the image data 123456789012 corresponds to the following image layers:
Layer 1: 123
456
Layer 2: 789
012
The image you received is 25 pixels wide and 6 pixels tall.
To make sure the image wasn't corrupted during transmission, the Elves would like you to find the layer that contains the fewest 0 digits. On that layer, what is the number of 1 digits multiplied by the number of 2 digits?
Your puzzle answer was 1742.
--- Part Two ---
Now you're ready to decode the image. The image is rendered by stacking the layers and aligning the pixels with the same positions in each layer. The digits indicate the color of the corresponding pixel: 0 is black, 1 is white, and 2 is transparent.
The layers are rendered with the first layer in front and the last layer in back. So, if a given position has a transparent pixel in the first and second layers, a black pixel in the third layer, and a white pixel in the fourth layer, the final image would have a black pixel at that position.
For example, given an image 2 pixels wide and 2 pixels tall, the image data 0222112222120000 corresponds to the following image layers:
Layer 1: 02
22
Layer 2: 11
22
Layer 3: 22
12
Layer 4: 00
00
Then, the full image can be found by determining the top visible pixel in each position:
 The top-left pixel is black because the top layer is 0.
 The top-right pixel is white because the top layer is 2 (transparent), but the second layer is 1.
 The bottom-left pixel is white because the top two layers are 2, but the third layer is 1.
 The bottom-right pixel is black because the only visible pixel in that position is 0 (from layer 4).
So, the final image looks like this:
01
10
What message is produced after decoding your image?
Your puzzle answer was GJYEA.
Both parts of this puzzle are complete! They provide two gold stars: **
At this point, you should return to your Advent calendar and try another puzzle.
If you still want to see it, you can get your puzzle input.
References
Visible links
. https://adventofcode.com/
. https://adventofcode.com/2019/about
. https://adventofcode.com/2019/events
. https://adventofcode.com/2019/settings
. https://adventofcode.com/2019/auth/logout
. Advent of Code Supporter
https://adventofcode.com/2019/support
. https://adventofcode.com/2019
. https://adventofcode.com/2019
. https://adventofcode.com/2019/support
. https://adventofcode.com/2019/sponsors
. https://adventofcode.com/2019/leaderboard
. https://adventofcode.com/2019/stats
. https://adventofcode.com/2019/sponsors
. https://en.wikipedia.org/wiki/BIOS
. https://adventofcode.com/2019
. https://adventofcode.com/2019/day/8/input

83
2019/day09/problem Normal file
View File

@ -0,0 +1,83 @@
Advent of Code
--- Day 9: Sensor Boost ---
You've just said goodbye to the rebooted rover and left Mars when you receive a faint distress signal coming from the asteroid belt. It must be the Ceres monitoring station!
In order to lock on to the signal, you'll need to boost your sensors. The Elves send up the latest BOOST program - Basic Operation Of System Test.
While BOOST (your puzzle input) is capable of boosting your sensors, for tenuous safety reasons, it refuses to do so until the computer it runs on passes some checks to demonstrate it is a complete Intcode computer.
Your existing Intcode computer is missing one key feature: it needs support for parameters in relative mode.
Parameters in mode 2, relative mode, behave very similarly to parameters in position mode: the parameter is interpreted as a position. Like position mode, parameters in relative mode can be read from or written to.
The important difference is that relative mode parameters don't count from address 0. Instead, they count from a value called the relative base. The relative base starts at 0.
The address a relative mode parameter refers to is itself plus the current relative base. When the relative base is 0, relative mode parameters and position mode parameters with the same value refer to the same address.
For example, given a relative base of 50, a relative mode parameter of -7 refers to memory address 50 + -7 = 43.
The relative base is modified with the relative base offset instruction:
 Opcode 9 adjusts the relative base by the value of its only parameter. The relative base increases (or decreases, if the value is negative) by the value of the parameter.
For example, if the relative base is 2000, then after the instruction 109,19, the relative base would be 2019. If the next instruction were 204,-34, then the value at address 1985 would be output.
Your Intcode computer will also need a few other capabilities:
 The computer's available memory should be much larger than the initial program. Memory beyond the initial program starts with the value 0 and can be read or written like any other memory. (It is invalid to try to access memory at a negative address, though.)
 The computer should have support for large numbers. Some instructions near the beginning of the BOOST program will verify this capability.
Here are some example programs that use these features:
 109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99 takes no input and produces a copy of itself as output.
 1102,34915192,34915192,7,4,7,99,0 should output a 16-digit number.
 104,1125899906842624,99 should output the large number in the middle.
The BOOST program will ask for a single input; run it in test mode by providing it the value 1. It will perform a series of checks on each opcode, output any opcodes (and the associated parameter modes) that seem to be functioning incorrectly, and finally output a BOOST keycode.
Once your Intcode computer is fully functional, the BOOST program should report no malfunctioning opcodes when run in test mode; it should only output a single value, the BOOST keycode. What BOOST keycode does it produce?
Your puzzle answer was 2351176124.
--- Part Two ---
You now have a complete Intcode computer.
Finally, you can lock on to the Ceres distress signal! You just need to boost your sensors using the BOOST program.
The program runs in sensor boost mode by providing the input instruction the value 2. Once run, it will boost the sensors automatically, but it might take a few seconds to complete the operation on slower hardware. In sensor boost mode, the program will output a single value: the coordinates of the distress
signal.
Run the BOOST program in sensor boost mode. What are the coordinates of the distress signal?
Your puzzle answer was 73110.
Both parts of this puzzle are complete! They provide two gold stars: **
At this point, you should return to your Advent calendar and try another puzzle.
If you still want to see it, you can get your puzzle input.
References
Visible links
. https://adventofcode.com/
. https://adventofcode.com/2019/about
. https://adventofcode.com/2019/events
. https://adventofcode.com/2019/settings
. https://adventofcode.com/2019/auth/logout
. Advent of Code Supporter
https://adventofcode.com/2019/support
. https://adventofcode.com/2019
. https://adventofcode.com/2019
. https://adventofcode.com/2019/support
. https://adventofcode.com/2019/sponsors
. https://adventofcode.com/2019/leaderboard
. https://adventofcode.com/2019/stats
. https://adventofcode.com/2019/sponsors
. https://adventofcode.com/2019/day/5
. https://en.wikipedia.org/wiki/Quine_(computing)
. https://adventofcode.com/2019
. https://adventofcode.com/2019/day/9/input

206
2019/day10/problem Normal file
View File

@ -0,0 +1,206 @@
Advent of Code
--- Day 10: Monitoring Station ---
You fly into the asteroid belt and reach the Ceres monitoring station. The Elves here have an emergency: they're having trouble tracking all of the asteroids and can't be sure they're safe.
The Elves would like to build a new monitoring station in a nearby area of space; they hand you a map of all of the asteroids in that region (your puzzle input).
The map indicates whether each position is empty (.) or contains an asteroid (#). The asteroids are much smaller than they appear on the map, and every asteroid is exactly in the center of its marked position. The asteroids can be described with X,Y coordinates where X is the distance from the left edge and Y
is the distance from the top edge (so the top-left corner is 0,0 and the position immediately to its right is 1,0).
Your job is to figure out which asteroid would be the best place to build a new monitoring station. A monitoring station can detect any asteroid to which it has direct line of sight - that is, there cannot be another asteroid exactly between them. This line of sight can be at any angle, not just lines aligned
to the grid or diagonally. The best location is the asteroid that can detect the largest number of other asteroids.
For example, consider the following map:
.#..#
.....
#####
....#
...##
The best location for a new monitoring station on this map is the highlighted asteroid at 3,4 because it can detect 8 asteroids, more than any other location. (The only asteroid it cannot detect is the one at 1,0; its view of this asteroid is blocked by the asteroid at 2,2.) All other asteroids are worse
locations; they can detect 7 or fewer other asteroids. Here is the number of other asteroids a monitoring station on each asteroid could detect:
.7..7
.....
67775
....7
...87
Here is an asteroid (#) and some examples of the ways its line of sight might be blocked. If there were another asteroid at the location of a capital letter, the locations marked with the corresponding lowercase letter would be blocked and could not be detected:
#.........
...A......
...B..a...
.EDCG....a
..F.c.b...
.....c....
..efd.c.gb
.......c..
....f...c.
...e..d..c
Here are some larger examples:
 Best is 5,8 with 33 other asteroids detected:
......#.#.
#..#.#....
..#######.
.#.#.###..
.#..#.....
..#....#.#
#..#....#.
.##.#..###
##...#..#.
.#....####
 Best is 1,2 with 35 other asteroids detected:
#.#...#.#.
.###....#.
.#....#...
##.#.#.#.#
....#.#.#.
.##..###.#
..#...##..
..##....##
......#...
.####.###.
 Best is 6,3 with 41 other asteroids detected:
.#..#..###
####.###.#
....###.#.
..###.##.#
##.##.#.#.
....###..#
..#.#..#.#
#..#.#.###
.##...##.#
.....#.#..
 Best is 11,13 with 210 other asteroids detected:
.#..##.###...#######
##.############..##.
.#.######.########.#
.###.#######.####.#.
#####.##.#.##.###.##
..#####..#.#########
####################
#.####....###.#.#.##
##.#################
#####.##.###..####..
..######..##.#######
####.##.####...##..#
.#####..#.######.###
##...#.##########...
#.##########.#######
.####.#.###.###.#.##
....##.##.###..#####
.#.#.###########.###
#.#.#.#####.####.###
###.##.####.##.#..##
Find the best location for a new monitoring station. How many other asteroids can be detected from that location?
Your puzzle answer was 340.
--- Part Two ---
Once you give them the coordinates, the Elves quickly deploy an Instant Monitoring Station to the location and discover the worst: there are simply too many asteroids.
The only solution is complete vaporization by giant laser.
Fortunately, in addition to an asteroid scanner, the new monitoring station also comes equipped with a giant rotating laser perfect for vaporizing asteroids. The laser starts by pointing up and always rotates clockwise, vaporizing any asteroid it hits.
If multiple asteroids are exactly in line with the station, the laser only has enough power to vaporize one of them before continuing its rotation. In other words, the same asteroids that can be detected can be vaporized, but if vaporizing one asteroid makes another one detectable, the newly-detected asteroid
won't be vaporized until the laser has returned to the same position by rotating a full 360 degrees.
For example, consider the following map, where the asteroid with the new monitoring station (and laser) is marked X:
.#....#####...#..
##...##.#####..##
##...#...#.#####.
..#.....X...###..
..#.#.....#....##
The first nine asteroids to get vaporized, in order, would be:
.#....###24...#..
##...##.13#67..9#
##...#...5.8####.
..#.....X...###..
..#.#.....#....##
Note that some asteroids (the ones behind the asteroids marked 1, 5, and 7) won't have a chance to be vaporized until the next full rotation. The laser continues rotating; the next nine to be vaporized are:
.#....###.....#..
##...##...#.....#
##...#......1234.
..#.....X...5##..
..#.9.....8....76
The next nine to be vaporized are then:
.8....###.....#..
56...9#...#.....#
34...7...........
..2.....X....##..
..1..............
Finally, the laser completes its first full rotation (1 through 3), a second rotation (4 through 8), and vaporizes the last asteroid (9) partway through its third rotation:
......234.....6..
......1...5.....7
.................
........X....89..
.................
In the large example above (the one with the best monitoring station location at 11,13):
 The 1st asteroid to be vaporized is at 11,12.
 The 2nd asteroid to be vaporized is at 12,1.
 The 3rd asteroid to be vaporized is at 12,2.
 The 10th asteroid to be vaporized is at 12,8.
 The 20th asteroid to be vaporized is at 16,0.
 The 50th asteroid to be vaporized is at 16,9.
 The 100th asteroid to be vaporized is at 10,16.
 The 199th asteroid to be vaporized is at 9,6.
 The 200th asteroid to be vaporized is at 8,2.
 The 201st asteroid to be vaporized is at 10,9.
 The 299th and final asteroid to be vaporized is at 11,1.
The Elves are placing bets on which will be the 200th asteroid to be vaporized. Win the bet by determining which asteroid that will be; what do you get if you multiply its X coordinate by 100 and then add its Y coordinate? (For example, 8,2 becomes 802.)
Your puzzle answer was 2628.
Both parts of this puzzle are complete! They provide two gold stars: **
At this point, you should return to your Advent calendar and try another puzzle.
If you still want to see it, you can get your puzzle input.
References
Visible links
. https://adventofcode.com/
. https://adventofcode.com/2019/about
. https://adventofcode.com/2019/events
. https://adventofcode.com/2019/settings
. https://adventofcode.com/2019/auth/logout
. Advent of Code Supporter
https://adventofcode.com/2019/support
. https://adventofcode.com/2019
. https://adventofcode.com/2019
. https://adventofcode.com/2019/support
. https://adventofcode.com/2019/sponsors
. https://adventofcode.com/2019/leaderboard
. https://adventofcode.com/2019/stats
. https://adventofcode.com/2019/sponsors
. https://adventofcode.com/2019
. https://adventofcode.com/2019/day/10/input

111
2019/day11/problem Normal file
View File

@ -0,0 +1,111 @@
Advent of Code
--- Day 11: Space Police ---
On the way to Jupiter, you're pulled over by the Space Police.
"Attention, unmarked spacecraft! You are in violation of Space Law! All spacecraft must have a clearly visible registration identifier! You have 24 hours to comply or be sent to Space Jail!"
Not wanting to be sent to Space Jail, you radio back to the Elves on Earth for help. Although it takes almost three hours for their reply signal to reach you, they send instructions for how to power up the emergency hull painting robot and even provide a small Intcode program (your puzzle input) that will cause
it to paint your ship appropriately.
There's just one problem: you don't have an emergency hull painting robot.
You'll need to build a new emergency hull painting robot. The robot needs to be able to move around on the grid of square panels on the side of your ship, detect the color of its current panel, and paint its current panel black or white. (All of the panels are currently black.)
The Intcode program will serve as the brain of the robot. The program uses input instructions to access the robot's camera: provide 0 if the robot is over a black panel or 1 if the robot is over a white panel. Then, the program will output two values:
 First, it will output a value indicating the color to paint the panel the robot is over: 0 means to paint the panel black, and 1 means to paint the panel white.
 Second, it will output a value indicating the direction the robot should turn: 0 means it should turn left 90 degrees, and 1 means it should turn right 90 degrees.
After the robot turns, it should always move forward exactly one panel. The robot starts facing up.
The robot will continue running for a while like this and halt when it is finished drawing. Do not restart the Intcode computer inside the robot during this process.
For example, suppose the robot is about to start running. Drawing black panels as ., white panels as #, and the robot pointing the direction it is facing (< ^ > v), the initial state and region near the robot looks like this:
.....
.....
..^..
.....
.....
The panel under the robot (not visible here because a ^ is shown instead) is also black, and so any input instructions at this point should be provided 0. Suppose the robot eventually outputs 1 (paint white) and then 0 (turn left). After taking these actions and moving forward one panel, the region now looks
like this:
.....
.....
.<#..
.....
.....
Input instructions should still be provided 0. Next, the robot might output 0 (paint black) and then 0 (turn left):
.....
.....
..#..
.v...
.....
After more outputs (1,0, 1,0):
.....
.....
..^..
.##..
.....
The robot is now back where it started, but because it is now on a white panel, input instructions should be provided 1. After several more outputs (0,1, 1,0, 1,0), the area looks like this:
.....
..<#.
...#.
.##..
.....
Before you deploy the robot, you should probably have an estimate of the area it will cover: specifically, you need to know the number of panels it paints at least once, regardless of color. In the example above, the robot painted 6 panels at least once. (It painted its starting panel twice, but that panel is
still only counted once; it also never painted the panel it ended on.)
Build a new emergency hull painting robot and run the Intcode program on it. How many panels does it paint at least once?
Your puzzle answer was 1681.
--- Part Two ---
You're not sure what it's trying to paint, but it's definitely not a registration identifier. The Space Police are getting impatient.
Checking your external ship cameras again, you notice a white panel marked "emergency hull painting robot starting panel". The rest of the panels are still black, but it looks like the robot was expecting to start on a white panel, not a black one.
Based on the Space Law Space Brochure that the Space Police attached to one of your windows, a valid registration identifier is always eight capital letters. After starting the robot on a single white panel instead, what registration identifier does it paint on your hull?
Your puzzle answer was EGZCRKGK.
Both parts of this puzzle are complete! They provide two gold stars: **
At this point, you should return to your Advent calendar and try another puzzle.
If you still want to see it, you can get your puzzle input.
References
Visible links
. https://adventofcode.com/
. https://adventofcode.com/2019/about
. https://adventofcode.com/2019/events
. https://adventofcode.com/2019/settings
. https://adventofcode.com/2019/auth/logout
. Advent of Code Supporter
https://adventofcode.com/2019/support
. https://adventofcode.com/2019
. https://adventofcode.com/2019
. https://adventofcode.com/2019/support
. https://adventofcode.com/2019/sponsors
. https://adventofcode.com/2019/leaderboard
. https://adventofcode.com/2019/stats
. https://adventofcode.com/2019/sponsors
. https://www.youtube.com/watch?v=KwY28rpyKDE
. https://www.youtube.com/watch?v=BVn1oQL9sWg&t=5
. https://adventofcode.com/2019/day/9
. https://www.youtube.com/watch?v=KjsSvjA5TuE
. https://adventofcode.com/2019
. https://adventofcode.com/2019/day/11/input

264
2019/day12/problem Normal file
View File

@ -0,0 +1,264 @@
Advent of Code
--- Day 12: The N-Body Problem ---
The space near Jupiter is not a very safe place; you need to be careful of a big distracting red spot, extreme radiation, and a whole lot of moons swirling around. You decide to start by tracking the four largest moons: Io, Europa, Ganymede, and Callisto.
After a brief scan, you calculate the position of each moon (your puzzle input). You just need to simulate their motion so you can avoid them.
Each moon has a 3-dimensional position (x, y, and z) and a 3-dimensional velocity. The position of each moon is given in your scan; the x, y, and z velocity of each moon starts at 0.
Simulate the motion of the moons in time steps. Within each time step, first update the velocity of every moon by applying gravity. Then, once all moons' velocities have been updated, update the position of every moon by applying velocity. Time progresses by one step once all of the positions are updated.
To apply gravity, consider every pair of moons. On each axis (x, y, and z), the velocity of each moon changes by exactly +1 or -1 to pull the moons together. For example, if Ganymede has an x position of 3, and Callisto has a x position of 5, then Ganymede's x velocity changes by +1 (because 5 > 3) and
Callisto's x velocity changes by -1 (because 3 < 5). However, if the positions on a given axis are the same, the velocity on that axis does not change for that pair of moons.
Once all gravity has been applied, apply velocity: simply add the velocity of each moon to its own position. For example, if Europa has a position of x=1, y=2, z=3 and a velocity of x=-2, y=0,z=3, then its new position would be x=-1, y=2, z=6. This process does not modify the velocity of any moon.
For example, suppose your scan reveals the following positions:
<x=-1, y=0, z=2>
<x=2, y=-10, z=-7>
<x=4, y=-8, z=8>
<x=3, y=5, z=-1>
Simulating the motion of these moons would produce the following:
After 0 steps:
pos=<x=-1, y= 0, z= 2>, vel=<x= 0, y= 0, z= 0>
pos=<x= 2, y=-10, z=-7>, vel=<x= 0, y= 0, z= 0>
pos=<x= 4, y= -8, z= 8>, vel=<x= 0, y= 0, z= 0>
pos=<x= 3, y= 5, z=-1>, vel=<x= 0, y= 0, z= 0>
After 1 step:
pos=<x= 2, y=-1, z= 1>, vel=<x= 3, y=-1, z=-1>
pos=<x= 3, y=-7, z=-4>, vel=<x= 1, y= 3, z= 3>
pos=<x= 1, y=-7, z= 5>, vel=<x=-3, y= 1, z=-3>
pos=<x= 2, y= 2, z= 0>, vel=<x=-1, y=-3, z= 1>
After 2 steps:
pos=<x= 5, y=-3, z=-1>, vel=<x= 3, y=-2, z=-2>
pos=<x= 1, y=-2, z= 2>, vel=<x=-2, y= 5, z= 6>
pos=<x= 1, y=-4, z=-1>, vel=<x= 0, y= 3, z=-6>
pos=<x= 1, y=-4, z= 2>, vel=<x=-1, y=-6, z= 2>
After 3 steps:
pos=<x= 5, y=-6, z=-1>, vel=<x= 0, y=-3, z= 0>
pos=<x= 0, y= 0, z= 6>, vel=<x=-1, y= 2, z= 4>
pos=<x= 2, y= 1, z=-5>, vel=<x= 1, y= 5, z=-4>
pos=<x= 1, y=-8, z= 2>, vel=<x= 0, y=-4, z= 0>
After 4 steps:
pos=<x= 2, y=-8, z= 0>, vel=<x=-3, y=-2, z= 1>
pos=<x= 2, y= 1, z= 7>, vel=<x= 2, y= 1, z= 1>
pos=<x= 2, y= 3, z=-6>, vel=<x= 0, y= 2, z=-1>
pos=<x= 2, y=-9, z= 1>, vel=<x= 1, y=-1, z=-1>
After 5 steps:
pos=<x=-1, y=-9, z= 2>, vel=<x=-3, y=-1, z= 2>
pos=<x= 4, y= 1, z= 5>, vel=<x= 2, y= 0, z=-2>
pos=<x= 2, y= 2, z=-4>, vel=<x= 0, y=-1, z= 2>
pos=<x= 3, y=-7, z=-1>, vel=<x= 1, y= 2, z=-2>
After 6 steps:
pos=<x=-1, y=-7, z= 3>, vel=<x= 0, y= 2, z= 1>
pos=<x= 3, y= 0, z= 0>, vel=<x=-1, y=-1, z=-5>
pos=<x= 3, y=-2, z= 1>, vel=<x= 1, y=-4, z= 5>
pos=<x= 3, y=-4, z=-2>, vel=<x= 0, y= 3, z=-1>
After 7 steps:
pos=<x= 2, y=-2, z= 1>, vel=<x= 3, y= 5, z=-2>
pos=<x= 1, y=-4, z=-4>, vel=<x=-2, y=-4, z=-4>
pos=<x= 3, y=-7, z= 5>, vel=<x= 0, y=-5, z= 4>
pos=<x= 2, y= 0, z= 0>, vel=<x=-1, y= 4, z= 2>
After 8 steps:
pos=<x= 5, y= 2, z=-2>, vel=<x= 3, y= 4, z=-3>
pos=<x= 2, y=-7, z=-5>, vel=<x= 1, y=-3, z=-1>
pos=<x= 0, y=-9, z= 6>, vel=<x=-3, y=-2, z= 1>
pos=<x= 1, y= 1, z= 3>, vel=<x=-1, y= 1, z= 3>
After 9 steps:
pos=<x= 5, y= 3, z=-4>, vel=<x= 0, y= 1, z=-2>
pos=<x= 2, y=-9, z=-3>, vel=<x= 0, y=-2, z= 2>
pos=<x= 0, y=-8, z= 4>, vel=<x= 0, y= 1, z=-2>
pos=<x= 1, y= 1, z= 5>, vel=<x= 0, y= 0, z= 2>
After 10 steps:
pos=<x= 2, y= 1, z=-3>, vel=<x=-3, y=-2, z= 1>
pos=<x= 1, y=-8, z= 0>, vel=<x=-1, y= 1, z= 3>
pos=<x= 3, y=-6, z= 1>, vel=<x= 3, y= 2, z=-3>
pos=<x= 2, y= 0, z= 4>, vel=<x= 1, y=-1, z=-1>
Then, it might help to calculate the total energy in the system. The total energy for a single moon is its potential energy multiplied by its kinetic energy. A moon's potential energy is the sum of the absolute values of its x, y, and z position coordinates. A moon's kinetic energy is the sum of the absolute
values of its velocity coordinates. Below, each line shows the calculations for a moon's potential energy (pot), kinetic energy (kin), and total energy:
Energy after 10 steps:
pot: 2 + 1 + 3 = 6; kin: 3 + 2 + 1 = 6; total: 6 * 6 = 36
pot: 1 + 8 + 0 = 9; kin: 1 + 1 + 3 = 5; total: 9 * 5 = 45
pot: 3 + 6 + 1 = 10; kin: 3 + 2 + 3 = 8; total: 10 * 8 = 80
pot: 2 + 0 + 4 = 6; kin: 1 + 1 + 1 = 3; total: 6 * 3 = 18
Sum of total energy: 36 + 45 + 80 + 18 = 179
In the above example, adding together the total energy for all moons after 10 steps produces the total energy in the system, 179.
Here's a second example:
<x=-8, y=-10, z=0>
<x=5, y=5, z=10>
<x=2, y=-7, z=3>
<x=9, y=-8, z=-3>
Every ten steps of simulation for 100 steps produces:
After 0 steps:
pos=<x= -8, y=-10, z= 0>, vel=<x= 0, y= 0, z= 0>
pos=<x= 5, y= 5, z= 10>, vel=<x= 0, y= 0, z= 0>
pos=<x= 2, y= -7, z= 3>, vel=<x= 0, y= 0, z= 0>
pos=<x= 9, y= -8, z= -3>, vel=<x= 0, y= 0, z= 0>
After 10 steps:
pos=<x= -9, y=-10, z= 1>, vel=<x= -2, y= -2, z= -1>
pos=<x= 4, y= 10, z= 9>, vel=<x= -3, y= 7, z= -2>
pos=<x= 8, y=-10, z= -3>, vel=<x= 5, y= -1, z= -2>
pos=<x= 5, y=-10, z= 3>, vel=<x= 0, y= -4, z= 5>
After 20 steps:
pos=<x=-10, y= 3, z= -4>, vel=<x= -5, y= 2, z= 0>
pos=<x= 5, y=-25, z= 6>, vel=<x= 1, y= 1, z= -4>
pos=<x= 13, y= 1, z= 1>, vel=<x= 5, y= -2, z= 2>
pos=<x= 0, y= 1, z= 7>, vel=<x= -1, y= -1, z= 2>
After 30 steps:
pos=<x= 15, y= -6, z= -9>, vel=<x= -5, y= 4, z= 0>
pos=<x= -4, y=-11, z= 3>, vel=<x= -3, y=-10, z= 0>
pos=<x= 0, y= -1, z= 11>, vel=<x= 7, y= 4, z= 3>
pos=<x= -3, y= -2, z= 5>, vel=<x= 1, y= 2, z= -3>
After 40 steps:
pos=<x= 14, y=-12, z= -4>, vel=<x= 11, y= 3, z= 0>
pos=<x= -1, y= 18, z= 8>, vel=<x= -5, y= 2, z= 3>
pos=<x= -5, y=-14, z= 8>, vel=<x= 1, y= -2, z= 0>
pos=<x= 0, y=-12, z= -2>, vel=<x= -7, y= -3, z= -3>
After 50 steps:
pos=<x=-23, y= 4, z= 1>, vel=<x= -7, y= -1, z= 2>
pos=<x= 20, y=-31, z= 13>, vel=<x= 5, y= 3, z= 4>
pos=<x= -4, y= 6, z= 1>, vel=<x= -1, y= 1, z= -3>
pos=<x= 15, y= 1, z= -5>, vel=<x= 3, y= -3, z= -3>
After 60 steps:
pos=<x= 36, y=-10, z= 6>, vel=<x= 5, y= 0, z= 3>
pos=<x=-18, y= 10, z= 9>, vel=<x= -3, y= -7, z= 5>
pos=<x= 8, y=-12, z= -3>, vel=<x= -2, y= 1, z= -7>
pos=<x=-18, y= -8, z= -2>, vel=<x= 0, y= 6, z= -1>
After 70 steps:
pos=<x=-33, y= -6, z= 5>, vel=<x= -5, y= -4, z= 7>
pos=<x= 13, y= -9, z= 2>, vel=<x= -2, y= 11, z= 3>
pos=<x= 11, y= -8, z= 2>, vel=<x= 8, y= -6, z= -7>
pos=<x= 17, y= 3, z= 1>, vel=<x= -1, y= -1, z= -3>
After 80 steps:
pos=<x= 30, y= -8, z= 3>, vel=<x= 3, y= 3, z= 0>
pos=<x= -2, y= -4, z= 0>, vel=<x= 4, y=-13, z= 2>
pos=<x=-18, y= -7, z= 15>, vel=<x= -8, y= 2, z= -2>
pos=<x= -2, y= -1, z= -8>, vel=<x= 1, y= 8, z= 0>
After 90 steps:
pos=<x=-25, y= -1, z= 4>, vel=<x= 1, y= -3, z= 4>
pos=<x= 2, y= -9, z= 0>, vel=<x= -3, y= 13, z= -1>
pos=<x= 32, y= -8, z= 14>, vel=<x= 5, y= -4, z= 6>
pos=<x= -1, y= -2, z= -8>, vel=<x= -3, y= -6, z= -9>
After 100 steps:
pos=<x= 8, y=-12, z= -9>, vel=<x= -7, y= 3, z= 0>
pos=<x= 13, y= 16, z= -3>, vel=<x= 3, y=-11, z= -5>
pos=<x=-29, y=-11, z= -1>, vel=<x= -3, y= 7, z= 4>
pos=<x= 16, y=-13, z= 23>, vel=<x= 7, y= 1, z= 1>
Energy after 100 steps:
pot: 8 + 12 + 9 = 29; kin: 7 + 3 + 0 = 10; total: 29 * 10 = 290
pot: 13 + 16 + 3 = 32; kin: 3 + 11 + 5 = 19; total: 32 * 19 = 608
pot: 29 + 11 + 1 = 41; kin: 3 + 7 + 4 = 14; total: 41 * 14 = 574
pot: 16 + 13 + 23 = 52; kin: 7 + 1 + 1 = 9; total: 52 * 9 = 468
Sum of total energy: 290 + 608 + 574 + 468 = 1940
What is the total energy in the system after simulating the moons given in your scan for 1000 steps?
Your puzzle answer was 6735.
--- Part Two ---
All this drifting around in space makes you wonder about the nature of the universe. Does history really repeat itself? You're curious whether the moons will ever return to a previous state.
Determine the number of steps that must occur before all of the moons' positions and velocities exactly match a previous point in time.
For example, the first example above takes 2772 steps before they exactly match a previous point in time; it eventually returns to the initial state:
After 0 steps:
pos=<x= -1, y= 0, z= 2>, vel=<x= 0, y= 0, z= 0>
pos=<x= 2, y=-10, z= -7>, vel=<x= 0, y= 0, z= 0>
pos=<x= 4, y= -8, z= 8>, vel=<x= 0, y= 0, z= 0>
pos=<x= 3, y= 5, z= -1>, vel=<x= 0, y= 0, z= 0>
After 2770 steps:
pos=<x= 2, y= -1, z= 1>, vel=<x= -3, y= 2, z= 2>
pos=<x= 3, y= -7, z= -4>, vel=<x= 2, y= -5, z= -6>
pos=<x= 1, y= -7, z= 5>, vel=<x= 0, y= -3, z= 6>
pos=<x= 2, y= 2, z= 0>, vel=<x= 1, y= 6, z= -2>
After 2771 steps:
pos=<x= -1, y= 0, z= 2>, vel=<x= -3, y= 1, z= 1>
pos=<x= 2, y=-10, z= -7>, vel=<x= -1, y= -3, z= -3>
pos=<x= 4, y= -8, z= 8>, vel=<x= 3, y= -1, z= 3>
pos=<x= 3, y= 5, z= -1>, vel=<x= 1, y= 3, z= -1>
After 2772 steps:
pos=<x= -1, y= 0, z= 2>, vel=<x= 0, y= 0, z= 0>
pos=<x= 2, y=-10, z= -7>, vel=<x= 0, y= 0, z= 0>
pos=<x= 4, y= -8, z= 8>, vel=<x= 0, y= 0, z= 0>
pos=<x= 3, y= 5, z= -1>, vel=<x= 0, y= 0, z= 0>
Of course, the universe might last for a very long time before repeating. Here's a copy of the second example from above:
<x=-8, y=-10, z=0>
<x=5, y=5, z=10>
<x=2, y=-7, z=3>
<x=9, y=-8, z=-3>
This set of initial positions takes 4686774924 steps before it repeats a previous state! Clearly, you might need to find a more efficient way to simulate the universe.
How many steps does it take to reach the first state that exactly matches a previous state?
Your puzzle answer was 326489627728984.
Both parts of this puzzle are complete! They provide two gold stars: **
At this point, you should return to your Advent calendar and try another puzzle.
If you still want to see it, you can get your puzzle input.
References
Visible links
. https://adventofcode.com/
. https://adventofcode.com/2019/about
. https://adventofcode.com/2019/events
. https://adventofcode.com/2019/settings
. https://adventofcode.com/2019/auth/logout
. Advent of Code Supporter
https://adventofcode.com/2019/support
. https://adventofcode.com/2019
. https://adventofcode.com/2019
. https://adventofcode.com/2019/support
. https://adventofcode.com/2019/sponsors
. https://adventofcode.com/2019/leaderboard
. https://adventofcode.com/2019/stats
. https://adventofcode.com/2019/sponsors
. https://en.wikipedia.org/wiki/Great_Red_Spot
. https://en.wikipedia.org/wiki/Magnetosphere_of_Jupiter
. https://en.wikipedia.org/wiki/Moons_of_Jupiter#List
. https://en.wikipedia.org/wiki/Absolute_value
. https://adventofcode.com/2019
. https://adventofcode.com/2019/day/12/input