115 changed files with 14665 additions and 0 deletions
@ -0,0 +1,310 @@ |
|||
>--- Day 25: Sea Cucumber --- |
|||
|
|||
This is it: the bottom of the ocean trench, the last place the sleigh keys could be. Your submarine's experimental antenna still isn't boosted enough to detect the keys, but they must be here. All you need to do is reach the seafloor and find them. |
|||
|
|||
At least, you'd touch down on the seafloor if you could; unfortunately, it's completely covered by two large herds of sea cucumbers, and there isn't an open space large enough for your submarine. |
|||
|
|||
You suspect that the Elves must have done this before, because just then you discover the phone number of a deep-sea marine biologist on a handwritten note taped to the wall of the submarine's cockpit. |
|||
|
|||
"Sea cucumbers? Yeah, they're probably hunting for food. But don't worry, they're predictable critters: they move in perfectly straight lines, only moving forward when there's space to do so. They're actually quite polite!" |
|||
|
|||
You explain that you'd like to predict when you could land your submarine. |
|||
|
|||
"Oh that's easy, they'll eventually pile up and leave enough space for-- wait, did you say submarine? And the only place with that many sea cucumbers would be at the very bottom of the Mariana--" You hang up the phone. |
|||
|
|||
There are two herds of sea cucumbers sharing the same region; one always moves east (>), while the other always moves south (v). Each location can contain at most one sea cucumber; the remaining locations are empty (.). The submarine helpfully generates a map of the situation (your puzzle input). For example: |
|||
|
|||
v...>>.vv> |
|||
.vv>>.vv.. |
|||
>>.>v>...v |
|||
>>v>>.>.v. |
|||
v>v.vv.v.. |
|||
>.>>..v... |
|||
.vv..>.>v. |
|||
v.v..>>v.v |
|||
....v..v.> |
|||
|
|||
Every step, the sea cucumbers in the east-facing herd attempt to move forward one location, then the sea cucumbers in the south-facing herd attempt to move forward one location. When a herd moves forward, every sea cucumber in the herd first simultaneously considers whether there is a sea cucumber in the adjacent location it's facing (even another sea cucumber facing the same direction), and then every sea cucumber facing an empty location simultaneously moves into that location. |
|||
|
|||
So, in a situation like this: |
|||
|
|||
...>>>>>... |
|||
|
|||
After one step, only the rightmost sea cucumber would have moved: |
|||
|
|||
...>>>>.>.. |
|||
|
|||
After the next step, two sea cucumbers move: |
|||
|
|||
...>>>.>.>. |
|||
|
|||
During a single step, the east-facing herd moves first, then the south-facing herd moves. So, given this situation: |
|||
|
|||
.......... |
|||
.>v....v.. |
|||
.......>.. |
|||
.......... |
|||
|
|||
After a single step, of the sea cucumbers on the left, only the south-facing sea cucumber has moved (as it wasn't out of the way in time for the east-facing cucumber on the left to move), but both sea cucumbers on the right have moved (as the east-facing sea cucumber moved out of the way of the south-facing sea cucumber): |
|||
|
|||
.......... |
|||
.>........ |
|||
..v....v>. |
|||
.......... |
|||
|
|||
Due to strong water currents in the area, sea cucumbers that move off the right edge of the map appear on the left edge, and sea cucumbers that move off the bottom edge of the map appear on the top edge. Sea cucumbers always check whether their destination location is empty before moving, even if that destination is on the opposite side of the map: |
|||
|
|||
Initial state: |
|||
...>... |
|||
....... |
|||
......> |
|||
v.....> |
|||
......> |
|||
....... |
|||
..vvv.. |
|||
|
|||
After 1 step: |
|||
..vv>.. |
|||
....... |
|||
>...... |
|||
v.....> |
|||
>...... |
|||
....... |
|||
....v.. |
|||
|
|||
After 2 steps: |
|||
....v>. |
|||
..vv... |
|||
.>..... |
|||
......> |
|||
v>..... |
|||
....... |
|||
....... |
|||
|
|||
After 3 steps: |
|||
......> |
|||
..v.v.. |
|||
..>v... |
|||
>...... |
|||
..>.... |
|||
v...... |
|||
....... |
|||
|
|||
After 4 steps: |
|||
>...... |
|||
..v.... |
|||
..>.v.. |
|||
.>.v... |
|||
...>... |
|||
....... |
|||
v...... |
|||
|
|||
To find a safe place to land your submarine, the sea cucumbers need to stop moving. Again consider the first example: |
|||
|
|||
Initial state: |
|||
v...>>.vv> |
|||
.vv>>.vv.. |
|||
>>.>v>...v |
|||
>>v>>.>.v. |
|||
v>v.vv.v.. |
|||
>.>>..v... |
|||
.vv..>.>v. |
|||
v.v..>>v.v |
|||
....v..v.> |
|||
|
|||
After 1 step: |
|||
....>.>v.> |
|||
v.v>.>v.v. |
|||
>v>>..>v.. |
|||
>>v>v>.>.v |
|||
.>v.v...v. |
|||
v>>.>vvv.. |
|||
..v...>>.. |
|||
vv...>>vv. |
|||
>.v.v..v.v |
|||
|
|||
After 2 steps: |
|||
>.v.v>>..v |
|||
v.v.>>vv.. |
|||
>v>.>.>.v. |
|||
>>v>v.>v>. |
|||
.>..v....v |
|||
.>v>>.v.v. |
|||
v....v>v>. |
|||
.vv..>>v.. |
|||
v>.....vv. |
|||
|
|||
After 3 steps: |
|||
v>v.v>.>v. |
|||
v...>>.v.v |
|||
>vv>.>v>.. |
|||
>>v>v.>.v> |
|||
..>....v.. |
|||
.>.>v>v..v |
|||
..v..v>vv> |
|||
v.v..>>v.. |
|||
.v>....v.. |
|||
|
|||
After 4 steps: |
|||
v>..v.>>.. |
|||
v.v.>.>.v. |
|||
>vv.>>.v>v |
|||
>>.>..v>.> |
|||
..v>v...v. |
|||
..>>.>vv.. |
|||
>.v.vv>v.v |
|||
.....>>vv. |
|||
vvv>...v.. |
|||
|
|||
After 5 steps: |
|||
vv>...>v>. |
|||
v.v.v>.>v. |
|||
>.v.>.>.>v |
|||
>v>.>..v>> |
|||
..v>v.v... |
|||
..>.>>vvv. |
|||
.>...v>v.. |
|||
..v.v>>v.v |
|||
v.v.>...v. |
|||
|
|||
... |
|||
|
|||
After 10 steps: |
|||
..>..>>vv. |
|||
v.....>>.v |
|||
..v.v>>>v> |
|||
v>.>v.>>>. |
|||
..v>v.vv.v |
|||
.v.>>>.v.. |
|||
v.v..>v>.. |
|||
..v...>v.> |
|||
.vv..v>vv. |
|||
|
|||
... |
|||
|
|||
After 20 steps: |
|||
v>.....>>. |
|||
>vv>.....v |
|||
.>v>v.vv>> |
|||
v>>>v.>v.> |
|||
....vv>v.. |
|||
.v.>>>vvv. |
|||
..v..>>vv. |
|||
v.v...>>.v |
|||
..v.....v> |
|||
|
|||
... |
|||
|
|||
After 30 steps: |
|||
.vv.v..>>> |
|||
v>...v...> |
|||
>.v>.>vv.> |
|||
>v>.>.>v.> |
|||
.>..v.vv.. |
|||
..v>..>>v. |
|||
....v>..>v |
|||
v.v...>vv> |
|||
v.v...>vvv |
|||
|
|||
... |
|||
|
|||
After 40 steps: |
|||
>>v>v..v.. |
|||
..>>v..vv. |
|||
..>>>v.>.v |
|||
..>>>>vvv> |
|||
v.....>... |
|||
v.v...>v>> |
|||
>vv.....v> |
|||
.>v...v.>v |
|||
vvv.v..v.> |
|||
|
|||
... |
|||
|
|||
After 50 steps: |
|||
..>>v>vv.v |
|||
..v.>>vv.. |
|||
v.>>v>>v.. |
|||
..>>>>>vv. |
|||
vvv....>vv |
|||
..v....>>> |
|||
v>.......> |
|||
.vv>....v> |
|||
.>v.vv.v.. |
|||
|
|||
... |
|||
|
|||
After 55 steps: |
|||
..>>v>vv.. |
|||
..v.>>vv.. |
|||
..>>v>>vv. |
|||
..>>>>>vv. |
|||
v......>vv |
|||
v>v....>>v |
|||
vvv...>..> |
|||
>vv.....>. |
|||
.>v.vv.v.. |
|||
|
|||
After 56 steps: |
|||
..>>v>vv.. |
|||
..v.>>vv.. |
|||
..>>v>>vv. |
|||
..>>>>>vv. |
|||
v......>vv |
|||
v>v....>>v |
|||
vvv....>.> |
|||
>vv......> |
|||
.>v.vv.v.. |
|||
|
|||
After 57 steps: |
|||
..>>v>vv.. |
|||
..v.>>vv.. |
|||
..>>v>>vv. |
|||
..>>>>>vv. |
|||
v......>vv |
|||
v>v....>>v |
|||
vvv.....>> |
|||
>vv......> |
|||
.>v.vv.v.. |
|||
|
|||
After 58 steps: |
|||
..>>v>vv.. |
|||
..v.>>vv.. |
|||
..>>v>>vv. |
|||
..>>>>>vv. |
|||
v......>vv |
|||
v>v....>>v |
|||
vvv.....>> |
|||
>vv......> |
|||
.>v.vv.v.. |
|||
|
|||
In this example, the sea cucumbers stop moving after 58 steps. |
|||
|
|||
Find somewhere safe to land your submarine. What is the first step on which no sea cucumbers move? |
|||
|
|||
Your puzzle answer was 520. |
|||
--- Part Two --- |
|||
|
|||
Suddenly, the experimental antenna control console lights up: |
|||
|
|||
Sleigh keys detected! |
|||
|
|||
According to the console, the keys are directly under the submarine. You landed right on them! Using a robotic arm on the submarine, you move the sleigh keys into the airlock. |
|||
|
|||
Now, you just need to get them to Santa in time to save Christmas! You check your clock - it is Christmas. There's no way you can get them back to the surface in time. |
|||
|
|||
Just as you start to lose hope, you notice a button on the sleigh keys: remote start. You can start the sleigh from the bottom of the ocean! You just need some way to boost the signal from the keys so it actually reaches the sleigh. Good thing the submarine has that experimental antenna! You'll definitely need 50 stars to boost it that far, though. |
|||
|
|||
The experimental antenna control console lights up again: |
|||
|
|||
Energy source detected. |
|||
Integrating energy source from device "sleigh keys"...done. |
|||
Installing device drivers...done. |
|||
Recalibrating experimental antenna...done. |
|||
Boost strength due to matching signal phase: 1 star |
|||
|
|||
Only 49 stars to go. |
|||
|
|||
If you like, you can [Remotely Start The Sleigh Again]. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
@ -0,0 +1,47 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys |
|||
from copy import deepcopy |
|||
|
|||
def cprint(cucs): |
|||
for l in cucs: |
|||
print(''.join(l)) |
|||
print('\n') |
|||
|
|||
def step(cucs): |
|||
nc = deepcopy(cucs) |
|||
for y,l in enumerate(cucs): |
|||
for x,c in enumerate(l): |
|||
if c == '>': |
|||
if cucs[y][(x+1)%len(l)] == '.': |
|||
nc[y][x] = '.' |
|||
nc[y][(x+1)%len(l)] = '>' |
|||
cucs = deepcopy(nc) |
|||
for y,l in enumerate(cucs): |
|||
for x,c in enumerate(l): |
|||
if c == 'v': |
|||
if cucs[(y+1)%len(cucs)][x] == '.': |
|||
nc[y][x] = '.' |
|||
nc[(y+1)%len(cucs)][x] = 'v' |
|||
return nc |
|||
|
|||
if __name__ == '__main__': |
|||
cucs = [list(line.strip('\n')) for line in open(sys.argv[1])] |
|||
|
|||
# challenge 1 |
|||
nc = [] |
|||
i = 0 |
|||
while nc != cucs: |
|||
print(i) |
|||
i += 1 |
|||
cprint(nc) |
|||
cucs = deepcopy(nc) if nc != [] else cucs |
|||
nc = step(cucs) |
|||
|
|||
res1 = str(i) |
|||
print("challenge 1:" + "\n" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
res2 = "doesn't exist :)" |
|||
print("challenge 2:" + "\n" + res2 + "\n") |
|||
|
@ -0,0 +1,35 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys |
|||
|
|||
if __name__ == '__main__': |
|||
measurements = open(sys.argv[1]).read().strip('\n\n').split('\n') |
|||
meas = [int(i) for i in measurements] |
|||
|
|||
# challenge 1 |
|||
incr = 0 |
|||
last = 0 |
|||
for i in meas: |
|||
if i > last: |
|||
incr += 1 |
|||
last = i |
|||
res1 = str(incr - 1) |
|||
print("challenge 1: " + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
incr = 0 |
|||
first = meas[0] |
|||
second = meas[1] |
|||
third = meas[2] |
|||
last = first + second + third |
|||
for i in meas[3:]: |
|||
first = second |
|||
second = third |
|||
third = i |
|||
nex = first + second + third |
|||
if nex > last: |
|||
incr += 1 |
|||
last = nex |
|||
res2 = str(incr) |
|||
print("challenge 2: " + res2 + "\n") |
|||
|
@ -0,0 +1,86 @@ |
|||
--- Day 1: Sonar Sweep --- |
|||
|
|||
You're minding your own business on a ship at sea when the overboard alarm goes off! You rush to see if you can help. Apparently, one of the Elves tripped and accidentally sent the sleigh keys flying into the ocean! |
|||
|
|||
Before you know it, you're inside a submarine the Elves keep ready for situations like this. It's covered in Christmas lights (because of course it is), and it even has an experimental antenna that should be able to track the keys if you can boost its signal strength high enough; there's a little meter that indicates the antenna's signal strength by displaying 0-50 stars. |
|||
|
|||
Your instincts tell you that in order to save Christmas, you'll need to get all fifty stars by December 25th. |
|||
|
|||
Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck! |
|||
|
|||
As the submarine drops below the surface of the ocean, it automatically performs a sonar sweep of the nearby sea floor. On a small screen, the sonar sweep report (your puzzle input) appears: each line is a measurement of the sea floor depth as the sweep looks further and further away from the submarine. |
|||
|
|||
For example, suppose you had the following report: |
|||
|
|||
199 |
|||
200 |
|||
208 |
|||
210 |
|||
200 |
|||
207 |
|||
240 |
|||
269 |
|||
260 |
|||
263 |
|||
|
|||
This report indicates that, scanning outward from the submarine, the sonar sweep found depths of 199, 200, 208, 210, and so on. |
|||
|
|||
The first order of business is to figure out how quickly the depth increases, just so you know what you're dealing with - you never know if the keys will get carried into deeper water by an ocean current or a fish or something. |
|||
|
|||
To do this, count the number of times a depth measurement increases from the previous measurement. (There is no measurement before the first measurement.) In the example above, the changes are as follows: |
|||
|
|||
199 (N/A - no previous measurement) |
|||
200 (increased) |
|||
208 (increased) |
|||
210 (increased) |
|||
200 (decreased) |
|||
207 (increased) |
|||
240 (increased) |
|||
269 (increased) |
|||
260 (decreased) |
|||
263 (increased) |
|||
|
|||
In this example, there are 7 measurements that are larger than the previous measurement. |
|||
|
|||
How many measurements are larger than the previous measurement? |
|||
|
|||
Your puzzle answer was 1400. |
|||
--- Part Two --- |
|||
|
|||
Considering every single measurement isn't as useful as you expected: there's just too much noise in the data. |
|||
|
|||
Instead, consider sums of a three-measurement sliding window. Again considering the above example: |
|||
|
|||
199 A |
|||
200 A B |
|||
208 A B C |
|||
210 B C D |
|||
200 E C D |
|||
207 E F D |
|||
240 E F G |
|||
269 F G H |
|||
260 G H |
|||
263 H |
|||
|
|||
Start by comparing the first and second three-measurement windows. The measurements in the first window are marked A (199, 200, 208); their sum is 199 + 200 + 208 = 607. The second window is marked B (200, 208, 210); its sum is 618. The sum of measurements in the second window is larger than the sum of the first, so this first comparison increased. |
|||
|
|||
Your goal now is to count the number of times the sum of measurements in this sliding window increases from the previous sum. So, compare A with B, then compare B with C, then C with D, and so on. Stop when there aren't enough measurements left to create a new three-measurement sum. |
|||
|
|||
In the above example, the sum of each three-measurement window is as follows: |
|||
|
|||
A: 607 (N/A - no previous sum) |
|||
B: 618 (increased) |
|||
C: 618 (no change) |
|||
D: 617 (decreased) |
|||
E: 647 (increased) |
|||
F: 716 (increased) |
|||
G: 769 (increased) |
|||
H: 792 (increased) |
|||
|
|||
In this example, there are 5 sums that are larger than the previous sum. |
|||
|
|||
Consider sums of a three-measurement sliding window. How many sums are larger than the previous sum? |
|||
|
|||
Your puzzle answer was 1429. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
File diff suppressed because it is too large
@ -0,0 +1,44 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys |
|||
|
|||
|
|||
if __name__ == '__main__': |
|||
lines = open(sys.argv[1]).readlines() |
|||
dirs = [i.strip('\n').split(" ") for i in lines] |
|||
|
|||
# challenge 1 |
|||
dep = 0 |
|||
pos = 0 |
|||
|
|||
for d in dirs: |
|||
if d[0] == 'forward': |
|||
pos += int(d[1]) |
|||
elif d[0] == 'up': |
|||
dep -= int(d[1]) |
|||
elif d[0] == 'down': |
|||
dep += int(d[1]) |
|||
else: |
|||
print(d) |
|||
|
|||
res1 = str(dep * pos) |
|||
print("challenge 1:" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
dep = 0 |
|||
pos = 0 |
|||
aim = 0 |
|||
|
|||
for d in dirs: |
|||
if d[0] == 'forward': |
|||
pos += int(d[1]) |
|||
dep += int(d[1]) * aim |
|||
elif d[0] == 'up': |
|||
aim -= int(d[1]) |
|||
elif d[0] == 'down': |
|||
aim += int(d[1]) |
|||
else: |
|||
print(d) |
|||
res2 = str(dep * pos) |
|||
print("challenge 2:" + res2 + "\n") |
|||
|
@ -0,0 +1,65 @@ |
|||
--- Day 2: Dive! --- |
|||
|
|||
Now, you need to figure out how to pilot this thing. |
|||
|
|||
It seems like the submarine can take a series of commands like forward 1, down 2, or up 3: |
|||
|
|||
forward X increases the horizontal position by X units. |
|||
down X increases the depth by X units. |
|||
up X decreases the depth by X units. |
|||
|
|||
Note that since you're on a submarine, down and up affect your depth, and so they have the opposite result of what you might expect. |
|||
|
|||
The submarine seems to already have a planned course (your puzzle input). You should probably figure out where it's going. For example: |
|||
|
|||
forward 5 |
|||
down 5 |
|||
forward 8 |
|||
up 3 |
|||
down 8 |
|||
forward 2 |
|||
|
|||
Your horizontal position and depth both start at 0. The steps above would then modify them as follows: |
|||
|
|||
forward 5 adds 5 to your horizontal position, a total of 5. |
|||
down 5 adds 5 to your depth, resulting in a value of 5. |
|||
forward 8 adds 8 to your horizontal position, a total of 13. |
|||
up 3 decreases your depth by 3, resulting in a value of 2. |
|||
down 8 adds 8 to your depth, resulting in a value of 10. |
|||
forward 2 adds 2 to your horizontal position, a total of 15. |
|||
|
|||
After following these instructions, you would have a horizontal position of 15 and a depth of 10. (Multiplying these together produces 150.) |
|||
|
|||
Calculate the horizontal position and depth you would have after following the planned course. What do you get if you multiply your final horizontal position by your final depth? |
|||
|
|||
Your puzzle answer was 1648020. |
|||
--- Part Two --- |
|||
|
|||
Based on your calculations, the planned course doesn't seem to make any sense. You find the submarine manual and discover that the process is actually slightly more complicated. |
|||
|
|||
In addition to horizontal position and depth, you'll also need to track a third value, aim, which also starts at 0. The commands also mean something entirely different than you first thought: |
|||
|
|||
down X increases your aim by X units. |
|||
up X decreases your aim by X units. |
|||
forward X does two things: |
|||
It increases your horizontal position by X units. |
|||
It increases your depth by your aim multiplied by X. |
|||
|
|||
Again note that since you're on a submarine, down and up do the opposite of what you might expect: "down" means aiming in the positive direction. |
|||
|
|||
Now, the above example does something different: |
|||
|
|||
forward 5 adds 5 to your horizontal position, a total of 5. Because your aim is 0, your depth does not change. |
|||
down 5 adds 5 to your aim, resulting in a value of 5. |
|||
forward 8 adds 8 to your horizontal position, a total of 13. Because your aim is 5, your depth increases by 8*5=40. |
|||
up 3 decreases your aim by 3, resulting in a value of 2. |
|||
down 8 adds 8 to your aim, resulting in a value of 10. |
|||
forward 2 adds 2 to your horizontal position, a total of 15. Because your aim is 10, your depth increases by 2*10=20 to a total of 60. |
|||
|
|||
After following these new instructions, you would have a horizontal position of 15 and a depth of 60. (Multiplying these produces 900.) |
|||
|
|||
Using this new interpretation of the commands, calculate the horizontal position and depth you would have after following the planned course. What do you get if you multiply your final horizontal position by your final depth? |
|||
|
|||
Your puzzle answer was 1759818555. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
File diff suppressed because it is too large
@ -0,0 +1,62 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys |
|||
|
|||
def inverted(i): |
|||
if i == 0: |
|||
return 1 |
|||
else: |
|||
return 0 |
|||
|
|||
def filter(lis, pos, i): |
|||
if len(lis) == 1: |
|||
return lis |
|||
if sum([b[pos] for b in lis]) >= sum([inverted(b[pos]) for b in lis]): |
|||
val = i |
|||
else: |
|||
val = inverted(i) |
|||
|
|||
return [i for i in lis if i[pos] == val] |
|||
|
|||
if __name__ == '__main__': |
|||
lines = open(sys.argv[1]).readlines() |
|||
|
|||
bins = [[int(i) for i in list(l.strip('\n'))] for l in lines] |
|||
|
|||
# challenge 1 |
|||
lis = [0] * len(bins[0]) |
|||
|
|||
for i in range(len(bins[0])): |
|||
lis[i] = sum([b[i] for b in bins]) |
|||
|
|||
g = '' |
|||
e = '' |
|||
|
|||
for i in range(len(bins[0])): |
|||
if lis[i] > 0.5 * len(lines): |
|||
g += '1' |
|||
e += '0' |
|||
else: |
|||
g += '0' |
|||
e += '1' |
|||
|
|||
gamma = int(g, 2) |
|||
eps = int(e,2) |
|||
|
|||
res1 = str(gamma * eps) |
|||
print("challenge 1:" + res1 + "\n") |
|||
|
|||
ox = bins |
|||
co2 = bins |
|||
|
|||
# challenge 2 |
|||
for i in range(len(bins[0])): |
|||
ox = filter(ox, i, 1) |
|||
co2 = filter(co2, i, 0) |
|||
|
|||
oxr = int(''.join(str(i) for i in ox[0]), 2) |
|||
csr = int(''.join(str(i) for i in co2[0]), 2) |
|||
|
|||
res2 = str(oxr * csr) |
|||
print("challenge 2:" + res2 + "\n") |
|||
|
@ -0,0 +1,74 @@ |
|||
--- Day 3: Binary Diagnostic --- |
|||
|
|||
The submarine has been making some odd creaking noises, so you ask it to produce a diagnostic report just in case. |
|||
|
|||
The diagnostic report (your puzzle input) consists of a list of binary numbers which, when decoded properly, can tell you many useful things about the conditions of the submarine. The first parameter to check is the power consumption. |
|||
|
|||
You need to use the binary numbers in the diagnostic report to generate two new binary numbers (called the gamma rate and the epsilon rate). The power consumption can then be found by multiplying the gamma rate by the epsilon rate. |
|||
|
|||
Each bit in the gamma rate can be determined by finding the most common bit in the corresponding position of all numbers in the diagnostic report. For example, given the following diagnostic report: |
|||
|
|||
00100 |
|||
11110 |
|||
10110 |
|||
10111 |
|||
10101 |
|||
01111 |
|||
00111 |
|||
11100 |
|||
10000 |
|||
11001 |
|||
00010 |
|||
01010 |
|||
|
|||
Considering only the first bit of each number, there are five 0 bits and seven 1 bits. Since the most common bit is 1, the first bit of the gamma rate is 1. |
|||
|
|||
The most common second bit of the numbers in the diagnostic report is 0, so the second bit of the gamma rate is 0. |
|||
|
|||
The most common value of the third, fourth, and fifth bits are 1, 1, and 0, respectively, and so the final three bits of the gamma rate are 110. |
|||
|
|||
So, the gamma rate is the binary number 10110, or 22 in decimal. |
|||
|
|||
The epsilon rate is calculated in a similar way; rather than use the most common bit, the least common bit from each position is used. So, the epsilon rate is 01001, or 9 in decimal. Multiplying the gamma rate (22) by the epsilon rate (9) produces the power consumption, 198. |
|||
|
|||
Use the binary numbers in your diagnostic report to calculate the gamma rate and epsilon rate, then multiply them together. What is the power consumption of the submarine? (Be sure to represent your answer in decimal, not binary.) |
|||
|
|||
Your puzzle answer was 3242606. |
|||
--- Part Two --- |
|||
|
|||
Next, you should verify the life support rating, which can be determined by multiplying the oxygen generator rating by the CO2 scrubber rating. |
|||
|
|||
Both the oxygen generator rating and the CO2 scrubber rating are values that can be found in your diagnostic report - finding them is the tricky part. Both values are located using a similar process that involves filtering out values until only one remains. Before searching for either rating value, start with the full list of binary numbers from your diagnostic report and consider just the first bit of those numbers. Then: |
|||
|
|||
Keep only numbers selected by the bit criteria for the type of rating value for which you are searching. Discard numbers which do not match the bit criteria. |
|||
If you only have one number left, stop; this is the rating value for which you are searching. |
|||
Otherwise, repeat the process, considering the next bit to the right. |
|||
|
|||
The bit criteria depends on which type of rating value you want to find: |
|||
|
|||
To find oxygen generator rating, determine the most common value (0 or 1) in the current bit position, and keep only numbers with that bit in that position. If 0 and 1 are equally common, keep values with a 1 in the position being considered. |
|||
To find CO2 scrubber rating, determine the least common value (0 or 1) in the current bit position, and keep only numbers with that bit in that position. If 0 and 1 are equally common, keep values with a 0 in the position being considered. |
|||
|
|||
For example, to determine the oxygen generator rating value using the same example diagnostic report from above: |
|||
|
|||
Start with all 12 numbers and consider only the first bit of each number. There are more 1 bits (7) than 0 bits (5), so keep only the 7 numbers with a 1 in the first position: 11110, 10110, 10111, 10101, 11100, 10000, and 11001. |
|||
Then, consider the second bit of the 7 remaining numbers: there are more 0 bits (4) than 1 bits (3), so keep only the 4 numbers with a 0 in the second position: 10110, 10111, 10101, and 10000. |
|||
In the third position, three of the four numbers have a 1, so keep those three: 10110, 10111, and 10101. |
|||
In the fourth position, two of the three numbers have a 1, so keep those two: 10110 and 10111. |
|||
In the fifth position, there are an equal number of 0 bits and 1 bits (one each). So, to find the oxygen generator rating, keep the number with a 1 in that position: 10111. |
|||
As there is only one number left, stop; the oxygen generator rating is 10111, or 23 in decimal. |
|||
|
|||
Then, to determine the CO2 scrubber rating value from the same example above: |
|||
|
|||
Start again with all 12 numbers and consider only the first bit of each number. There are fewer 0 bits (5) than 1 bits (7), so keep only the 5 numbers with a 0 in the first position: 00100, 01111, 00111, 00010, and 01010. |
|||
Then, consider the second bit of the 5 remaining numbers: there are fewer 1 bits (2) than 0 bits (3), so keep only the 2 numbers with a 1 in the second position: 01111 and 01010. |
|||
In the third position, there are an equal number of 0 bits and 1 bits (one each). So, to find the CO2 scrubber rating, keep the number with a 0 in that position: 01010. |
|||
As there is only one number left, stop; the CO2 scrubber rating is 01010, or 10 in decimal. |
|||
|
|||
Finally, to find the life support rating, multiply the oxygen generator rating (23) by the CO2 scrubber rating (10) to get 230. |
|||
|
|||
Use the binary numbers in your diagnostic report to calculate the oxygen generator rating and CO2 scrubber rating, then multiply them together. What is the life support rating of the submarine? (Be sure to represent your answer in decimal, not binary.) |
|||
|
|||
Your puzzle answer was 4856080. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
File diff suppressed because it is too large
@ -0,0 +1,63 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys |
|||
|
|||
def printb(board): |
|||
for line in board: |
|||
print(str(line[0]) + ' ' + str(line[1]) + ' ' + str(line[2]) + ' ' + str(line[3]) + ' ' + str(line[4])) |
|||
print("\n") |
|||
|
|||
def check_win(board): |
|||
for l in board: |
|||
if l == ['x' ,'x', 'x', 'x', 'x']: |
|||
return True |
|||
hit = 0 |
|||
for i in range(len(board)): |
|||
for l in board: |
|||
if l[i] == 'x': |
|||
hit += 1 |
|||
if hit == len(board): |
|||
return True |
|||
hit = 0 |
|||
return False |
|||
|
|||
def play(boards): |
|||
for num in nums: |
|||
boards = [mark_board(board, num) for board in boards] |
|||
for board in boards: |
|||
if check_win(board): |
|||
return num * sum([sum([i for i in l if i != 'x']) for l in board]) |
|||
|
|||
def play2(boards): |
|||
for num in nums: |
|||
boards = [mark_board(board, num) for board in boards] |
|||
if sum([1 if check_win(board) else 0 for board in boards]) == (len(boards) - 1): |
|||
for i in range(len(boards)): |
|||
if not check_win(boards[i]): |
|||
last = i |
|||
if sum([1 if check_win(board) else 0 for board in boards]) == (len(boards)): |
|||
if check_win(boards[last]): |
|||
board = boards[last] |
|||
return num * sum([sum([i for i in l if i != 'x']) for l in board]) |
|||
|
|||
|
|||
def mark_board(board, num): |
|||
return [['x' if col == num else col for col in li] for li in board] |
|||
|
|||
if __name__ == '__main__': |
|||
lines = open(sys.argv[1]).read().split('\n\n') # or split \n\n or sth similar |
|||
|
|||
nums = [int(i) for i in lines[0].split(',')] |
|||
|
|||
boards = [[[int(n) for n in l.split(' ') if n != ''] for l in li.split('\n')] for li in lines[1:]] |
|||
|
|||
boards = [[l for l in b if l != []] for b in boards] |
|||
|
|||
# challenge 1 |
|||
res1 = str(play(boards)) |
|||
print("challenge 1:" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
res2 = str(play2(boards)) |
|||
print("challenge 2:" + res2 + "\n") |
|||
|
@ -0,0 +1,74 @@ |
|||
--- Day 4: Giant Squid --- |
|||
|
|||
You're already almost 1.5km (almost a mile) below the surface of the ocean, already so deep that you can't see any sunlight. What you can see, however, is a giant squid that has attached itself to the outside of your submarine. |
|||
|
|||
Maybe it wants to play bingo? |
|||
|
|||
Bingo is played on a set of boards each consisting of a 5x5 grid of numbers. Numbers are chosen at random, and the chosen number is marked on all boards on which it appears. (Numbers may not appear on all boards.) If all numbers in any row or any column of a board are marked, that board wins. (Diagonals don't count.) |
|||
|
|||
The submarine has a bingo subsystem to help passengers (currently, you and the giant squid) pass the time. It automatically generates a random order in which to draw numbers and a random set of boards (your puzzle input). For example: |
|||
|
|||
7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1 |
|||
|
|||
22 13 17 11 0 |
|||
8 2 23 4 24 |
|||
21 9 14 16 7 |
|||
6 10 3 18 5 |
|||
1 12 20 15 19 |
|||
|
|||
3 15 0 2 22 |
|||
9 18 13 17 5 |
|||
19 8 7 25 23 |
|||
20 11 10 24 4 |
|||
14 21 16 12 6 |
|||
|
|||
14 21 17 24 4 |
|||
10 16 15 9 19 |
|||
18 8 23 26 20 |
|||
22 11 13 6 5 |
|||
2 0 12 3 7 |
|||
|
|||
After the first five numbers are drawn (7, 4, 9, 5, and 11), there are no winners, but the boards are marked as follows (shown here adjacent to each other to save space): |
|||
|
|||
22 13 17 11 0 3 15 0 2 22 14 21 17 24 4 |
|||
8 2 23 4 24 9 18 13 17 5 10 16 15 9 19 |
|||
21 9 14 16 7 19 8 7 25 23 18 8 23 26 20 |
|||
6 10 3 18 5 20 11 10 24 4 22 11 13 6 5 |
|||
1 12 20 15 19 14 21 16 12 6 2 0 12 3 7 |
|||
|
|||
After the next six numbers are drawn (17, 23, 2, 0, 14, and 21), there are still no winners: |
|||
|
|||
22 13 17 11 0 3 15 0 2 22 14 21 17 24 4 |
|||
8 2 23 4 24 9 18 13 17 5 10 16 15 9 19 |
|||
21 9 14 16 7 19 8 7 25 23 18 8 23 26 20 |
|||
6 10 3 18 5 20 11 10 24 4 22 11 13 6 5 |
|||
1 12 20 15 19 14 21 16 12 6 2 0 12 3 7 |
|||
|
|||
Finally, 24 is drawn: |
|||
|
|||
22 13 17 11 0 3 15 0 2 22 14 21 17 24 4 |
|||
8 2 23 4 24 9 18 13 17 5 10 16 15 9 19 |
|||
21 9 14 16 7 19 8 7 25 23 18 8 23 26 20 |
|||
6 10 3 18 5 20 11 10 24 4 22 11 13 6 5 |
|||
1 12 20 15 19 14 21 16 12 6 2 0 12 3 7 |
|||
|
|||
At this point, the third board wins because it has at least one complete row or column of marked numbers (in this case, the entire top row is marked: 14 21 17 24 4). |
|||
|
|||
The score of the winning board can now be calculated. Start by finding the sum of all unmarked numbers on that board; in this case, the sum is 188. Then, multiply that sum by the number that was just called when the board won, 24, to get the final score, 188 * 24 = 4512. |
|||
|
|||
To guarantee victory against the giant squid, figure out which board will win first. What will your final score be if you choose that board? |
|||
|
|||
Your puzzle answer was 65325. |
|||
--- Part Two --- |
|||
|
|||
On the other hand, it might be wise to try a different strategy: let the giant squid win. |
|||
|
|||
You aren't sure how many bingo boards a giant squid could play at once, so rather than waste time counting its arms, the safe thing to do is to figure out which board will win last and choose that one. That way, no matter which boards it picks, it will win for sure. |
|||
|
|||
In the above example, the second board is the last to win, which happens after 13 is eventually called and its middle column is completely marked. If you were to keep playing until this point, the second board would have a sum of unmarked numbers equal to 148 for a final score of 148 * 13 = 1924. |
|||
|
|||
Figure out which board will win last. Once it wins, what would its final score be? |
|||
|
|||
Your puzzle answer was 4624. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
@ -0,0 +1,601 @@ |
|||
49,48,98,84,71,59,37,36,6,21,46,30,5,33,3,62,63,45,43,35,65,77,57,75,19,44,4,76,88,92,12,27,7,51,14,72,96,9,0,17,83,64,38,95,54,20,1,74,69,80,81,56,10,68,42,15,99,53,93,94,47,13,29,34,60,41,82,90,25,85,78,91,32,70,58,28,61,24,55,87,39,11,79,50,22,8,89,26,16,2,73,23,18,66,52,31,86,97,67,40 |
|||
|
|||
86 46 47 61 57 |
|||
44 74 17 5 87 |
|||
78 8 54 55 97 |
|||
11 90 7 75 70 |
|||
81 50 84 10 60 |
|||
|
|||
47 28 64 52 44 |
|||
73 48 30 15 53 |
|||
57 21 78 75 26 |
|||
51 39 72 18 25 |
|||
29 76 83 54 82 |
|||
|
|||
81 1 18 24 12 |
|||
3 38 15 85 50 |
|||
32 10 74 86 84 |
|||
30 64 56 79 95 |
|||
78 94 35 93 8 |
|||
|
|||
48 30 79 85 87 |
|||
66 35 13 17 95 |
|||
32 22 94 61 20 |
|||
50 42 0 3 93 |
|||
69 44 68 1 9 |
|||
|
|||
91 79 93 41 33 |
|||
98 51 39 9 10 |
|||
24 70 99 2 11 |
|||
32 13 21 6 68 |
|||
40 27 48 89 7 |
|||
|
|||
40 29 34 1 23 |
|||
79 36 75 57 95 |
|||
61 50 4 21 48 |
|||
54 0 81 98 72 |
|||
24 30 15 31 52 |
|||
|
|||
18 68 17 25 34 |
|||
97 36 77 6 30 |
|||
79 72 38 94 60 |
|||
54 45 16 67 12 |
|||
58 31 57 71 92 |
|||
|
|||
40 58 80 86 85 |
|||
91 57 51 23 10 |
|||
61 78 4 36 66 |
|||
24 41 88 25 99 |
|||
15 68 12 55 75 |
|||
|
|||
82 99 17 5 76 |
|||
65 42 73 78 61 |
|||
34 62 14 23 68 |
|||
9 79 72 45 0 |
|||
43 96 11 13 10 |
|||
|
|||
98 47 90 14 12 |
|||
80 63 35 42 11 |
|||
27 66 1 9 32 |
|||
17 85 61 71 68 |
|||
6 29 7 94 67 |
|||
|
|||
38 35 70 18 59 |
|||
62 54 84 10 27 |
|||
60 92 90 64 86 |
|||
25 99 49 43 4 |
|||
23 50 39 16 40 |
|||
|
|||
72 1 73 8 33 |
|||
86 65 99 49 66 |
|||
56 79 23 41 46 |
|||
4 48 43 55 93 |
|||
98 63 47 37 30 |
|||
|
|||
33 96 72 93 99 |
|||
30 12 56 46 65 |
|||
39 40 59 94 50 |
|||
0 8 67 27 47 |
|||
53 57 24 77 42 |
|||
|
|||
9 57 8 28 12 |
|||
90 81 21 25 51 |
|||
88 18 78 3 64 |
|||
20 87 97 45 85 |
|||
92 40 52 29 17 |
|||
|
|||
99 89 15 54 32 |
|||
93 81 36 14 91 |
|||
86 7 67 18 92 |
|||
65 21 55 38 8 |
|||
12 88 27 90 94 |
|||
|
|||
96 0 6 91 44 |
|||
28 60 10 70 75 |
|||
69 37 51 21 87 |
|||
93 59 14 53 15 |
|||
64 66 9 50 27 |
|||
|
|||
33 46 38 2 41 |
|||
24 51 50 72 57 |
|||
42 85 99 97 56 |
|||
35 69 12 86 73 |
|||
4 47 34 80 17 |
|||
|
|||
70 28 77 73 53 |
|||
67 94 83 79 82 |
|||
89 9 96 48 17 |
|||
47 86 88 12 3 |
|||
55 39 98 14 90 |
|||
|
|||
64 82 85 45 10 |
|||
27 5 12 72 40 |
|||
52 31 25 79 65 |
|||
6 26 3 43 57 |
|||
89 49 36 59 35 |
|||
|
|||
70 0 58 98 65 |
|||
54 93 75 14 26 |
|||
28 69 17 29 78 |
|||
46 22 47 85 87 |
|||
44 38 10 11 63 |
|||
|
|||
18 52 66 42 58 |
|||
99 78 44 28 73 |
|||
24 71 5 14 82 |
|||
77 35 45 76 19 |
|||
70 20 0 43 48 |
|||
|
|||
42 82 85 87 51 |
|||
40 49 93 95 74 |
|||
25 79 37 67 55 |
|||
26 27 90 47 22 |
|||
38 50 33 10 75 |
|||
|
|||
15 99 60 28 79 |
|||
94 42 63 20 57 |
|||
44 55 96 67 53 |
|||
64 3 29 61 33 |
|||
51 12 39 97 30 |
|||
|
|||
7 95 28 39 76 |
|||
87 31 23 47 75 |
|||
88 10 78 24 20 |
|||
30 81 22 51 62 |
|||
53 93 55 38 0 |
|||
|
|||
12 99 2 89 17 |
|||
30 23 92 66 10 |
|||
39 60 74 82 15 |
|||
1 28 49 0 29 |
|||
90 55 9 69 83 |
|||
|
|||
79 44 70 59 88 |
|||
90 8 81 23 5 |
|||
40 67 66 55 17 |
|||
95 61 75 48 91 |
|||
98 71 24 38 29 |
|||
|
|||
95 28 8 76 13 |
|||
86 21 48 3 6 |
|||
34 47 31 50 2 |
|||
52 40 77 60 61 |
|||
0 88 87 23 25 |
|||
|
|||
63 70 34 91 17 |
|||
98 49 8 2 14 |
|||
25 22 92 65 18 |
|||
78 61 97 73 20 |
|||
57 83 16 7 68 |
|||
|
|||
43 23 70 39 16 |
|||
0 60 76 7 58 |
|||
89 40 38 17 5 |
|||
86 50 10 77 37 |
|||
26 65 25 69 92 |
|||
|
|||
34 71 92 19 80 |
|||
93 6 24 42 45 |
|||
96 9 50 85 21 |
|||
36 49 13 25 17 |
|||
20 98 74 70 57 |
|||
|
|||
25 96 65 77 30 |
|||
22 34 41 36 91 |
|||
62 18 61 15 19 |
|||
42 74 86 58 97 |
|||
87 31 53 8 52 |
|||
|
|||
40 37 15 53 91 |
|||
14 11 35 49 55 |
|||
73 32 83 66 87 |
|||
98 31 70 58 88 |
|||
7 61 8 76 16 |
|||
|
|||
27 94 87 57 80 |
|||
54 35 40 59 72 |
|||
88 84 70 98 92 |
|||
37 52 45 7 16 |
|||
0 30 12 22 41 |
|||
|
|||
44 65 68 14 70 |
|||
5 35 17 90 7 |
|||
56 89 48 84 32 |
|||
73 69 74 51 72 |
|||
24 10 94 78 60 |
|||
|
|||
81 15 3 42 90 |
|||
54 52 74 84 71 |
|||
97 78 20 9 2 |
|||
59 66 1 91 87 |
|||
70 56 93 47 37 |
|||
|
|||
93 36 19 69 94 |
|||
17 20 48 58 52 |
|||
85 57 90 42 14 |
|||
16 92 4 49 65 |
|||
22 9 2 24 44 |
|||
|
|||
47 99 13 31 62 |
|||
81 58 88 91 94 |
|||
29 11 96 95 1 |
|||
14 20 82 34 37 |
|||
84 39 76 41 22 |
|||
|
|||
1 74 21 2 67 |
|||
38 79 96 26 88 |
|||
19 17 94 71 52 |
|||
31 28 69 8 51 |
|||
41 77 45 95 82 |
|||
|
|||
24 9 94 69 65 |
|||
97 84 85 53 5 |
|||
92 11 61 77 8 |
|||
21 75 33 57 63 |
|||
43 68 55 52 93 |
|||
|
|||
27 21 8 75 73 |
|||
4 53 23 56 47 |
|||
28 94 50 80 19 |
|||
89 58 24 12 13 |
|||
60 5 99 96 9 |
|||
|
|||
31 43 59 65 33 |
|||
51 32 14 58 4 |
|||
11 41 70 78 12 |
|||
1 25 57 80 49 |
|||
91 66 0 27 17 |
|||
|
|||
64 67 37 24 35 |
|||
4 22 54 75 21 |
|||
19 91 9 52 83 |
|||
20 68 53 12 0 |
|||
28 76 51 49 89 |
|||
|
|||
67 89 14 54 81 |
|||
0 59 51 63 56 |
|||
85 88 95 7 36 |
|||
40 27 47 86 19 |
|||
52 92 22 16 30 |
|||
|
|||
75 25 39 9 19 |
|||
59 92 24 6 22 |
|||
79 73 34 66 49 |
|||
16 89 56 76 55 |
|||
5 45 4 46 62 |
|||
|
|||
71 44 63 97 47 |
|||
27 61 70 52 46 |
|||
19 80 21 68 65 |
|||
28 45 84 14 94 |
|||
38 73 66 78 92 |
|||
|
|||
47 45 41 96 54 |
|||
38 14 62 55 91 |
|||
2 11 97 12 51 |
|||
36 49 3 95 76 |
|||
5 75 7 94 87 |
|||
|
|||
70 24 93 96 86 |
|||
49 51 73 50 83 |
|||
97 0 57 13 9 |
|||
99 46 22 67 39 |
|||
56 21 29 52 27 |
|||
|
|||
42 82 80 65 19 |
|||
78 41 56 83 75 |
|||
51 72 10 1 33 |
|||
84 63 21 87 86 |
|||
77 64 31 68 6 |
|||
|
|||
60 50 31 5 58 |
|||
83 9 87 98 13 |
|||
4 35 24 33 88 |
|||
54 59 71 64 3 |
|||
16 57 48 15 86 |
|||
|
|||
45 29 81 25 14 |
|||
13 21 79 90 0 |
|||
88 38 56 11 15 |
|||
47 2 40 35 75 |
|||
91 28 48 32 98 |
|||
|
|||
87 58 78 65 69 |
|||
89 35 45 26 13 |
|||
28 61 15 3 44 |
|||
64 57 92 93 50 |
|||
90 39 4 70 9 |
|||
|
|||
16 35 41 40 81 |
|||
48 92 94 83 79 |
|||
54 50 62 8 53 |
|||
14 5 85 68 22 |
|||
42 26 33 23 93 |
|||
|
|||
7 13 82 89 49 |
|||
43 21 79 38 56 |
|||
6 31 90 58 81 |
|||
39 47 77 30 54 |
|||
23 41 86 19 8 |
|||
|
|||
69 20 95 33 63 |
|||
64 34 4 79 36 |
|||
13 21 78 56 6 |
|||
35 44 85 27 76 |
|||
75 15 14 52 39 |
|||
|
|||
42 71 73 1 45 |
|||
66 75 7 40 54 |
|||
91 83 65 53 20 |
|||
34 97 88 5 61 |
|||
63 82 50 74 38 |
|||
|
|||
62 89 40 70 91 |
|||
84 12 19 96 79 |
|||
72 15 35 23 14 |
|||
4 69 0 55 17 |
|||
85 90 20 28 13 |
|||
|
|||
27 93 23 1 38 |
|||
67 28 62 9 96 |
|||
31 35 47 44 88 |
|||
78 57 53 5 69 |
|||
91 15 82 75 61 |
|||
|
|||
17 44 85 92 94 |
|||
0 67 5 50 64 |
|||
66 65 98 58 56 |
|||
62 4 57 99 34 |
|||
83 43 76 12 69 |
|||
|
|||
0 28 13 68 86 |
|||
84 24 50 32 40 |
|||
25 71 72 96 94 |
|||
89 1 64 81 23 |
|||
97 66 5 15 91 |
|||
|
|||
59 67 79 84 44 |
|||
74 61 81 20 68 |
|||
24 92 55 99 11 |
|||
76 60 97 43 66 |
|||
31 30 89 45 53 |
|||
|
|||
1 97 15 34 85 |
|||
45 59 54 66 24 |
|||
53 36 51 58 27 |
|||
84 83 71 5 95 |
|||
70 6 65 79 13 |
|||
|
|||
84 86 0 25 2 |
|||
1 59 92 39 56 |
|||
17 7 88 78 24 |
|||
51 87 89 44 31 |
|||
54 63 50 18 36 |
|||
|
|||
98 86 30 70 12 |
|||
11 52 49 39 14 |
|||
16 35 56 87 72 |
|||
85 65 93 92 60 |
|||
20 43 77 41 79 |
|||
|
|||
50 31 71 78 21 |
|||
70 94 99 35 29 |
|||
56 58 27 65 28 |
|||
45 36 47 69 98 |
|||
5 48 61 19 93 |
|||
|
|||
64 65 86 14 53 |
|||
7 43 75 39 38 |
|||
20 59 80 88 54 |
|||
12 32 66 34 87 |
|||
29 15 25 19 45 |
|||
|
|||
88 20 42 5 32 |
|||
56 8 80 15 98 |
|||
36 99 35 27 16 |
|||
92 66 75 91 10 |
|||
81 96 65 0 57 |
|||
|
|||
29 78 8 76 41 |
|||
99 18 60 90 47 |
|||
50 51 40 2 31 |
|||
38 70 25 52 39 |
|||
26 35 84 6 80 |
|||
|
|||
6 68 56 15 53 |
|||
99 60 69 25 7 |
|||
65 35 9 11 66 |
|||
92 85 48 40 97 |
|||
63 59 57 17 55 |
|||
|
|||
46 95 75 99 21 |
|||
50 24 64 35 63 |
|||
93 39 3 67 82 |
|||
41 42 84 15 55 |
|||
79 81 97 60 17 |
|||
|
|||
33 14 60 42 40 |
|||
76 73 56 71 88 |
|||
91 41 83 74 16 |
|||
57 85 35 44 47 |
|||
99 59 46 12 45 |
|||
|
|||
53 83 54 21 68 |
|||
79 97 85 0 67 |
|||
41 90 48 95 3 |
|||
96 70 65 22 25 |
|||
60 77 33 15 28 |
|||
|
|||
17 12 5 51 15 |
|||
75 92 72 16 65 |
|||
59 85 29 23 57 |
|||
14 53 97 68 84 |
|||
1 93 49 38 28 |
|||
|
|||
27 40 24 12 57 |
|||
84 13 9 43 31 |
|||
70 23 51 94 34 |
|||
1 80 91 16 29 |
|||
99 75 49 52 54 |
|||
|
|||
52 85 23 72 40 |
|||
6 88 16 41 67 |
|||
53 94 8 32 33 |
|||
75 62 24 13 64 |
|||
65 0 60 86 47 |
|||
|
|||
5 28 27 15 41 |
|||
19 77 38 83 45 |
|||
32 70 78 26 90 |
|||
82 80 85 22 84 |
|||
59 73 24 9 63 |
|||
|
|||
29 58 28 82 13 |
|||
78 55 63 43 51 |
|||
19 33 90 91 48 |
|||
93 7 35 22 71 |
|||
40 95 38 24 46 |
|||
|
|||
38 30 13 16 74 |
|||
69 68 42 6 4 |
|||
62 82 29 79 1 |
|||
61 7 15 25 85 |
|||
5 66 45 43 90 |
|||
|
|||
19 65 12 91 34 |
|||
17 6 30 32 64 |
|||
37 53 4 35 62 |
|||
41 22 13 11 25 |
|||
60 27 93 76 51 |
|||
|
|||
3 92 25 88 14 |
|||
40 30 55 10 37 |
|||
19 94 56 34 74 |
|||
75 87 80 54 83 |
|||
2 20 70 45 16 |
|||
|
|||
52 93 87 60 11 |
|||
82 66 88 59 95 |
|||
58 31 49 33 28 |
|||
77 39 43 9 51 |
|||
20 80 98 47 16 |
|||
|
|||
35 48 47 11 82 |
|||
8 36 54 20 40 |
|||
90 95 85 4 66 |
|||
22 75 64 81 10 |
|||
27 62 89 30 12 |
|||
|
|||
75 40 11 63 19 |
|||
4 43 6 93 48 |
|||
85 58 82 66 52 |
|||
32 28 0 14 20 |
|||
78 61 83 95 87 |
|||
|
|||
57 79 16 37 33 |
|||
20 17 27 38 63 |
|||
35 77 60 97 34 |
|||
22 78 72 43 26 |
|||
29 12 9 46 54 |
|||
|
|||
26 94 37 57 1 |
|||
49 6 65 80 55 |
|||
46 38 33 89 99 |
|||
42 18 86 97 98 |
|||
45 76 41 9 12 |
|||
|
|||
83 70 31 61 30 |
|||
16 78 84 12 18 |
|||
15 65 62 55 98 |
|||
6 21 80 41 69 |
|||
25 2 24 10 79 |
|||
|
|||
98 75 5 66 37 |
|||
90 7 26 61 15 |
|||
48 70 20 60 41 |
|||
23 58 82 22 74 |
|||
80 8 51 67 55 |
|||
|
|||
84 86 77 97 28 |
|||
37 87 2 93 5 |
|||
16 64 35 61 27 |
|||
8 3 36 10 73 |
|||
31 65 94 63 13 |
|||
|
|||
91 9 64 67 19 |
|||
56 35 11 62 28 |
|||
0 65 59 72 45 |
|||
34 24 51 26 80 |
|||
93 50 58 53 27 |
|||
|
|||
27 54 77 57 94 |
|||
60 46 55 74 62 |
|||
16 9 19 48 6 |
|||
69 1 26 78 2 |
|||
45 75 41 25 90 |
|||
|
|||
45 83 97 81 95 |
|||
26 64 40 94 7 |
|||
57 28 86 8 36 |
|||
98 92 16 13 20 |
|||
99 79 50 65 51 |
|||
|
|||
38 6 96 71 10 |
|||
51 55 2 44 74 |
|||
31 61 98 72 73 |
|||
79 54 91 34 62 |
|||
88 17 46 45 43 |
|||
|
|||
17 18 39 59 26 |
|||
45 40 91 47 74 |
|||
46 97 94 12 79 |
|||
61 7 8 56 50 |
|||
0 77 20 57 9 |
|||
|
|||
74 4 65 2 23 |
|||
45 56 90 94 96 |
|||
80 71 69 86 85 |
|||
19 78 35 47 98 |
|||
51 73 6 33 14 |
|||
|
|||
8 60 40 2 37 |
|||
10 68 44 50 73 |
|||
69 26 6 52 93 |
|||
33 65 46 24 11 |
|||
71 59 15 28 84 |
|||
|
|||
57 65 70 98 68 |
|||
80 3 13 39 20 |
|||
11 71 47 78 42 |
|||
31 61 72 86 9 |
|||
53 43 87 28 77 |
|||
|
|||
67 32 59 34 77 |
|||
29 23 80 27 62 |
|||
81 97 46 14 42 |
|||
19 47 44 85 24 |
|||
53 9 71 37 1 |
|||
|
|||
83 13 27 41 9 |
|||
95 62 65 86 63 |
|||
0 17 33 11 76 |
|||
45 64 39 71 55 |
|||
84 52 21 59 20 |
|||
|
|||
63 45 55 80 3 |
|||
14 73 47 96 10 |
|||
82 26 85 0 11 |
|||
53 6 28 57 60 |
|||
49 99 18 50 71 |
|||
|
|||
30 67 16 22 84 |
|||
81 4 34 61 65 |
|||
57 69 51 94 58 |
|||
6 89 37 75 47 |
|||
19 14 97 2 86 |
|||
|
|||
64 83 1 66 70 |
|||
30 82 96 3 67 |
|||
79 11 22 95 14 |
|||
87 60 4 15 26 |
|||
84 69 99 19 74 |
@ -0,0 +1,82 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys |
|||
import re |
|||
|
|||
def parse(line): |
|||
groups = re.compile(r"(?P<x1>\d+),(?P<y1>\d+) -> (?P<x2>\d+),(?P<y2>\d+)").search(line) |
|||
return groups |
|||
|
|||
def calc(x1, y1, x2, y2, mem): |
|||
if x1 == x2: |
|||
if y1 > y2: |
|||
y = y2 |
|||
y2 = y1 |
|||
y1 = y |
|||
for y in range(y1, y2+1): |
|||
if (x1, y) not in mem: |
|||
mem[(x1, y)] = 1 |
|||
else: |
|||
mem[(x1, y)] += 1 |
|||
elif y1 == y2: |
|||
if x1 > x2: |
|||
x = x2 |
|||
x2 = x1 |
|||
x1 = x |
|||
for x in range(x1, x2+1): |
|||
if (x, y1) not in mem: |
|||
mem[(x, y1)] = 1 |
|||
else: |
|||
mem[(x, y1)] += 1 |
|||
|
|||
|
|||
def calc2(x1, y1, x2, y2): |
|||
if x1 != x2 and y1 != y2: |
|||
if x1 > x2: |
|||
dif = x1-x2+1 |
|||
m1 = -1 |
|||
else: |
|||
dif = x2-x1+1 |
|||
m1 = 1 |
|||
if y1 > y2: |
|||
m2 = -1 |
|||
else: |
|||
m2 = 1 |
|||
for i in range(dif): |
|||
if (x1+m1*i, y1+m2*i) not in memo2: |
|||
memo2[(x1+m1*i, y1+m2*i)] = 1 |
|||
else: |
|||
memo2[(x1+m1*i, y1+m2*i)] += 1 |
|||
|
|||
|
|||
if __name__ == '__main__': |
|||
lines = open(sys.argv[1]).readlines() |
|||
|
|||
coords = [tuple(map(int,parse(line).groups())) for line in lines] |
|||
|
|||
# challenge 1 |
|||
|
|||
memo = {} |
|||
for c in coords: |
|||
calc(*c,memo) |
|||
|
|||
res1 = 0 |
|||
for v in memo.values(): |
|||
if v > 1: |
|||
res1 += 1 |
|||
|
|||
print("challenge 1:" + "\n" + str(res1) + "\n") |
|||
|
|||
# challenge 2 |
|||
|
|||
memo2 = {} |
|||
for c in coords: |
|||
calc(*c,memo2) |
|||
calc2(*c) |
|||
|
|||
res2 = 0 |
|||
for v in memo2.values(): |
|||
if v > 1: |
|||
res2 += 1 |
|||
print("challenge 2:" + "\n" + str(res2) + "\n") |
|||
|
@ -0,0 +1,73 @@ |
|||
--- Day 5: Hydrothermal Venture --- |
|||
|
|||
You come across a field of hydrothermal vents on the ocean floor! These vents constantly produce large, opaque clouds, so it would be best to avoid them if possible. |
|||
|
|||
They tend to form in lines; the submarine helpfully produces a list of nearby lines of vents (your puzzle input) for you to review. For example: |
|||
|
|||
0,9 -> 5,9 |
|||
8,0 -> 0,8 |
|||
9,4 -> 3,4 |
|||
2,2 -> 2,1 |
|||
7,0 -> 7,4 |
|||
6,4 -> 2,0 |
|||
0,9 -> 2,9 |
|||
3,4 -> 1,4 |
|||
0,0 -> 8,8 |
|||
5,5 -> 8,2 |
|||
|
|||
Each line of vents is given as a line segment in the format x1,y1 -> x2,y2 where x1,y1 are the coordinates of one end the line segment and x2,y2 are the coordinates of the other end. These line segments include the points at both ends. In other words: |
|||
|
|||
An entry like 1,1 -> 1,3 covers points 1,1, 1,2, and 1,3. |
|||
An entry like 9,7 -> 7,7 covers points 9,7, 8,7, and 7,7. |
|||
|
|||
For now, only consider horizontal and vertical lines: lines where either x1 = x2 or y1 = y2. |
|||
|
|||
So, the horizontal and vertical lines from the above list would produce the following diagram: |
|||
|
|||
.......1.. |
|||
..1....1.. |
|||
..1....1.. |
|||
.......1.. |
|||
.112111211 |
|||
.......... |
|||
.......... |
|||
.......... |
|||
.......... |
|||
222111.... |
|||
|
|||
In this diagram, the top left corner is 0,0 and the bottom right corner is 9,9. Each position is shown as the number of lines which cover that point or . if no line covers that point. The top-left pair of 1s, for example, comes from 2,2 -> 2,1; the very bottom row is formed by the overlapping lines 0,9 -> 5,9 and 0,9 -> 2,9. |
|||
|
|||
To avoid the most dangerous areas, you need to determine the number of points where at least two lines overlap. In the above example, this is anywhere in the diagram with a 2 or larger - a total of 5 points. |
|||
|
|||
Consider only horizontal and vertical lines. At how many points do at least two lines overlap? |
|||
|
|||
Your puzzle answer was 5373. |
|||
--- Part Two --- |
|||
|
|||
Unfortunately, considering only horizontal and vertical lines doesn't give you the full picture; you need to also consider diagonal lines. |
|||
|
|||
Because of the limits of the hydrothermal vent mapping system, the lines in your list will only ever be horizontal, vertical, or a diagonal line at exactly 45 degrees. In other words: |
|||
|
|||
An entry like 1,1 -> 3,3 covers points 1,1, 2,2, and 3,3. |
|||
An entry like 9,7 -> 7,9 covers points 9,7, 8,8, and 7,9. |
|||
|
|||
Considering all lines from the above example would now produce the following diagram: |
|||
|
|||
1.1....11. |
|||
.111...2.. |
|||
..2.1.111. |
|||
...1.2.2.. |
|||
.112313211 |
|||
...1.2.... |
|||
..1...1... |
|||
.1.....1.. |
|||
1.......1. |
|||
222111.... |
|||
|
|||
You still need to determine the number of points where at least two lines overlap. In the above example, this is still anywhere in the diagram with a 2 or larger - now a total of 12 points. |
|||
|
|||
Consider all of the lines. At how many points do at least two lines overlap? |
|||
|
|||
Your puzzle answer was 21514. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
@ -0,0 +1,500 @@ |
|||
580,438 -> 580,817 |
|||
220,987 -> 199,966 |
|||
300,674 -> 300,523 |
|||
27,362 -> 27,932 |
|||
890,430 -> 854,430 |
|||
488,202 -> 488,885 |
|||
824,930 -> 824,740 |
|||
208,756 -> 851,113 |
|||
967,288 -> 967,960 |
|||
700,139 -> 531,139 |
|||
671,463 -> 671,150 |
|||
270,954 -> 270,801 |
|||
682,718 -> 682,146 |
|||
849,837 -> 353,341 |
|||
779,635 -> 420,635 |
|||
228,872 -> 228,419 |
|||
34,76 -> 745,787 |
|||
180,548 -> 180,969 |
|||
429,668 -> 445,652 |
|||
601,11 -> 893,11 |
|||
400,314 -> 128,586 |
|||
120,80 -> 972,932 |
|||
133,144 -> 969,980 |
|||
987,15 -> 106,896 |
|||
940,676 -> 940,322 |
|||
471,490 -> 900,490 |
|||
884,847 -> 64,27 |
|||
327,168 -> 327,948 |
|||
878,826 -> 463,411 |
|||
950,196 -> 161,985 |
|||
226,897 -> 234,889 |
|||
314,475 -> 698,475 |
|||
947,27 -> 72,902 |
|||
19,933 -> 936,16 |
|||
15,101 -> 335,101 |
|||
142,321 -> 781,321 |
|||
248,586 -> 130,586 |
|||
312,967 -> 565,714 |
|||
955,973 -> 63,81 |
|||
640,798 -> 153,798 |
|||
24,711 -> 147,711 |
|||
601,118 -> 601,712 |
|||
32,461 -> 32,275 |
|||
334,309 -> 43,309 |
|||
92,297 -> 92,30 |
|||
209,363 -> 799,953 |
|||
765,630 -> 892,630 |
|||
974,140 -> 127,987 |
|||
41,300 -> 606,300 |
|||
769,646 -> 149,26 |
|||
229,348 -> 379,348 |
|||
694,789 -> 423,518 |
|||
196,489 -> 842,489 |
|||
941,238 -> 206,238 |
|||
969,989 -> 132,152 |
|||
742,28 -> 402,28 |
|||
632,776 -> 399,543 |
|||
150,583 -> 444,877 |
|||
365,686 -> 365,401 |
|||
925,539 -> 925,366 |
|||
488,799 -> 488,637 |
|||
799,913 -> 512,626 |
|||
681,123 -> 626,68 |
|||
515,508 -> 515,568 |
|||
513,630 -> 823,630 |
|||
633,773 -> 244,384 |
|||
315,686 -> 315,131 |
|||
351,815 -> 351,965 |
|||
837,281 -> 186,932 |
|||
204,663 -> 179,663 |
|||
147,949 -> 647,449 |
|||
60,12 -> 928,880 |
|||
644,436 -> 644,635 |
|||
716,192 -> 916,192 |
|||
440,141 -> 440,560 |
|||
529,971 -> 752,971 |
|||
433,296 -> 148,581 |
|||
250,228 -> 348,228 |
|||
245,760 -> 631,760 |
|||
328,767 -> 558,767 |
|||
103,626 -> 937,626 |
|||
141,953 -> 913,181 |
|||
716,392 -> 389,65 |
|||
751,543 -> 751,763 |
|||
182,51 -> 623,492 |
|||
549,416 -> 907,58 |
|||
285,533 -> 690,533 |
|||
567,521 -> 567,227 |
|||
894,849 -> 69,24 |
|||
14,52 -> 911,949 |
|||
11,67 -> 887,943 |
|||
205,47 -> 820,47 |
|||
823,738 -> 823,833 |
|||
378,268 -> 378,531 |
|||
364,908 -> 874,398 |
|||
317,478 -> 317,265 |
|||
481,943 -> 867,557 |
|||
521,954 -> 929,954 |
|||
960,25 -> 27,958 |
|||
930,392 -> 175,392 |
|||
22,884 -> 853,53 |
|||
505,839 -> 624,720 |
|||
756,351 -> 737,351 |
|||
417,763 -> 417,167 |
|||
151,73 -> 151,51 |
|||
132,492 -> 567,57 |
|||
100,366 -> 942,366 |
|||
514,644 -> 578,644 |
|||
566,842 -> 14,290 |
|||
861,811 -> 861,174 |
|||
952,759 -> 172,759 |
|||
129,733 -> 129,821 |
|||
88,174 -> 877,963 |
|||
811,322 -> 767,366 |
|||
600,932 -> 544,988 |
|||
20,696 -> 407,696 |
|||
901,346 -> 901,267 |
|||
785,249 -> 785,602 |
|||
553,446 -> 553,541 |
|||
866,177 -> 206,837 |
|||
899,109 -> 19,989 |
|||
932,170 -> 149,953 |
|||
963,957 -> 258,957 |
|||
473,167 -> 355,49 |
|||
241,978 -> 241,333 |
|||
854,115 -> 77,892 |
|||
983,363 -> 289,363 |
|||
240,174 -> 520,454 |
|||
591,70 -> 591,139 |
|||
812,485 -> 319,485 |
|||
204,162 -> 204,121 |
|||
145,984 -> 959,170 |
|||
297,305 -> 297,968 |
|||
631,319 -> 631,56 |
|||
509,688 -> 509,829 |
|||
139,553 -> 139,458 |
|||
236,371 -> 237,372 |
|||
30,75 -> 149,75 |
|||
109,23 -> 109,325 |
|||
972,11 -> 20,963 |
|||
929,797 -> 882,750 |
|||
66,63 -> 845,842 |
|||
174,11 -> 174,104 |
|||
533,69 -> 533,199 |
|||
653,637 -> 653,584 |
|||
742,521 -> 473,790 |
|||
483,321 -> 464,302 |
|||
913,857 -> 95,39 |
|||
59,90 -> 835,866 |
|||
520,476 -> 520,50 |
|||
620,151 -> 421,350 |
|||
783,911 -> 783,817 |
|||
644,774 -> 740,774 |
|||
506,740 -> 506,751 |
|||
663,932 -> 536,805 |
|||
858,246 -> 128,976 |
|||
79,563 -> 372,563 |
|||
242,77 -> 672,77 |
|||
964,87 -> 374,677 |
|||
202,727 -> 644,285 |
|||
612,726 -> 612,724 |
|||
539,492 -> 611,492 |
|||
742,476 -> 929,476 |
|||
969,391 -> 925,435 |
|||
937,980 -> 119,162 |
|||
771,476 -> 771,581 |
|||
783,439 -> 875,439 |
|||
117,630 -> 600,147 |
|||
975,198 -> 244,929 |
|||
673,958 -> 673,326 |
|||
115,49 -> 984,918 |
|||
221,804 -> 639,386 |
|||
247,722 -> 70,722 |
|||
906,852 -> 92,38 |
|||
800,314 -> 115,314 |
|||
578,415 -> 578,431 |
|||
358,270 -> 358,410 |
|||
41,499 -> 41,877 |
|||
612,902 -> 612,612 |
|||
400,23 -> 315,23 |
|||
764,968 -> 764,723 |
|||
770,633 -> 770,229 |
|||
687,648 -> 687,531 |
|||
29,352 -> 29,473 |
|||
11,351 -> 944,351 |
|||
150,388 -> 150,434 |
|||
708,67 -> 866,67 |
|||
896,453 -> 594,755 |
|||
787,975 -> 63,251 |
|||
412,455 -> 198,455 |
|||
124,531 -> 124,420 |
|||
657,870 -> 470,870 |
|||
957,958 -> 36,37 |
|||
144,210 -> 756,822 |
|||
662,313 -> 271,313 |
|||
14,326 -> 636,948 |
|||
381,716 -> 381,24 |
|||
735,288 -> 735,788 |
|||
731,219 -> 731,881 |
|||
791,111 -> 303,111 |
|||
280,507 -> 333,454 |
|||
261,400 -> 600,400 |
|||
862,919 -> 862,560 |
|||
67,90 -> 827,850 |
|||
366,675 -> 581,675 |
|||
303,203 -> 303,479 |
|||
402,963 -> 402,347 |
|||
905,676 -> 905,60 |
|||
436,879 -> 100,879 |
|||
305,584 -> 322,584 |
|||
377,20 -> 221,20 |
|||
67,985 -> 959,93 |
|||
583,224 -> 583,197 |
|||
443,138 -> 786,138 |
|||
22,878 -> 889,11 |
|||
507,589 -> 56,589 |
|||
175,880 -> 947,108 |
|||
630,884 -> 630,786 |
|||
683,757 -> 848,757 |
|||
751,896 -> 54,199 |
|||
826,864 -> 826,339 |
|||
532,362 -> 532,648 |
|||
62,887 -> 62,841 |
|||
409,440 -> 409,501 |
|||
815,615 -> 272,615 |
|||
534,514 -> 534,43 |
|||
655,913 -> 878,913 |
|||
82,121 -> 270,121 |
|||
55,204 -> 84,175 |
|||
456,625 -> 383,552 |
|||
872,255 -> 872,497 |
|||
159,917 -> 837,239 |
|||
327,484 -> 193,484 |
|||
684,178 -> 789,178 |
|||
373,478 -> 117,222 |
|||
970,676 -> 970,65 |
|||
781,392 -> 781,413 |
|||
161,772 -> 177,772 |
|||
756,849 -> 373,849 |
|||
622,688 -> 622,839 |
|||
369,893 -> 369,353 |
|||
568,32 -> 568,219 |
|||
685,650 -> 685,428 |
|||
623,91 -> 981,449 |
|||
642,319 -> 642,747 |
|||
219,947 -> 715,451 |
|||
956,870 -> 770,870 |
|||
901,950 -> 219,268 |
|||
303,170 -> 303,486 |
|||
127,58 -> 861,792 |
|||
537,548 -> 537,569 |
|||
275,403 -> 275,112 |
|||
908,404 -> 735,404 |
|||
274,695 -> 239,730 |
|||
437,153 -> 437,436 |
|||
14,91 -> 909,986 |
|||
43,24 -> 949,930 |
|||
644,494 -> 324,494 |
|||
866,175 -> 556,485 |
|||
146,413 -> 146,341 |
|||
946,675 -> 661,960 |
|||
433,89 -> 751,407 |
|||
248,720 -> 248,377 |
|||
108,449 -> 845,449 |
|||
944,482 -> 944,59 |
|||
686,768 -> 686,861 |
|||
176,489 -> 176,586 |
|||
554,400 -> 554,412 |
|||
267,430 -> 268,430 |
|||
635,341 -> 635,977 |
|||
936,972 -> 22,58 |
|||
223,458 -> 223,39 |
|||
259,783 -> 259,788 |
|||
556,557 -> 556,443 |
|||
585,908 -> 61,384 |
|||
246,246 -> 594,594 |
|||
725,434 -> 43,434 |
|||
937,977 -> 937,303 |
|||
575,28 -> 191,28 |
|||
133,876 -> 133,459 |
|||
423,544 -> 501,544 |
|||
643,463 -> 563,463 |
|||
363,480 -> 12,831 |
|||
715,905 -> 458,905 |
|||
31,837 -> 264,604 |
|||
733,845 -> 733,220 |
|||
814,678 -> 719,678 |
|||
406,551 -> 735,551 |
|||
955,949 -> 37,31 |
|||
156,731 -> 749,138 |
|||
655,926 -> 646,926 |
|||
679,331 -> 679,718 |
|||
880,871 -> 204,195 |
|||
623,655 -> 779,655 |
|||
440,902 -> 550,902 |
|||
429,82 -> 491,82 |
|||
382,715 -> 382,342 |
|||
513,100 -> 513,514 |
|||
871,937 -> 16,82 |
|||
490,383 -> 442,383 |
|||
934,835 -> 157,58 |
|||
723,237 -> 373,587 |
|||
237,671 -> 237,130 |
|||
719,975 -> 365,975 |
|||
85,564 -> 352,564 |
|||
344,603 -> 583,603 |
|||
751,740 -> 751,847 |
|||
651,197 -> 660,197 |
|||
357,210 -> 745,598 |
|||
78,883 -> 883,78 |
|||
219,438 -> 714,933 |
|||
745,299 -> 268,299 |
|||
765,769 -> 878,769 |
|||
904,358 -> 315,358 |
|||
656,52 -> 145,563 |
|||
667,146 -> 693,146 |
|||
13,989 -> 984,18 |
|||
958,481 -> 958,936 |
|||
981,491 -> 519,29 |
|||
842,449 -> 337,449 |
|||
181,863 -> 29,863 |
|||
212,298 -> 212,21 |
|||
88,115 -> 920,947 |
|||
882,797 -> 882,966 |
|||
908,735 -> 908,910 |
|||
254,241 -> 348,335 |
|||
192,348 -> 192,364 |
|||
785,86 -> 662,209 |
|||
627,456 -> 911,740 |
|||
375,699 -> 375,897 |
|||
771,298 -> 98,971 |
|||
758,286 -> 735,286 |
|||
72,908 -> 72,189 |
|||
404,974 -> 545,833 |
|||
735,28 -> 48,28 |
|||
83,847 -> 476,847 |
|||
317,779 -> 811,285 |
|||
329,349 -> 990,349 |
|||
20,811 -> 816,811 |
|||
57,80 -> 906,929 |
|||
276,939 -> 276,98 |
|||
986,24 -> 24,986 |
|||
700,85 -> 700,111 |
|||
256,82 -> 900,82 |
|||
452,393 -> 195,393 |
|||
855,61 -> 187,729 |
|||
577,411 -> 577,852 |
|||
714,531 -> 714,698 |
|||
542,172 -> 549,172 |
|||
388,394 -> 164,170 |
|||
316,293 -> 331,308 |
|||
293,881 -> 293,981 |
|||
360,443 -> 720,803 |
|||
211,571 -> 656,126 |
|||
779,753 -> 636,896 |
|||
989,311 -> 337,963 |
|||
362,397 -> 362,716 |
|||
154,855 -> 154,91 |
|||
217,982 -> 217,942 |
|||
599,438 -> 599,399 |
|||
906,951 -> 906,146 |
|||
501,960 -> 457,960 |
|||
825,382 -> 13,382 |
|||
880,927 -> 874,927 |
|||
662,117 -> 662,428 |
|||
112,707 -> 659,160 |
|||
984,857 -> 356,229 |
|||
269,57 -> 269,220 |
|||
383,592 -> 916,592 |
|||
326,871 -> 982,871 |
|||
356,608 -> 826,608 |
|||
260,124 -> 260,128 |
|||
985,981 -> 15,11 |
|||
527,492 -> 470,492 |
|||
220,24 -> 520,324 |
|||
874,563 -> 562,251 |
|||
303,506 -> 737,940 |
|||
951,973 -> 69,91 |
|||
463,58 -> 127,394 |
|||
599,349 -> 599,528 |
|||
517,513 -> 654,513 |
|||
255,411 -> 255,325 |
|||
310,163 -> 582,435 |
|||
939,204 -> 939,466 |
|||
547,214 -> 490,214 |
|||
880,58 -> 880,442 |
|||
762,128 -> 549,128 |
|||
156,835 -> 556,835 |
|||
835,220 -> 717,220 |
|||
583,210 -> 583,117 |
|||
780,782 -> 250,252 |
|||
960,693 -> 781,872 |
|||
101,699 -> 665,699 |
|||
939,528 -> 939,106 |
|||
566,671 -> 512,671 |
|||
852,883 -> 852,871 |
|||
483,644 -> 835,644 |
|||
619,954 -> 401,736 |
|||
267,406 -> 133,406 |
|||
207,792 -> 748,251 |
|||
920,544 -> 41,544 |
|||
725,224 -> 290,659 |
|||
716,508 -> 903,321 |
|||
277,684 -> 444,517 |
|||
964,11 -> 15,960 |
|||
488,66 -> 488,118 |
|||
587,211 -> 587,728 |
|||
987,28 -> 780,28 |
|||
307,334 -> 717,334 |
|||
96,217 -> 96,680 |
|||
521,834 -> 519,834 |
|||
242,193 -> 78,357 |
|||
760,583 -> 909,434 |
|||
855,915 -> 894,876 |
|||
739,878 -> 782,835 |
|||
406,780 -> 375,780 |
|||
244,788 -> 244,512 |
|||
837,829 -> 454,446 |
|||
685,819 -> 709,819 |
|||
909,980 -> 198,269 |
|||
283,766 -> 283,11 |
|||
178,13 -> 178,473 |
|||
675,372 -> 675,366 |
|||
285,186 -> 285,329 |
|||
771,401 -> 351,821 |
|||
473,397 -> 473,719 |
|||
973,20 -> 10,983 |
|||
201,223 -> 750,223 |
|||
945,354 -> 312,987 |
|||
886,571 -> 847,571 |
|||
821,957 -> 821,545 |
|||
87,703 -> 660,130 |
|||
955,699 -> 733,477 |
|||
575,310 -> 523,310 |
|||
836,287 -> 836,948 |
|||
820,713 -> 536,713 |
|||
947,35 -> 947,308 |
|||
835,285 -> 835,186 |
|||
57,928 -> 927,58 |
|||
622,798 -> 622,745 |
|||
945,99 -> 624,99 |
|||
315,568 -> 315,853 |
|||
893,587 -> 893,540 |
|||
240,58 -> 240,84 |
|||
57,284 -> 57,521 |
|||
24,930 -> 818,136 |
|||
949,778 -> 949,829 |
|||
922,923 -> 25,26 |
|||
349,508 -> 349,46 |
|||
975,178 -> 65,178 |
|||
398,768 -> 534,768 |
|||
456,223 -> 948,715 |
|||
104,102 -> 104,42 |
|||
622,727 -> 622,702 |
|||
319,379 -> 319,443 |
|||
584,355 -> 584,151 |
|||
707,357 -> 707,80 |
|||
977,90 -> 302,90 |
|||
215,359 -> 215,670 |
|||
541,657 -> 407,657 |
|||
292,646 -> 292,163 |
|||
194,831 -> 909,831 |
|||
191,227 -> 134,227 |
|||
313,405 -> 651,405 |
|||
154,125 -> 154,467 |
|||
437,899 -> 895,899 |
|||
388,815 -> 388,444 |
|||
713,823 -> 713,131 |
|||
454,810 -> 381,810 |
|||
981,163 -> 981,909 |
|||
224,397 -> 759,932 |
|||
320,85 -> 681,85 |
|||
887,147 -> 844,190 |
|||
355,564 -> 355,386 |
|||
888,152 -> 716,324 |
|||
14,36 -> 846,868 |
|||
297,133 -> 679,133 |
|||
563,541 -> 563,45 |
|||
262,209 -> 967,914 |
|||
181,740 -> 181,651 |
|||
958,541 -> 624,875 |
|||
720,930 -> 720,572 |
|||
85,943 -> 347,943 |
|||
67,736 -> 855,736 |
|||
980,249 -> 412,249 |
|||
726,546 -> 726,679 |
|||
241,633 -> 241,843 |
|||
468,164 -> 468,590 |
|||
148,937 -> 870,215 |
|||
399,706 -> 127,706 |
|||
716,934 -> 59,934 |
|||
24,55 -> 679,710 |
|||
148,271 -> 148,709 |
|||
807,48 -> 940,48 |
|||
606,168 -> 606,643 |
|||
756,359 -> 521,594 |
|||
100,199 -> 37,136 |
|||
20,29 -> 980,989 |
|||
37,41 -> 255,41 |
|||
368,823 -> 302,823 |
@ -0,0 +1,10 @@ |
|||
0,9 -> 5,9 |
|||
8,0 -> 0,8 |
|||
9,4 -> 3,4 |
|||
2,2 -> 2,1 |
|||
7,0 -> 7,4 |
|||
6,4 -> 2,0 |
|||
0,9 -> 2,9 |
|||
3,4 -> 1,4 |
|||
0,0 -> 8,8 |
|||
5,5 -> 8,2 |
@ -0,0 +1,50 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys |
|||
from copy import deepcopy |
|||
|
|||
def sim(lf, days): |
|||
nf = {} |
|||
for i in range(days): |
|||
for k,v in lf.items(): |
|||
if k == 7: |
|||
nf[6] = (nf[6] + v) if 6 in nf else v |
|||
elif k == 6: |
|||
nf[5] = v |
|||
elif k == 0: |
|||
nf[8] = v |
|||
nf[6] = (nf[6] + v) if 6 in nf else v |
|||
else: |
|||
nf[k-1] = v |
|||
lf = deepcopy(nf) |
|||
nf = {} |
|||
return sum(lf.values()) |
|||
|
|||
if __name__ == '__main__': |
|||
lines = open(sys.argv[1]).read().strip('\n\n').split('\n') # or split \n\n or sth similar |
|||
nums = [int(i) for i in lines[0].split(",")] |
|||
|
|||
lf1 = {} |
|||
|
|||
lf1[6] = 0 |
|||
lf1[7] = 0 |
|||
lf1[8] = 0 |
|||
|
|||
for n in nums: |
|||
if n not in lf1: |
|||
lf1[n] = 1 |
|||
else: |
|||
lf1[n] += 1 |
|||
|
|||
lf2 = deepcopy(lf1) |
|||
|
|||
|
|||
|
|||
# challenge 1 |
|||
res1 = str(sim(lf1, 80)) |
|||
print("challenge 1:" +"\n" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
res2 = str(sim(lf2, 256)) |
|||
print("challenge 2:" +"\n" + res2 + "\n") |
|||
|
@ -0,0 +1,66 @@ |
|||
--- Day 6: Lanternfish --- |
|||
|
|||
The sea floor is getting steeper. Maybe the sleigh keys got carried this way? |
|||
|
|||
A massive school of glowing lanternfish swims past. They must spawn quickly to reach such large numbers - maybe exponentially quickly? You should model their growth rate to be sure. |
|||
|
|||
Although you know nothing about this specific species of lanternfish, you make some guesses about their attributes. Surely, each lanternfish creates a new lanternfish once every 7 days. |
|||
|
|||
However, this process isn't necessarily synchronized between every lanternfish - one lanternfish might have 2 days left until it creates another lanternfish, while another might have 4. So, you can model each fish as a single number that represents the number of days until it creates a new lanternfish. |
|||
|
|||
Furthermore, you reason, a new lanternfish would surely need slightly longer before it's capable of producing more lanternfish: two more days for its first cycle. |
|||
|
|||
So, suppose you have a lanternfish with an internal timer value of 3: |
|||
|
|||
After one day, its internal timer would become 2. |
|||
After another day, its internal timer would become 1. |
|||
After another day, its internal timer would become 0. |
|||
After another day, its internal timer would reset to 6, and it would create a new lanternfish with an internal timer of 8. |
|||
After another day, the first lanternfish would have an internal timer of 5, and the second lanternfish would have an internal timer of 7. |
|||
|
|||
A lanternfish that creates a new fish resets its timer to 6, not 7 (because 0 is included as a valid timer value). The new lanternfish starts with an internal timer of 8 and does not start counting down until the next day. |
|||
|
|||
Realizing what you're trying to do, the submarine automatically produces a list of the ages of several hundred nearby lanternfish (your puzzle input). For example, suppose you were given the following list: |
|||
|
|||
3,4,3,1,2 |
|||
|
|||
This list means that the first fish has an internal timer of 3, the second fish has an internal timer of 4, and so on until the fifth fish, which has an internal timer of 2. Simulating these fish over several days would proceed as follows: |
|||
|
|||
Initial state: 3,4,3,1,2 |
|||
After 1 day: 2,3,2,0,1 |
|||
After 2 days: 1,2,1,6,0,8 |
|||
After 3 days: 0,1,0,5,6,7,8 |
|||
After 4 days: 6,0,6,4,5,6,7,8,8 |
|||
After 5 days: 5,6,5,3,4,5,6,7,7,8 |
|||
After 6 days: 4,5,4,2,3,4,5,6,6,7 |
|||
After 7 days: 3,4,3,1,2,3,4,5,5,6 |
|||
After 8 days: 2,3,2,0,1,2,3,4,4,5 |
|||
After 9 days: 1,2,1,6,0,1,2,3,3,4,8 |
|||
After 10 days: 0,1,0,5,6,0,1,2,2,3,7,8 |
|||
After 11 days: 6,0,6,4,5,6,0,1,1,2,6,7,8,8,8 |
|||
After 12 days: 5,6,5,3,4,5,6,0,0,1,5,6,7,7,7,8,8 |
|||
After 13 days: 4,5,4,2,3,4,5,6,6,0,4,5,6,6,6,7,7,8,8 |
|||
After 14 days: 3,4,3,1,2,3,4,5,5,6,3,4,5,5,5,6,6,7,7,8 |
|||
After 15 days: 2,3,2,0,1,2,3,4,4,5,2,3,4,4,4,5,5,6,6,7 |
|||
After 16 days: 1,2,1,6,0,1,2,3,3,4,1,2,3,3,3,4,4,5,5,6,8 |
|||
After 17 days: 0,1,0,5,6,0,1,2,2,3,0,1,2,2,2,3,3,4,4,5,7,8 |
|||
After 18 days: 6,0,6,4,5,6,0,1,1,2,6,0,1,1,1,2,2,3,3,4,6,7,8,8,8,8 |
|||
|
|||
Each day, a 0 becomes a 6 and adds a new 8 to the end of the list, while each other number decreases by 1 if it was present at the start of the day. |
|||
|
|||
In this example, after 18 days, there are a total of 26 fish. After 80 days, there would be a total of 5934. |
|||
|
|||
Find a way to simulate lanternfish. How many lanternfish would there be after 80 days? |
|||
|
|||
Your puzzle answer was 362666. |
|||
--- Part Two --- |
|||
|
|||
Suppose the lanternfish live forever and have unlimited food and space. Would they take over the entire ocean? |
|||
|
|||
After 256 days in the example above, there would be a total of 26984457539 lanternfish! |
|||
|
|||
How many lanternfish would there be after 256 days? |
|||
|
|||
Your puzzle answer was 1640526601595. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
@ -0,0 +1 @@ |
|||
2,4,1,5,1,3,1,1,5,2,2,5,4,2,1,2,5,3,2,4,1,3,5,3,1,3,1,3,5,4,1,1,1,1,5,1,2,5,5,5,2,3,4,1,1,1,2,1,4,1,3,2,1,4,3,1,4,1,5,4,5,1,4,1,2,2,3,1,1,1,2,5,1,1,1,2,1,1,2,2,1,4,3,3,1,1,1,2,1,2,5,4,1,4,3,1,5,5,1,3,1,5,1,5,2,4,5,1,2,1,1,5,4,1,1,4,5,3,1,4,5,1,3,2,2,1,1,1,4,5,2,2,5,1,4,5,2,1,1,5,3,1,1,1,3,1,2,3,3,1,4,3,1,2,3,1,4,2,1,2,5,4,2,5,4,1,1,2,1,2,4,3,3,1,1,5,1,1,1,1,1,3,1,4,1,4,1,2,3,5,1,2,5,4,5,4,1,3,1,4,3,1,2,2,2,1,5,1,1,1,3,2,1,3,5,2,1,1,4,4,3,5,3,5,1,4,3,1,3,5,1,3,4,1,2,5,2,1,5,4,3,4,1,3,3,5,1,1,3,5,3,3,4,3,5,5,1,4,1,1,3,5,5,1,5,4,4,1,3,1,1,1,1,3,2,1,2,3,1,5,1,1,1,4,3,1,1,1,1,1,1,1,1,1,2,1,1,2,5,3 |
@ -0,0 +1 @@ |
|||
3,4,3,1,2 |
@ -0,0 +1,27 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys |
|||
|
|||
|
|||
def fuel(crabs, x): |
|||
return sum(abs(c-x) for c in crabs) |
|||
|
|||
def fuel_incr(crabs, x): |
|||
return sum(sc[abs(c-x)] for c in crabs) |
|||
|
|||
if __name__ == '__main__': |
|||
lines = open(sys.argv[1]).read().strip('\n\n').split('\n') # or split \n\n or sth similar |
|||
nums = [int(i) for i in lines[0].split(",")] |
|||
|
|||
# challenge 1 |
|||
res1 = str(min(fuel(nums, i) for i in range(max(nums)))) |
|||
print("challenge 1:" +"\n" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
sc = [0] * (max(nums)+1) |
|||
for i in range(max(nums)+1): |
|||
sc[i] = sc[i-1] + i |
|||
|
|||
res2 = str(min(fuel_incr(nums, i) for i in range(max(nums)))) |
|||
print("challenge 2:" +"\n" + res2 + "\n") |
|||
|
@ -0,0 +1,62 @@ |
|||
--- Day 7: The Treachery of Whales --- |
|||
|
|||
A giant whale has decided your submarine is its next meal, and it's much faster than you are. There's nowhere to run! |
|||
|
|||
Suddenly, a swarm of crabs (each in its own tiny submarine - it's too deep for them otherwise) zooms in to rescue you! They seem to be preparing to blast a hole in the ocean floor; sensors indicate a massive underground cave system just beyond where they're aiming! |
|||
|
|||
The crab submarines all need to be aligned before they'll have enough power to blast a large enough hole for your submarine to get through. However, it doesn't look like they'll be aligned before the whale catches you! Maybe you can help? |
|||
|
|||
There's one major catch - crab submarines can only move horizontally. |
|||
|
|||
You quickly make a list of the horizontal position of each crab (your puzzle input). Crab submarines have limited fuel, so you need to find a way to make all of their horizontal positions match while requiring them to spend as little fuel as possible. |
|||
|
|||
For example, consider the following horizontal positions: |
|||
|
|||
16,1,2,0,4,2,7,1,2,14 |
|||
|
|||
This means there's a crab with horizontal position 16, a crab with horizontal position 1, and so on. |
|||
|
|||
Each change of 1 step in horizontal position of a single crab costs 1 fuel. You could choose any horizontal position to align them all on, but the one that costs the least fuel is horizontal position 2: |
|||
|
|||
Move from 16 to 2: 14 fuel |
|||
Move from 1 to 2: 1 fuel |
|||
Move from 2 to 2: 0 fuel |
|||
Move from 0 to 2: 2 fuel |
|||
Move from 4 to 2: 2 fuel |
|||
Move from 2 to 2: 0 fuel |
|||
Move from 7 to 2: 5 fuel |
|||
Move from 1 to 2: 1 fuel |
|||
Move from 2 to 2: 0 fuel |
|||
Move from 14 to 2: 12 fuel |
|||
|
|||
This costs a total of 37 fuel. This is the cheapest possible outcome; more expensive outcomes include aligning at position 1 (41 fuel), position 3 (39 fuel), or position 10 (71 fuel). |
|||
|
|||
Determine the horizontal position that the crabs can align to using the least fuel possible. How much fuel must they spend to align to that position? |
|||
|
|||
Your puzzle answer was 357353. |
|||
--- Part Two --- |
|||
|
|||
The crabs don't seem interested in your proposed solution. Perhaps you misunderstand crab engineering? |
|||
|
|||
As it turns out, crab submarine engines don't burn fuel at a constant rate. Instead, each change of 1 step in horizontal position costs 1 more unit of fuel than the last: the first step costs 1, the second step costs 2, the third step costs 3, and so on. |
|||
|
|||
As each crab moves, moving further becomes more expensive. This changes the best horizontal position to align them all on; in the example above, this becomes 5: |
|||
|
|||
Move from 16 to 5: 66 fuel |
|||
Move from 1 to 5: 10 fuel |
|||
Move from 2 to 5: 6 fuel |
|||
Move from 0 to 5: 15 fuel |
|||
Move from 4 to 5: 1 fuel |
|||
Move from 2 to 5: 6 fuel |
|||
Move from 7 to 5: 3 fuel |
|||
Move from 1 to 5: 10 fuel |
|||
Move from 2 to 5: 6 fuel |
|||
Move from 14 to 5: 45 fuel |
|||
|
|||
This costs a total of 168 fuel. This is the new cheapest possible outcome; the old alignment position (2) now costs 206 fuel instead. |
|||
|
|||
Determine the horizontal position that the crabs can align to using the least fuel possible so they can make you an escape route! How much fuel must they spend to align to that position? |
|||
|
|||
Your puzzle answer was 104822130. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
@ -0,0 +1 @@ |
|||
1101,1,29,67,1102,0,1,65,1008,65,35,66,1005,66,28,1,67,65,20,4,0,1001,65,1,65,1106,0,8,99,35,67,101,99,105,32,110,39,101,115,116,32,112,97,115,32,117,110,101,32,105,110,116,99,111,100,101,32,112,114,111,103,114,97,109,10,601,578,981,315,530,525,671,1501,616,214,724,1247,543,58,183,282,242,54,90,130,1788,360,1719,710,1165,1476,29,744,164,293,1360,274,47,119,16,387,134,547,72,48,77,416,863,39,65,144,500,678,430,160,1689,550,753,1478,480,56,583,85,206,93,335,990,174,276,1119,52,308,470,563,387,897,21,85,720,983,178,383,134,299,722,57,391,489,768,232,646,1312,1316,31,57,927,176,531,421,1162,369,934,7,172,237,340,169,261,1371,1351,1268,72,58,375,1570,1238,55,513,403,1462,141,263,419,1316,852,251,39,358,209,204,439,150,1667,344,205,1299,1226,992,967,536,1160,1503,1154,1323,486,1079,329,823,506,1252,387,28,69,649,296,233,62,219,344,464,1284,291,234,47,949,1126,935,1367,1450,1431,379,344,478,731,648,77,184,927,211,262,728,1093,381,140,239,332,1436,78,665,1486,601,1444,364,1057,753,488,127,1001,350,1016,357,638,309,40,333,136,655,779,821,414,275,140,149,185,445,1169,476,196,907,1570,193,161,43,204,1489,1125,1024,101,17,592,1378,338,1625,3,269,1568,254,803,25,776,109,52,291,1595,255,739,34,768,378,632,4,181,373,162,562,74,85,160,16,47,38,266,1610,9,7,1398,358,287,450,188,1390,37,98,80,685,1645,50,55,16,542,20,443,848,49,808,76,233,69,110,471,73,408,638,89,861,280,1062,75,314,808,237,96,401,57,48,1306,115,1164,1533,5,1032,1314,66,630,96,496,116,1558,438,13,182,1360,802,101,327,370,444,335,812,430,900,1259,1117,318,118,433,501,401,101,582,27,454,981,776,14,26,163,384,1652,87,788,474,588,155,845,207,33,200,622,840,1360,432,11,525,86,296,481,200,529,95,924,431,40,846,220,285,14,66,755,111,647,643,1201,81,483,555,125,426,1499,29,115,48,39,92,316,434,217,218,116,9,33,496,358,1106,736,1181,1153,117,20,1719,1113,1620,26,581,407,114,1559,6,1918,964,909,340,630,817,473,111,1485,434,262,1702,651,11,182,1043,1904,633,336,252,677,1238,637,1008,82,327,171,185,19,141,395,1209,53,798,836,1378,598,262,298,265,287,85,21,249,848,162,89,1050,108,34,41,25,291,918,28,1234,139,351,867,146,79,995,1173,635,24,31,81,214,1114,155,1256,159,206,586,426,452,650,1653,47,42,264,240,500,864,893,1308,1249,853,286,62,592,102,77,1082,91,120,625,211,978,319,655,200,152,86,396,52,308,1479,38,41,53,179,648,216,41,641,659,1556,226,1421,291,33,1461,1095,529,309,1100,314,1695,505,1200,150,946,53,124,139,1506,52,33,463,613,33,1264,386,678,563,564,318,273,912,60,31,150,1321,133,1333,302,1243,49,421,808,1399,555,195,611,268,39,1302,1154,92,664,117,92,124,332,561,1436,865,198,71,271,909,40,1185,664,251,422,306,122,814,158,1676,122,217,312,952,845,104,572,1796,392,651,176,714,44,757,111,56,489,333,738,369,304,1239,105,297,277,674,213,938,2,681,336,171,1252,166,88,489,273,260,565,231,319,1085,650,211,510,12,511,325,46,107,980,1136,16,95,308,935,514,469,20,44,209,345,467,1310,500,75,594,166,199,741,193,28,52,106,1437,366,575,1200,609,678,534,573,723,325,8,386,268,690,321,186,375,2,104,657,1341,601,175,0,745,146,508,180,426,811,7,215,300,86,25,372,233,900,276,1625,808,1941,510,234,813,131,334,58,783,992,236,244,174,609,1581,1767,204,187,208,1340,347,803,146,299,140,142,339,60,118,300,809,276,413,267,946,77,154,466,425,193,187,852,674,2,17,1006,1007,166,195,137,97,41,407,65,1072,20,789,311,1227,20,132,1536,995,194,506,635,115,1500,529,93,72,950,208,944,1177,476,207,1228,5,974,226,225,290,690,581,218,401,49,361,1408,242,254,24,313,441,635,126,513,994,299,1722,52,1123,44,1332,628,534,789,298,692,45,596,1583,77,15,38,1293,1181,1498,772,148,297,49,692,87,594,49,148,170,54,1079,7,468,847,336,421,34,1108,406,892,689,245,298,85,1187,1142,286,310,207,34,660,549,39,1172,97,1,750,47,0,77,1632,135,54,18,22,1292,230,1031,11,225,820,461,1208,108,1443,274,1134,41,287,166,274,1032,585,1491,75,549,1231,1314,443,212,395,386,698,58,644,395,81,905,366,233,716,656,799,643,1011,173,790,360,269,930,13,606,488,387,1206,51 |
@ -0,0 +1 @@ |
|||
16,1,2,0,4,2,7,1,2,14 |
@ -0,0 +1,47 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys |
|||
|
|||
def search_num(d, val): |
|||
for k,v in d.items(): |
|||
if val == v: |
|||
return str(k) |
|||
|
|||
def decode(inp, out): |
|||
nums = {} |
|||
for i in sorted(inp, key=len): |
|||
if len(i) == 2: nums[1] = set(i) |
|||
elif len(i) == 3: nums[7] = set(i) |
|||
elif len(i) == 4: nums[4] = set(i) |
|||
elif len(i) == 5: #2, 3, 5 |
|||
if nums[1] <= set(i): nums[3] = set(i) |
|||
elif len(i) == 6: #0, 6, 9 |
|||
if nums[4] <= set(i): nums[9] = set(i) |
|||
elif nums[1] <= set(i): nums[0] = set(i) |
|||
else: nums[6] = set(i) |
|||
elif len(i) == 7: nums[8] = set(i) |
|||
for i in inp: |
|||
if set(i) not in nums.values(): |
|||
if set(i) <= nums[6]: nums[5] = set(i) |
|||
else: nums[2] = set(i) |
|||
return int(''.join([search_num(nums, set(o)) for o in out])) |
|||
|
|||
if __name__ == '__main__': |
|||
lines = open(sys.argv[1]).read().strip('\n\n').split('\n') # or split \n\n or sth similar |
|||
inp = [i.split(' | ') for i in lines] |
|||
inout = [(i[0].split(' '), i[1].split(' ')) for i in inp] |
|||
|
|||
# challenge 1 |
|||
sums = 0 |
|||
for _,out in inout: |
|||
for o in out: |
|||
if len(o) == 2 or len(o) == 3 or len(o) == 4 or len(o) == 7: |
|||
sums += 1 |
|||
|
|||
res1 = str(sums) |
|||
print("challenge 1:" +"\n" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
res2 = str(sum([decode(i,o) for i,o in inout])) |
|||
print("challenge 2:" +"\n" + res2 + "\n") |
|||
|
@ -0,0 +1,132 @@ |
|||
--- Day 8: Seven Segment Search --- |
|||
|
|||
You barely reach the safety of the cave when the whale smashes into the cave mouth, collapsing it. Sensors indicate another exit to this cave at a much greater depth, so you have no choice but to press on. |
|||
|
|||
As your submarine slowly makes its way through the cave system, you notice that the four-digit seven-segment displays in your submarine are malfunctioning; they must have been damaged during the escape. You'll be in a lot of trouble without them, so you'd better figure out what's wrong. |
|||
|
|||
Each digit of a seven-segment display is rendered by turning on or off any of seven segments named a through g: |
|||
|
|||
0: 1: 2: 3: 4: |
|||
aaaa .... aaaa aaaa .... |
|||
b c . c . c . c b c |
|||
b c . c . c . c b c |
|||
.... .... dddd dddd dddd |
|||
e f . f e . . f . f |
|||
e f . f e . . f . f |
|||
gggg .... gggg gggg .... |
|||
|
|||
5: 6: 7: 8: 9: |
|||
aaaa aaaa aaaa aaaa aaaa |
|||
b . b . . c b c b c |
|||
b . b . . c b c b c |
|||
dddd dddd .... dddd dddd |
|||
. f e f . f e f . f |
|||
. f e f . f e f . f |
|||
gggg gggg .... gggg gggg |
|||
|
|||
So, to render a 1, only segments c and f would be turned on; the rest would be off. To render a 7, only segments a, c, and f would be turned on. |
|||
|
|||
The problem is that the signals which control the segments have been mixed up on each display. The submarine is still trying to display numbers by producing output on signal wires a through g, but those wires are connected to segments randomly. Worse, the wire/segment connections are mixed up separately for each four-digit display! (All of the digits within a display use the same connections, though.) |
|||
|
|||
So, you might know that only signal wires b and g are turned on, but that doesn't mean segments b and g are turned on: the only digit that uses two segments is 1, so it must mean segments c and f are meant to be on. With just that information, you still can't tell which wire (b/g) goes to which segment (c/f). For that, you'll need to collect more information. |
|||
|
|||
For each display, you watch the changing signals for a while, make a note of all ten unique signal patterns you see, and then write down a single four digit output value (your puzzle input). Using the signal patterns, you should be able to work out which pattern corresponds to which digit. |
|||
|
|||
For example, here is what you might see in a single entry in your notes: |
|||
|
|||
acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab | |
|||
cdfeb fcadb cdfeb cdbaf |
|||
|
|||
(The entry is wrapped here to two lines so it fits; in your notes, it will all be on a single line.) |
|||
|
|||
Each entry consists of ten unique signal patterns, a | delimiter, and finally the four digit output value. Within an entry, the same wire/segment connections are used (but you don't know what the connections actually are). The unique signal patterns correspond to the ten different ways the submarine tries to render a digit using the current wire/segment connections. Because 7 is the only digit that uses three segments, dab in the above example means that to render a 7, signal lines d, a, and b are on. Because 4 is the only digit that uses four segments, eafb means that to render a 4, signal lines e, a, f, and b are on. |
|||
|
|||
Using this information, you should be able to work out which combination of signal wires corresponds to each of the ten digits. Then, you can decode the four digit output value. Unfortunately, in the above example, all of the digits in the output value (cdfeb fcadb cdfeb cdbaf) use five segments and are more difficult to deduce. |
|||
|
|||
For now, focus on the easy digits. Consider this larger example: |
|||
|
|||
be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | |
|||
fdgacbe cefdb cefbgd gcbe |
|||
edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | |
|||
fcgedb cgb dgebacf gc |
|||
fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef | |
|||
cg cg fdcagb cbg |
|||
fbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega | |
|||
efabcd cedba gadfec cb |
|||
aecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga | |
|||
gecf egdcabf bgf bfgea |
|||
fgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf | |
|||
gebdcfa ecba ca fadegcb |
|||
dbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf | |
|||
cefg dcbef fcge gbcadfe |
|||
bdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd | |
|||
ed bcgafe cdgba cbgef |
|||
egadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg | |
|||
gbdfcae bgc cg cgb |
|||
gcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc | |
|||
fgae cfgab fg bagce |
|||
|
|||
Because the digits 1, 4, 7, and 8 each use a unique number of segments, you should be able to tell which combinations of signals correspond to those digits. Counting only digits in the output values (the part after | on each line), in the above example, there are 26 instances of digits that use a unique number of segments (highlighted above). |
|||
|
|||
In the output values, how many times do digits 1, 4, 7, or 8 appear? |
|||
|
|||
Your puzzle answer was 504. |
|||
--- Part Two --- |
|||
|
|||
Through a little deduction, you should now be able to determine the remaining digits. Consider again the first example above: |
|||
|
|||
acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab | |
|||
cdfeb fcadb cdfeb cdbaf |
|||
|
|||
After some careful analysis, the mapping between signal wires and segments only make sense in the following configuration: |
|||
|
|||
dddd |
|||
e a |
|||
e a |
|||
ffff |
|||
g b |
|||
g b |
|||
cccc |
|||
|
|||
So, the unique signal patterns would correspond to the following digits: |
|||
|
|||
acedgfb: 8 |
|||
cdfbe: 5 |
|||
gcdfa: 2 |
|||
fbcad: 3 |
|||
dab: 7 |
|||
cefabd: 9 |
|||
cdfgeb: 6 |
|||
eafb: 4 |
|||
cagedb: 0 |
|||
ab: 1 |
|||
|
|||
Then, the four digits of the output value can be decoded: |
|||
|
|||
cdfeb: 5 |
|||
fcadb: 3 |
|||
cdfeb: 5 |
|||
cdbaf: 3 |
|||
|
|||
Therefore, the output value for this entry is 5353. |
|||
|
|||
Following this same process for each entry in the second, larger example above, the output value of each entry can be determined: |
|||
|
|||
fdgacbe cefdb cefbgd gcbe: 8394 |
|||
fcgedb cgb dgebacf gc: 9781 |
|||
cg cg fdcagb cbg: 1197 |
|||
efabcd cedba gadfec cb: 9361 |
|||
gecf egdcabf bgf bfgea: 4873 |
|||
gebdcfa ecba ca fadegcb: 8418 |
|||
cefg dcbef fcge gbcadfe: 4548 |
|||
ed bcgafe cdgba cbgef: 1625 |
|||
gbdfcae bgc cg cgb: 8717 |
|||
fgae cfgab fg bagce: 4315 |
|||
|
|||
Adding all of the output values in this larger example produces 61229. |
|||
|
|||
For each entry, determine all of the wire/segment connections and decode the four-digit output values. What do you get if you add up all of the output values? |
|||
|
|||
Your puzzle answer was 1073431. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
@ -0,0 +1,200 @@ |
|||
bcedagf ebadf gcdfe gfcead bcedgf dfeca ac dgca ace cafbge | ecfdbag gecfd feadb degacbf |
|||
gab cebfag bdfg gaefd bg debga gadbef dbafgce gdafec cadbe | befdga fgdaec gdaecf bdecgaf |
|||
feabcg eacd cdbeg cfgbda dgefb cbgefad ceb dbagc ce gadbec | ec ceb aecd daec |
|||
acdbf ebfa fagdec ef bcged edcfba gcedafb facgdb ebcfd ecf | fe fce gfcdab fe |
|||
bcg eacfbg daebgfc cfabd gbfaed degfcb gc cdeg cbdfg egfdb | fbgcaed edbfg aedgbcf cg |
|||
gdbaf cefgd egdaf deab afe egcbaf afgcbd efbdga ae ecbdagf | ea deab baed ebcgfa |
|||
ecadfgb dacbfe bgedfc afebc abf dbcef ecgab adef cfgbda fa | efad baf fab af |
|||
gaefcd dgbcef fdbeac cgfab ad dca ebcdf fbdecga dbcfa beda | ad dbefc fgecad edba |
|||
egfa dcgbfe ag gac fcdbage cebag gebafc gfebc gdabfc caebd | ag bgace gefa bgfced |
|||
dfbage fedcba ga gae bcegda fagb gcedf edfag adfeb geabdfc | ga gcfde ag facdebg |
|||
ebcfad agcfbe de cfbae degcaf ebdc bcadfeg fdabe gbfad ead | decfga dbgacef daecfbg dae |
|||
cdaegb ced gdfbe bdecfa caefbdg bcdeg gabcd gaec ec bacfdg | agec degafcb cde acbdg |
|||
bcadgf bgecfd abcgfe cd acgbd fedbagc gdeba afcd abfcg cdg | dc dbacefg befcadg dgfaecb |
|||
afcbed gdfaecb bfdec dbafe fc fcda fgabce gdefba bdecg cfe | fcda fagedb fc egdcb |
|||
bdecf dgcbe befcdg bef fgbc gcaebfd bgaecd caedf fb dfabeg | dbfceg fb bfe efb |
|||
bge gedabc fdeacbg dagfec feacg gcdbf eb aebf fcaegb fgceb | gbe beg gafce be |
|||
efdbcga egfba dafcge eacb acbfg ae edbgf bgfcea dcfgba gae | agbef fcagb bafge fabcg |
|||
fcbdg fdgcea dfcgaeb dfgac fdcgab ecbgad gb edcbf afgb gbc | cafbged ebfcdga bdcfg gcb |
|||
ceb cdefag be ebfcg agecf degfbca egbfca gaeb abecdf fcgdb | gebfc acgbefd aedfbc dfcbae |
|||
bfegd bdgea fd bfcge gfabcd fdg dcgeafb ebgdcf gebfac ecdf | degfb fedbg efgcb fced |
|||
dcfabe bcga fgbed ag aecfgb cdegfa baefg aeg eabfc agedbfc | ega aeg ag cebdgfa |
|||
fgade eaf abfgd fe abcfeg cfde efcdga dbeafgc daegc acdegb | gadbfec aef fae cdgea |
|||
abe debc cdagb agedb gebcfa eadbfgc bacegd gdefa be fcabgd | gdbacfe fagde dgbace acfgdb |
|||
fea gabdf ea beacfg cgdfae cabe cgebadf cdefbg ebgaf gefcb | edfacg fae ceba efa |
|||
ed fecba bfcdae aefcd ecabdg fcagd begdafc bedf ced gafcbe | dbceaf ced ced ced |
|||
abfgc gfbcae fbace gdeabf fae bdgcfa edcab acebfdg gcfe ef | aef fe fbdcga dfaebcg |
|||
ac eac dgebcf bcaef begcf cgab cdbgeaf agdcef ebfgac bedaf | dfcaeg bgeadfc bgcafe fgbce |
|||
afdbc bgecadf gfecad dca ac aebc dfceba ebfdgc gfdab cdfbe | acbe dac cedafg ca |
|||
fadcb efc baedcf fdbge aedc ce dgaefcb cgfbda dbcfe geacfb | ce ce gbcdefa dace |
|||
fcbea ebd cbdg ceafdg cdgabe dbeagf bd ecdba fcgedba egdca | ecadbgf gdeac bd acdfge |
|||
fbd gcdafb fb bcdea aefgd fcgedab gecdab febad becf fcdeab | badef ceadb bdgacfe afdcebg |
|||
dcgfbe cgdefa fc adcf bdeagc gcead cabefdg ecf fegac egfab | gecfadb afecg dcaf bfcgade |
|||
fbgdce acge fbegc ecfbadg cfa cdbfea bgfad bafcg cgafeb ac | ac efdcba agdfb fecbad |
|||
edg efdgca edba bdegf cafgedb faebdg ed fgecab fgbea bdfgc | eagdfbc cgdbf geafcb gefdcba |
|||
gcaedb fgedcba cfbgae fgc gcfde gefdb cfaged cf dafc dgcae | gcf fgeabc bdcgea acfd |
|||
bgecdfa bgedaf dbfa cgefda db efgad gdb agbde egbcdf aegbc | dbegfc dgb bdg cgdebf |
|||
egacbfd gecfba ecd acfgd degb fbadec de efgcd cfdbeg fbgec | egbcfa cfabdge ebgd ed |
|||
ecgdb ebdfc fagdbe fe afce afgdbc bdcaef cbegdfa abfcd dfe | caefbd ef fe bfdce |
|||
egadf cd gfdace acebf ecd cefbgd fdeca gfbdae gadc dbegcaf | fdagbe adgc gdeaf dafcegb |
|||
cgdfb eabfg abd deafbg dbcega afde bfgda fdeacbg ad fbeagc | fdgeabc feagcdb gafedbc da |
|||
bdega dbace fbecd bdfgaec feadbc bfca cda ac edgfac becdgf | ac ca cad bfca |
|||
gacef bgcae fgdceab gef fgbade abdecg fgabce cdaef bgfc gf | bfagedc cbfg adbgec bgfc |
|||
agcbd eagd abgdefc gec bceaf cbdgfe gfdacb baegdc acbge ge | egc ge gade ecg |
|||
cbgda egcad acbged gb bfcad acgfedb ebcfag gdeb cbg fdacge | gadfce edgb cgfabe adbecg |
|||
fgcaeb gcbdf dbfagec fgcae da gacdef aedc adf gadfc fegabd | fagdc afbecg deca edac |
|||
abedfcg ca bedcf abefc eabfdc aegbf dfbegc dgabcf bac aecd | ecfabd ecbfa acde abc |
|||
dag fedag cdeabg dg fdeca fgbae fdgc gadfce cdaebf eagbdfc | gd dcgaebf dgfc adg |
|||
aegbf cdga fcebad ecbag ac bca cbedga cfbgade gdbce fbdgec | geabc gadc ebgfacd gadc |
|||
aeg abde ea becdfg eadcg adcfg gaefcdb ebgfca acgdbe dcbge | ebad abde cedag ae |
|||
cfa eabfd eadfcb bface gdfbca gefbda ca eacd faebdgc cgbfe | efcgb cabdgf eagcfdb cfa |
|||
gfdeca fcabe agdbfec cde efdcb dfbaeg debgf cgebfd dc bdcg | ced bcfegd egbafd gcbd |
|||
db gfdbae gbfce fbdeg degfa fadecg abed gcfdba aegfdbc dgb | dgfbae db ecbgf daeb |
|||
fcdab gcfdab ebafgdc dg fgdc deafbc gbd aebcg dacgb gdfeba | adbcg gd ebgdfac gd |
|||
afg eagdcf bagfc fg gdbefca afcdb bcage dbcage ecafgb bgfe | gf aegcb gf gaf |
|||
fgc ecfb cbgeaf cf fgabe gdbecfa gedac bfgcda fcaeg debgaf | bfeag cbgefda gbaef abfeg |
|||
adcgfe gbfaed dcfbg fdeab fgdeb ebag ge fdgecba fadbec dge | gfcdb ge ged efadcb |
|||
cebgd bdfag bcgfd agfc dgfacb fecdab cf dafegb fdgeabc fcd | bacefd acgf cdf cfd |
|||
geabfd adf dfecbag agdefc ecdga acgfd fgcbd fa cedagb ecfa | bdgcfae fbgeda gdaec af |
|||
cdgabef gfeda dacegf agfdbe dafce aec bdfac efcgba ec cedg | eabdgf egbfad gdeacf ce |
|||
febd dab fbdca acdef db cafgb cebafdg bcfdea cagdbe fgacde | dbfe aedfc afcgb efdb |
|||
caebfg caegdb efbad da dgaf beafgd edfcb dgabcfe bad ebafg | dba dgfa ad efdbc |
|||
dbcef dgfab bcag cgd dcfbag gcdfb gedfba cg degfac dbgeafc | gcd cfebd fedcb cbag |
|||
cfbag cefagb dfaceb gb febca bdaefg cgeb fbg efcagdb gcfda | cgeb fbg abefdgc bg |
|||
cebgd geacb dbcgea dc dgc gfeacb bedgf cead cgadfb debfagc | ecad eacd dc eacbg |
|||
cbdgf fdacg fdbceg dafgcb acd gadb eacgf ad gaefbdc cedafb | dac dca cfage dgab |
|||
cgebfa bfedg fb bdgfec gafed bdcf bgedc feb aecgfbd bdcega | bdgcae bfdceg efb gebdc |
|||
cadg ac cfa acegfd efdac edgcf bafde afdcgbe egdcfb eagbfc | cfdegab dbcefg cbfgdea acdgef |
|||
baecdgf dacbfe ecf gbecad dbfcg cdgea gfae ef afdgce egfdc | aegf ef fe eafg |
|||
gc baefcd gfade agc ecgb cdgfab cegaf ebgfdca ecabf agefbc | gc bgfcea afcbe ecgb |
|||
ecfad efdab ba dgcafbe adgefb agdb fba egfbcd gecabf fgedb | bcgfed dfgbe dbag fba |
|||
bdgea ce ebdfcg fdgbc defcba abdcgf dbcgefa ecd gcbed cegf | ecd egcf efcdba agfbdc |
|||
fgcade bfgade bgfcea bfaegcd cfa fgcba fgabe gcbfd abec ca | ca cabe cdbgf dcegfba |
|||
aefgbc cedaf agbdcfe agecd fecba gdcfab fd ebcfda fbde cdf | cfagbed df aecfb fbcade |
|||
cgbfae fcdbga cgdfe abde gfdea deafgb afdgb ae cbgfead fae | afe afe becfagd ea |
|||
ec gfabed aceg dafgceb dec ebcgdf dabfc eagdfc dfcae gdfae | febcgad cgae caeg gabedfc |
|||
degacfb fcdgb befc fge edgca cbdfge aedgfb fegdc ef dgbcaf | egf gfe gecdabf gef |
|||
abfcg fgeab edfbca bfgadec eaf dbeag bdgaec ef efdg edafbg | aef ecdgba aef abefg |
|||
ecdfb cgedb ge adfbeg deg geca cdeabg abdcg afcbdg fgbdeca | ge fdebc deg bedfag |
|||
fbgdac dc adgc dcb caebdf cfgbd fbagc fgcaeb bgfde fbcaegd | cgda cbd dbc cd |
|||
fgecad dabfg def bcefg cabdgef daeb dbfega ed dbagcf ebfdg | dfe edcagfb bdae agbdfce |
|||
acbdfge gb cbdfea fecagb bfg bagdfe abedf agdb gbefd fdceg | febgd bg bg acefdbg |
|||
fbcgde efbg efdbc gec dafgc cgdfe agcebd fbceda ge gfadebc | fdebc egcfdab cbdeag ebfg |
|||
eadfgc cb dabfg adcegb gecfa bcgeaf acbfg fbec dcabgfe bcg | bgceda bc aecfbg gadecfb |
|||
fbade gbedfca fceadg cafed ebfcgd cgda cfa ac dfcge ebgfca | gdfceba feabd ca ac |
|||
adefgc fdgca abfdc dgc dabgcfe cg bgedaf geabdc fcge gfead | cadgf egcf cgef gc |
|||
dgcae da efcag dgaf gedafc dfabce gbefca ecgbd egdacbf ade | eda dfag aed agfd |
|||
gdcbf feac cbgeda gca faegdcb aegdf agbfed ca dcfag edgfca | aecf acedbfg aegbcdf bcgdf |
|||
bfdagc eb adgfceb edb dcbag eabg dgfbce dcefa abcged caebd | dbe bde dfacbg begfcad |
|||
ged dfecg dfgb gebcf fdbgec dg dcaef bfdgcae eagfbc gedbca | deg degcf fgbd acgbdef |
|||
bfgda acgefb cb decafg gcdae aebdgc acb ecdb cabgd bedgafc | dbce aefgcb edbc dfbcaeg |
|||
dabfge abdfg egbdac dfabc dcbfe ac daebfcg acb acgf afcgbd | cfag ac cagf cab |
|||
fbcea fdb edgcb afcebd cdfa fdebc gfeacb df aefbdg bdfgcae | bdf bdf df afegdbc |
|||
fdea gcadeb ef efcgab cfebd adbfce dgfcb feb decba adfgbec | gaebcdf dfecba dcbfg cbdfg |
|||
dgf gfadeb dabcgf bgcd fegca bcdaf cfeadb gd fdacg gdeacbf | gfd dbgc dg dg |
|||
fgace fbcge ac geadf acde fgdbea dfaebcg acdgbf cfgeda gca | ceafg bdfeagc ca agdfe |
|||
cdgbea fc efbdg bcedfga cfba dfc dagcfb fcdgb bagcd gdcefa | cf bgefd cf fegdb |
|||
efg afbdeg cbgdae ecgadfb cedagf abedg fagbe bacfe fg gbdf | egf fgbd gf egbaf |
|||
fgebca eafcb gdefb efbdc afgdbec cd dcb efacdb dcae bdfgac | cd eadc defgbca fcbadg |
|||
fg gbdec gdaebf cfadgb dcfab bfcdage bfg gfcdb fbcdea agcf | edgcfba fgca fcgbd aegbfd |
|||
fad bfecagd aecgd dabgcf adfeg feabg bdfaeg df dbfe fcagbe | edfb febacg dfbega fad |
|||
gfedacb gcabef bgcdfe fgabe dbgfae bgc gcae cbdaf cg gbcaf | gbc eagfbcd dfgeab gace |
|||
fbac fa defba efbcad dceab afe gbdeafc afcdeg dabecg gdbfe | eaf dgfbe dfegbca efbgd |
|||
fadgbc bcef afdce egbda adcgef bca dfcaeb eacdb cb cfdaegb | cdfbag becf bc fecb |
|||
fc cdgfeb cadeg efcbga aecfg bgfae fegbad dcgebfa fce afcb | fec adfcgbe efc fc |
|||
bgcf edbcg cdbfe acfdeb egdcbf dbgae efdbgca dcg gc efgcad | dgeacfb bedcg fgcb gc |
|||
fcb acdgf eadfcg abfgc ecgba cbagdf gdebfc fbda fb ebcfgad | cfgda cfagb bf dafcg |
|||
dabgfc bcagf gfdcea fegcb fa gdbca abdf dbcaeg bdgeafc fag | ecdfag adbf cafbdg cbadfge |
|||
gfacde bc gabdce cbdagef ceb acbf cfbeag cgfeb cgeaf gfbed | gbfce cb fcab gbecf |
|||
gcefd gf gfca gcdafe adebfg fdeac fecadb ecdbg fegdcba gfd | cfga gf acfgdbe fgd |
|||
cg bcdafg dgac cdgfb gefbd aecbdf cagfeb afedbcg bafcd cbg | bfadcge dfacebg dacg gc |
|||
fe abfe gcdbfea fgcdb fce bdceag cfgeb abcge egcbaf egfcda | agfebc bgace aefb abceg |
|||
dc cdg bedga bfacg gbcad gbecda dbfecga ecbd fdbgea dfaceg | gdbacfe fbgcaed cdafeg dc |
|||
abce ead aedgb dabgf ae cedbg cedgab bdfcage edbcgf fgedca | ae bace dea ae |
|||
bceg cfeag egdfca bcfage gb feabd dabgfc fedcgba ebfga gba | agb abedfgc gceb gceb |
|||
ac gbca cdabf fca agdbcfe fcadbg efgbad edcbf fdagb cafedg | cfa bacfd fgbad ca |
|||
ebcag degfba edcgbfa ecdab ceadbf dc dcef baefd agcfbd dcb | edfab bfeadgc acedb bdc |
|||
afgdcbe afdecb cafgdb abgfec afgcd ga gac cafdb abdg dcfeg | abdg bgcfae acg afebdcg |
|||
acdfb ed befdc adfcbg fdea ecd fgbdcea bagcde cegfb cfabed | de dce dcefab bcfge |
|||
ca dgac debacg fgcbea agedb fcdgeba bca ecfbd abcde feagdb | cgedab fbaecg faegdcb ac |
|||
ebdcfag bgcdea bface beadc edcgb da badg efdcgb cefadg ead | ead ad cebdag aedbc |
|||
fdeacgb bcgfda fbeag gebcaf adfeb cage fbcge agf ag bdgecf | ag adebf abecfdg ag |
|||
bgdca fgacbed cdfeb ecfg cfebda ebgdfc fgb gf fbgead gfdbc | gbf fdbce ebcafgd cedagfb |
|||
cgefad edbf fdc dgbec fabgc bfgcd bgfcade fd gbecad egcbfd | bgcfa febd dfc edcbg |
|||
efb edfba bcade cdbgae bcfa fcegbd agdfe bf afecdb agebfcd | fb abcf beagfdc ebf |
|||
egcd gbecad ed afdcb cbefag becag cdbae gacefbd beafgd ebd | bacdf dceg ed debgfa |
|||
gfbacde bfcd cd cebad ecdafb fecba gfcabe dce degcaf egadb | bgdcefa abcfge bfcd gbaecf |
|||
cdeaf cebafg afedg fcebdag gea dgabf ge aedcgf cdge fdecba | ge eg cegd degc |
|||
faedcg dfbc acegbfd eagbcd db eabcfd fbega cfaed adb edbfa | aedfc dfbc bd gacdfe |
|||
cbeadf gebfc age ag acedbg bgaec fgcadeb afdcge adgb ecbad | dcbfeag abdg dbga efbcg |
|||
gabd fdaecb gacbf dbcfg gfcae ba cba ecfgabd gdbcaf dfcbge | acb agdcfeb ecfga eagfc |
|||
gbcfd edbfc dgacbf cgb fgaedc gadcfbe bgaf ecagbd gb gdcfa | gbadce gcb gfdacbe cdgbeaf |
|||
fgeadc bedg bfcag cbdef fge eg edfcgba fdcbae ecdfgb bgfce | gfe eg fcbead eg |
|||
acegf gecfdab dacbfg afb ab fbaec aedb gcefbd ebcdfa bcfde | dgfbaec beafdc ba fgecbd |
|||
geabcdf egdb gb cfegab febgdc abfcd bgfcd gbf fcedg dcegaf | gafecbd gfb ebdg bg |
|||
cgefb fbagc ca abdc bgfcad bcefdga gdbaf edbafg cag feagcd | cgdafb badc adfbg acg |
|||
dbeg gd efcdag gabecdf cgd cdafb badcg edcbag gcabe agcbef | gcd dgc gcdba dgc |
|||
acgdf bcgeaf fd eagdfc dgcab dcafbeg fced gfd cegfa bdegaf | fd cedfag bcdga fgd |
|||
ef cbdae dgafce afe ebgf bafedg bacgdef agbfdc abdfe dgfab | bdefa fbge dabcgf fea |
|||
aefbdg cegadfb gcd dc dfaegc dcbaeg aegfd gecfd gcefb cafd | fegadc dgbcae cd cdg |
|||
bgdefc fabgec degbac aegdf abcge cdg adcb dagbefc eadgc dc | gdc cabd acebg cd |
|||
aebgc dbc dc acde agcdb fbcgeda cgbeda edfbcg ebfcga agfbd | gabce dbcga aecd ecda |
|||
deg eacgd ebdc bcdgae fdbgac afgbedc ed bcagd bdefga gfeac | badcg gbacd egbafcd bfdagc |
|||
fdega dca gfcba adgfc bcgd bgdcfa dc befcda gbafce bfgcead | agefdcb cabefgd dbaecf bdgc |
|||
abdc afecgb gbacfde dcfeg da agdce gbace fgadeb decbga dag | bcad cbda agbec adbc |
|||
beagfd cadef bfcae fcd fbgadc gdec gdcafeb gecdaf dc efagd | defac adgfeb agdcfbe bgcafed |
|||
eg bcfag gdecabf aecbfd gce dafecg gcbea dcebag gdeb bdace | badce ge eg cbdaegf |
|||
cfdgb dgbacef fa agf ceadbg efcbga efcgda afde adceg cagdf | agf gfa edfa agf |
|||
gbfcde edcfag dfg bdcgea cfedbag fcgba fd gafcd eadf cadge | bedagcf df dcafg eadgc |
|||
edfcab bdfca gfebdc acegdb dba dfae ad bcadgef bcfde fabgc | egbacdf ad dcebfag bdafc |
|||
acbfe afgd bgcaed acg bdeafcg ag dcbfge egfdca gefcd feagc | afgd dbgcef edgcf efcgd |
|||
dacgbe bgdc abdef bgead dag dg cebagf cgedaf aegcb fdegcab | cdbg adg gd dg |
|||
fg fcdgab abdfc deacgf fdabgec dgf dageb becdfa gbcf dgfab | dafcb agecdf adegbfc adbfc |
|||
cd ecgbf cgdf efbad bcadge gecdafb abcefg ecgbfd fedbc cbd | cgefb cdb fbecd cbd |
|||
afegdb gbafc bcafed dcbaeg efgd fe ecgbfda abgfe baegd eaf | egbad gfeab ebagf gbfae |
|||
bde fdebgac febgda cbea be adcefb fecdb dcgefa bfcgd caefd | fedbacg daefbg bed fbdce |
|||
eb ecb edacg acebfg cebagdf acdgfb cbega gefb agbfc eadcfb | fcagdb cbega be bcdafe |
|||
cefbgd gdaf dea ceagd cgedaf bgcfdea ad acbeg dbeacf ecgfd | dfecg agced dfag gceafd |
|||
da gedfc cafde bcagdef fad abde fbgaec badfgc daefcb aebcf | da bcfea ad dgeabcf |
|||
gdbeca gcadb facde afbdecg fg bagf cgdaf fgd cfebgd dagcfb | decabg gecdabf dagbc afbg |
|||
fbcdega febgcd df efcdg gbced dbefag aegfc cbgead fgd dbfc | dgabef cdfb dgf cgbefda |
|||
fbgaec acfgd gcdea cbedga acdfb dfeg gf aecfdg cbgfade cgf | gdfe gcf bcadeg fcg |
|||
fgced agfb faebcd gecabf eacgf ag ecfab aebdcg dfceagb cga | agc decgabf abegdfc agbdec |
|||
aecdbg cfeab cga fadceg adbeg cgbd ecabg gc dagfbec bdfaeg | beagd cag cfabe gca |
|||
afb gaefbc egbdf aedcb bdfae gbdace cbeadfg feacbd cafd fa | bcfaed gbadecf fa gbacfe |
|||
cbedg bgadef bag fadecbg ga fbcae fbdecg egcba dgac bdcage | ag febca cdebagf ebdgcfa |
|||
bcdaf adebgc ceb ebgdcf cfeagd agedc adecb eb gfdebca agbe | bcadf bdaecg facegd abcegd |
|||
afgbdce cagdfe dfb fdecb fb dabfge cbaf dcbfea gebcd fcdea | eafdcgb dbefc afebgd defca |
|||
dbfec abfecg fgced ceb dacfb dabe agefcbd gdacfb cfebad be | be cegdf gbcefad bdae |
|||
dbg bdagfc dgbfe cgebfd dbcaef ecbdf gfeab decg gcdebaf gd | cbeadf bdg aedfbc gdefbac |
|||
fcadgb bcf bgfcae cbfdeag face gfaebd cgbfe bcegd cf befag | abcgef bcf fbc cfebg |
|||
gefab db bda eafcd fcedbag cbedaf adfcgb ecdb acefgd fedba | db bfade ebdacf afebcd |
|||
dfbeacg cedagf dgfbc bgfda gdfea fab egbfad bage efcabd ab | agbfd bfa adfbgce fab |
|||
agfcd ecgabd bdgf egadfcb agf gf dfaec dgabc bfceag bacfgd | agf fag cfdea fdcgba |
|||
gebfdc fdae gbafc fdg dfagb aefdbg df baged ebfcdag acbedg | cfegbda bgfade daefbg abdecfg |
|||
gcdba gdefba ad dga deca cedgb cgbaf gdcbae gedfcba becgfd | gfabc ad fbcag dag |
|||
gefbd eagbdcf bfg bg aegb fbcde efdgac fgadcb efgad ebafdg | gbdfe bfedc cefagbd bdfce |
|||
gfedb cbegadf bcga fdcgea aecgbd bdcfea dgc bgcde abecd cg | befcad gedcfab bcedfa agbc |
|||
cedgfa efbdagc efdabc be baedgc bdfec fdgbc ceb dfcea afbe | eb afeb ebfa cbe |
|||
fedc fgbead dacgfe ec cagebf geacd dabcg ceg fgdea gdcbefa | ceagfb ecg dcef dcagfeb |
|||
aed agfbde bgfcda deafb fgae gcebdfa gdafb bfdec ae egabdc | ea dae agfe bcgadf |
|||
bdc cb gcbdf cgdebf adecgf gdefc dfcgaeb gadbf ebgadc cebf | fbce bfec dgcfe cfbe |
|||
fdecbg fdgac df fcgae dcf gcefdab aebcgf cdabg daef gefdac | fd ecbdfg edaf fade |
|||
cagebd bacfg egbdaf gc cgdf cbafe cbfdag cgb adbfg gecbfda | gbc adbgf gc bdecag |
|||
afed eag ecgbaf egdba egafbcd dbagc aebfdg dgebf gbfced ae | aedfgbc ea ea ega |
|||
eagfc gdbefc gf cgefda gfad adgbce dcgae aefcb egf fedabgc | adfcbge cdfega gaedbcf egcaf |
|||
bcage gbfadc dgfa abdcf cbafde bgfedc fbcga fbg fedbagc gf | fg fecdabg gf adfg |
|||
dcfge edfcbga defac febdag fdaecg ceag egd cfdgb eafbdc eg | cfdae fdceg efabdc egdafb |
|||
de bcdaf feagc fdeac gead aefcdgb afecgd cagbfe dce gbedcf | ed ed de deafc |
|||
cdaeg cb bafge fbcdea afbegc gbfc bca dgfebca gbadfe gebca | bfgae fcbg fbage cbfg |
|||
agf gdab bgcfe gfecda bafecgd dcefab afbeg baefdg febad ag | fbade eabcdf ga gadb |
|||
gcaf gfbec cbdega ebdacf cadgefb cf bgcaef edbfg fcb gcbae | bdfcega gdbfe fdbge fcb |
|||
afc gbace cbfd badfe fc faebc edabcf bafcdge eadgbf gdcaef | fc cf gbaefd fcbd |
|||
cdfage cdfebag eb cgaef cbgae ebgacf acgdb aeb ebcf agfdbe | cdbfega cebf ecfagd bcfe |
|||
afbdec dfegc dfga cedfga fgcebda edfca gf cdebg bcaegf gfe | efg cfgde dgaf fdga |
|||
ecfab eda da gefcad gcad aegcfdb dgbafe fegdc ebcfgd afecd | cegfad cefda ad caedf |
|||
gbedc gbadf bgafdce faed acdbgf agbedf fgecba ef egf efbdg | fbecga fe bgcdfea aegdbf |
|||
bagcdf dacbg fdbgcae dgbfa fa afd cfba gdcefa gabced fgedb | afd af fa bfca |
|||
fbgaed fbedg baed dcfgbe bga cfgda ebgcfa ba dbgeafc dafgb | aebgcf daeb ba ab |
|||
cdga feadgcb fbdeac ad dfbcge gcdef fda gedafc adegf eagbf | efagb fdcge faged fagebdc |
|||
ceafdb ga acfde acg egcafd cebfg febcgda dcgbaf egad fcega | ecagdbf gebcf cgfeadb cgbfda |
@ -0,0 +1,70 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys |
|||
|
|||
def risk_level(m, x, y): |
|||
adj = [] |
|||
if x-1 > -1: |
|||
adj.append(m[x-1][y]) |
|||
try: adj.append(m[x+1][y]) |
|||
except IndexError: pass |
|||
if y-1 > -1: |
|||
adj.append(m[x][y-1]) |
|||
try: adj.append(m[x][y+1]) |
|||
except IndexError: pass |
|||
|
|||
for a in adj: |
|||
if a <= m[x][y]: |
|||
return 0 |
|||
return m[x][y] + 1 |
|||
|
|||
def basin(m, x, y): |
|||
while (x,y) not in bas: |
|||
adj = {} |
|||
adj[(0,0)] = m[x][y] |
|||
if x-1 > -1: |
|||
adj[(-1,0)] = m[x-1][y] |
|||
try: adj[(1,0)] = m[x+1][y] |
|||
except IndexError: pass |
|||
if y-1 > -1: |
|||
adj[(0,-1)] = m[x][y-1] |
|||
try: adj[(0,1)] = m[x][y+1] |
|||
except IndexError: pass |
|||
|
|||
mi = min(adj.items(),key=lambda x: x[1]) |
|||
|
|||
x += mi[0][0] |
|||
y += mi[0][1] |
|||
bas[(x,y)] += 1 |
|||
|
|||
|
|||
if __name__ == '__main__': |
|||
lines = open(sys.argv[1]).read().strip('\n\n').split('\n') # or split \n\n or sth similar |
|||
mp = [[int(i) for i in l] for l in lines] |
|||
|
|||
bas = {} |
|||
risk = 0 |
|||
for x in range(len(mp)): |
|||
for y in range(len(mp[0])): |
|||
r = risk_level(mp, x, y) |
|||
risk += r |
|||
if r > 0: |
|||
bas[(x,y)] = 0 |
|||
|
|||
|
|||
for x in range(len(mp)): |
|||
for y in range(len(mp[0])): |
|||
if mp[x][y] != 9: |
|||
basin(mp, x, y) |
|||
|
|||
b = sorted(bas.values(), reverse=True) |
|||
|
|||
# challenge 1 |
|||
res1 = str(risk) |
|||
print("challenge 1:" +"\n" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
|
|||
res2 = str(b[0]*b[1]*b[2]) |
|||
print("challenge 2:" +"\n" + res2 + "\n") |
|||
|
@ -0,0 +1,44 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys |
|||
from operator import mul |
|||
from functools import reduce |
|||
|
|||
def adj(mp, x, y): |
|||
adj = {} |
|||
if x-1 > -1: adj[(-1,0)] = mp[x-1][y] |
|||
if x+1 < len(mp): adj[(1,0)] = mp[x+1][y] |
|||
if y-1 > -1: adj[(0,-1)] = mp[x][y-1] |
|||
if y+1 < len(mp[0]): adj[(0,1)] = mp[x][y+1] |
|||
return adj |
|||
|
|||
def risk(mp, x, y): |
|||
ad = adj(mp, x, y).values() |
|||
if all(map(lambda i: i > mp[x][y], ad)): |
|||
bas[(x,y)] = 0 |
|||
return mp[x][y] + 1 |
|||
else: return 0 |
|||
|
|||
def basin(mp, x, y): |
|||
nex = min(adj(mp, x, y).items(), key=lambda i: i[1]) |
|||
if (x,y) in bas: (i,j) = (x,y) |
|||
elif (x,y) in mem: (i,j) = mem[(x,y)] |
|||
else: |
|||
(i,j) = basin(mp, x+nex[0][0], y+nex[0][1]) |
|||
return (i,j) |
|||
bas[(i,j)] += 1 |
|||
return (i,j) |
|||
|
|||
if __name__ == '__main__': |
|||
m = [[int(i) for i in l] for l in open(sys.argv[1]).read().strip('\n\n').split('\n')] |
|||
|
|||
bas,mem = {},{} |
|||
# challenge 1 |
|||
res1 = str(sum([sum([risk(m, x, y) for y in range(len(m[0]))]) for x in range(len(m))])) |
|||
print("challenge 1:" +"\n" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
([([basin(m, x, y) for y in range(len(m[0])) if m[x][y] < 9]) for x in range(len(m))]) |
|||
res2 = str(reduce(mul, sorted(bas.values(), reverse=True)[0:3])) |
|||
print("challenge 2:" +"\n" + res2 + "\n") |
|||
|
@ -0,0 +1,72 @@ |
|||
--- Day 9: Smoke Basin --- |
|||
|
|||
These caves seem to be lava tubes. Parts are even still volcanically active; small hydrothermal vents release smoke into the caves that slowly settles like rain. |
|||
|
|||
If you can model how the smoke flows through the caves, you might be able to avoid it and be that much safer. The submarine generates a heightmap of the floor of the nearby caves for you (your puzzle input). |
|||
|
|||
Smoke flows to the lowest point of the area it's in. For example, consider the following heightmap: |
|||
|
|||
2199943210 |
|||
3987894921 |
|||
9856789892 |
|||
8767896789 |
|||
9899965678 |
|||
|
|||
Each number corresponds to the height of a particular location, where 9 is the highest and 0 is the lowest a location can be. |
|||
|
|||
Your first goal is to find the low points - the locations that are lower than any of its adjacent locations. Most locations have four adjacent locations (up, down, left, and right); locations on the edge or corner of the map have three or two adjacent locations, respectively. (Diagonal locations do not count as adjacent.) |
|||
|
|||
In the above example, there are four low points, all highlighted: two are in the first row (a 1 and a 0), one is in the third row (a 5), and one is in the bottom row (also a 5). All other locations on the heightmap have some lower adjacent location, and so are not low points. |
|||
|
|||
The risk level of a low point is 1 plus its height. In the above example, the risk levels of the low points are 2, 1, 6, and 6. The sum of the risk levels of all low points in the heightmap is therefore 15. |
|||
|
|||
Find all of the low points on your heightmap. What is the sum of the risk levels of all low points on your heightmap? |
|||
|
|||
Your puzzle answer was 506. |
|||
--- Part Two --- |
|||
|
|||
Next, you need to find the largest basins so you know what areas are most important to avoid. |
|||
|
|||
A basin is all locations that eventually flow downward to a single low point. Therefore, every low point has a basin, although some basins are very small. Locations of height 9 do not count as being in any basin, and all other locations will always be part of exactly one basin. |
|||
|
|||
The size of a basin is the number of locations within the basin, including the low point. The example above has four basins. |
|||
|
|||
The top-left basin, size 3: |
|||
|
|||
2199943210 |
|||
3987894921 |
|||
9856789892 |
|||
8767896789 |
|||
9899965678 |
|||
|
|||
The top-right basin, size 9: |
|||
|
|||
2199943210 |
|||
3987894921 |
|||
9856789892 |
|||
8767896789 |
|||
9899965678 |
|||
|
|||
The middle basin, size 14: |
|||
|
|||
2199943210 |
|||
3987894921 |
|||
9856789892 |
|||
8767896789 |
|||
9899965678 |
|||
|
|||
The bottom-right basin, size 9: |
|||
|
|||
2199943210 |
|||
3987894921 |
|||
9856789892 |
|||
8767896789 |
|||
9899965678 |
|||
|
|||
Find the three largest basins and multiply their sizes together. In the above example, this is 9 * 14 * 9 = 1134. |
|||
|
|||
What do you get if you multiply together the sizes of the three largest basins? |
|||
|
|||
Your puzzle answer was 931200. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
@ -0,0 +1,100 @@ |
|||
5456789349886456890123985435578996543213456789656899996467789234989765442345789778999989652349879899 |
|||
4349891298765348789339875323456789665434568996545698874356679959879898321457893569998879931998765668 |
|||
1298910989873234595498764312345678976746899989656987563234567899767987442578954678987968899897654457 |
|||
2987939875432123489999953201234599698657979979997965432023479998959876553689965789876856789789543345 |
|||
9896899984321012668899865313546789569798965469879876553135568987643988767997896898765945697698722256 |
|||
8765789965442143456789996579658895434999876398767987864589679876542099898966789999833123598589810123 |
|||
9954629876553234667899987988767932129899989219755398878678989987943989959355678998921057987678924345 |
|||
6543212989654345788999898999998941098789998998543229989789797999899876543134989997632345698789545456 |
|||
8654543498765476899398759126679953997678987987632101297997656798678965432015699876546559989898756567 |
|||
8767654579879989943297642014567899889567896597543223456789348976578976543126921998758698979999768979 |
|||
9988765678998999765965432123789998765456997498654345789893219865458897654434890139769987867896979989 |
|||
9899876989987899899876843234891249654369889329765567899994325976346789887565789349898765756975395699 |
|||
8767987899876999997987755346910198773235679939876688989875634987497893999679899959999654248954234799 |
|||
9653299999875789986599896467899987652134567899999789879876786798998932398789999898998643135932129978 |
|||
8632102398764578965434987578978698743028979989998998866987899899989510129999987797987659239891098769 |
|||
6543223987643589874323498678965469764167899878987897654398999989876431236789876576898798998789989756 |
|||
7654564597532599993214998789975379894356899865476789762129789879876543345699765455789987684569877546 |
|||
8799796798543489874109899899876123989456989874345678995345698765987876596998954314597998593498766434 |
|||
9989987987654678965929799999993239979569876543234589986797987653298989989897895423456987432987655325 |
|||
9876898998779899899898589998754998768998765432107678999989298942139599879766889435668986543498943212 |
|||
9785799659989956798767467899769878657889877543234789998979109893013498765455679546899598665569954323 |
|||
9654588949893245697654356999898767345678987698645679876767998782129987654343568958912459988798766534 |
|||
7543567998732196899793234789999543236789699798759798765656897643298799973212389979101967999899887646 |
|||
6432457898653989932989345699987684545893568999868979874545989654349698764324567899999899767999998787 |
|||
7421348999769878949878996789999876657932378999979657953435679876598539875634689979876798657789429898 |
|||
3210128799898767956965989899987988867891234989989345942124789998987621986875678967965987545679945929 |
|||
4323235678923456899854567978976799978910349878991249873675678989798710197987989459893296534567896912 |
|||
5454348789636567989765878967965456989321398767890956954578789977679821298998994299794987321457999899 |
|||
7689656896547678979896989549876567895432999656799897967789897855569932459019865987689876432346899768 |
|||
9798798998658999867998996432987678999549899245698689879892996743498643567999989876530998546456796547 |
|||
9899899139769643456999876545698789598998778967789542989954985432129754979789997987421987698578899656 |
|||
3956921019898752147898987676789993497987668989899901299875976593939878998668946799532398799989998997 |
|||
2345892345999864234987698787896432986543445899999892989989987989899999976557899987643469896799997989 |
|||
1016795469899975695995429898999999995432036789987799767898999879789998764345998987654567965678986879 |
|||
2525679579789986989876210989878878986544125679986678956967999765678999855235687899768789654379875668 |
|||
3434567989678999879998329876756569876543234589765459548456898764567899932123456969899997543268994345 |
|||
7566798998989239868965498995435457987764547678955347932345679876689999899015897954966989875346789656 |
|||
9789899867992198957896597954321349999975656889543136793656789997799975768976788963245976996657898769 |
|||
9899997656893987645789986896440497898896787897665945679778997598899854356898899995139895987767899878 |
|||
8989876545679998435699875789559976786797898998779897899899995439998765456999999989298784598998996999 |
|||
7879987934567954324987654668998765345689959689898799910999989323689878767892198778997653239569985321 |
|||
6567899895678965439876523456987643286789244567999667899989878934569989978999987667998732123489876432 |
|||
5434998799789877598965412355698321098992153456796543498868767957878999999398799456789541025678997643 |
|||
3129899678995998997894301234899532136789012568986432987659756899989999893298654345897632125989898856 |
|||
4598797587894359876894213568998754245989193467965421098643237923499989789139885457998784534898759878 |
|||
5999675466789299875689428689549895345678989979876533498754346935999767679099976868959987656789943989 |
|||
9876543245699987654578938795430976467989667899998754579865467899898654568989899979249898767899899993 |
|||
9985432125789998743567899894321987598992556998879867678987568998789843499876788989198779898989798921 |
|||
7898743014569879852456789965939798679321349876765978789998979987679921989795667891098655999876567893 |
|||
6987653123698765920378898979896549789210199765654989899979989875568999876654456789297643498765456989 |
|||
9998754534899994321234567898789329895321987654323499998765698784459679765443234678989931019874359878 |
|||
8979986785678987435345679987679434976433499876212578987644597643274598754320123799767892398765699967 |
|||
7768997896789876587486889898569555986545689974323459954323998932123459866541234598756789469886987856 |
|||
6456798987893987697578998766478976797969789865464567893219876543235579877532346689347898579998986543 |
|||
4347899999932398798678998754367898899898993976789679987623998995468678998546456789456987678979897421 |
|||
5456987891291999899989659765456789989697894987898799876534569989579789979798767897567898989469653210 |
|||
7567896790989899956796539878677899978576989998999893989545698878998996869899878998678999993298964523 |
|||
8879935789876788932986424989789999867485678899987932395987987659497895456989989659799899989987895634 |
|||
9989323498765567891093212399899998754334799789876421034599997545376994345679896543986789876766989745 |
|||
6695214998854458989989923569979876543212345698765432123498898434265679266989689959875698765454878957 |
|||
4594349876543234568979894698667987656101356789876743649987654320124589356789567898764329954343459998 |
|||
2987656987435156679965789987546499797219459899998654997698965434245678967892459929873219543212368999 |
|||
1099878994321067789874689876432345989498968978998789876569876554356789988921378910989398654563567897 |
|||
2178989965442128999943599984321259878987899567889898765459989866457891299543467899898989765687679956 |
|||
4569399879674236789732398743210198767466789335678999654378999878968954397664578998787779876998789632 |
|||
6891239998787645897653987654323987654345679126799198796459998989879765989876789999676567987899996543 |
|||
7920198769898657998764598765459876543234678938894349986567897692999979975987998987543456798998987655 |
|||
8941987654998789729978689876599987532145678956976499987778976543978898943299987976532102679987698786 |
|||
9659998543239897539989798987989976541013799767898989898989987999865767892109876598799993568976539987 |
|||
9998987654357999998599897899879997663123478988999875679297599789754456793298997329987889979765423498 |
|||
7767899765468998897432986798768989893234567899698764799198988678963345989987789419876776898976434579 |
|||
6756789976979767796521095679946679964545678924569953898999876567892259869876678923995665987897545678 |
|||
5345999898989745689432194599834569875657899535679831987894324456891098754324567899874354556789696989 |
|||
3234998789497659996543986987612346989798999947799762986543212367952169765913478998765212345678987891 |
|||
0199879695398798789674987965401656999899587899987653987655423478943459899894589998754303456789698910 |
|||
1987654569219899678995699876213457899945456989999768998766545678986567998789678999865412567896599932 |
|||
2398543458901987567989789984345569989631345678999899469898758789997679989698999989986543456789387893 |
|||
3987654567899895456778999995668979876520234567896952399969969898898798778456789976597654568895456794 |
|||
4598897678998754234567899876779989987431345778995431989459878976789989656345467894398767678998768989 |
|||
7679998789329895345978953987889296796532459889889549879321989345899876543234349943209879789899979978 |
|||
9796999899902976567889992198999345986545669994679698767990993276799989854101247895499989896789898765 |
|||
9895789999893597678999989239998456797676778933468987657789894387989998768212356976989998965899765754 |
|||
3934598998789698789999878956987568998987889012457896545698765498978999978326979899678987654987654323 |
|||
2123567997688999899898767999998678979998993233468993234569976999869899989545998787567899543499843212 |
|||
3234979783467899998789956678999989568989654354569689156789989897456789987659898645456789532398765301 |
|||
4569898672456789987695434599789995479679765457689589235679998756345679998798786534345789643999876412 |
|||
5698765421345698768459996789589954234569879878797678946899987643234568979897654323245689659876986433 |
|||
8789876510124569654347789993467893199979989989998789757998998743123458954999843210156799998765498764 |
|||
9998765421267898542125678975678999987898793296789899867987689854234567893598764321277899899654359875 |
|||
9329878632358987651014567896989998976799532135678999978976534965446789932349875432348998798765667986 |
|||
8912998793479199432123678998999876565987673234567998989986549876767899953456986546556795659976889997 |
|||
7894989895589298753234899769235965434598765345688997899987656998898998764567898657867954345989998998 |
|||
6789976986678999954745678952139876512349998656899876569898967989989689877698949768978985466996567899 |
|||
5689895499899888895677789543025987829467899767998775466789989879976578999789429899989876877895456789 |
|||
4578789357998767797799998765434598998998999878989654345678999967896469989993210967999987998954345678 |
|||
3435689467997655689899899879545679997889997999678921234589997656789359879879921256789798999543257789 |
|||
2324579569889834578965789998976899876679876544567892346899986545992198765767893345997569987654568999 |
|||
1012459698779323569954678967997987764589997432378965467999987956893987654556789457896456999765678967 |
|||
2123468987656313467893212356789996543678986543567899578998898768954998643544579968998345899976899456 |
|||
3654567896543202348932104567899987654569999864568998679997649879869876542123567899765456789987893237 |
@ -0,0 +1,5 @@ |
|||
2199943210 |
|||
3987894921 |
|||
9856789892 |
|||
8767896789 |
|||
9899965678 |
@ -0,0 +1,41 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys |
|||
import statistics |
|||
|
|||
def corr(line): |
|||
st = [] |
|||
for b in line: |
|||
if b in match.keys(): st.append(b) |
|||
if b in error.keys(): |
|||
if not (st.pop(), b) in match.items(): return error[b] |
|||
return 0 |
|||
|
|||
def inc(line): |
|||
st, score = [], 0 |
|||
for b in line: |
|||
if b in match.keys(): st.append(b) |
|||
if b in comp.keys(): st.pop() |
|||
miss = [match[b] for b in st] |
|||
for b in reversed(miss): |
|||
score *= 5 |
|||
score += comp[b] |
|||
return score |
|||
|
|||
if __name__ == '__main__': |
|||
inp = [list(i) for i in open(sys.argv[1]).read().strip('\n\n').split('\n')] |
|||
|
|||
match = {'(': ')', '{': '}', '[': ']', '<': '>'} |
|||
|
|||
# challenge 1 |
|||
error = {')': 3, ']': 57, '}': 1197, '>': 25137} |
|||
|
|||
res1 = str(sum([corr(line) for line in inp])) |
|||
print("challenge 1:" +"\n" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
comp = {')': 1, ']': 2, '}': 3, '>': 4} |
|||
|
|||
res2 = str(statistics.median([inc(line) for line in inp if corr(line) == 0])) |
|||
print("challenge 2:" +"\n" + res2 + "\n") |
|||
|
@ -0,0 +1,104 @@ |
|||
--- Day 10: Syntax Scoring --- |
|||
|
|||
You ask the submarine to determine the best route out of the deep-sea cave, but it only replies: |
|||
|
|||
Syntax error in navigation subsystem on line: all of them |
|||
|
|||
All of them?! The damage is worse than you thought. You bring up a copy of the navigation subsystem (your puzzle input). |
|||
|
|||
The navigation subsystem syntax is made of several lines containing chunks. There are one or more chunks on each line, and chunks contain zero or more other chunks. Adjacent chunks are not separated by any delimiter; if one chunk stops, the next chunk (if any) can immediately start. Every chunk must open and close with one of four legal pairs of matching characters: |
|||
|
|||
If a chunk opens with (, it must close with ). |
|||
If a chunk opens with [, it must close with ]. |
|||
If a chunk opens with {, it must close with }. |
|||
If a chunk opens with <, it must close with >. |
|||
|
|||
So, () is a legal chunk that contains no other chunks, as is []. More complex but valid chunks include ([]), {()()()}, <([{}])>, [<>({}){}[([])<>]], and even (((((((((()))))))))). |
|||
|
|||
Some lines are incomplete, but others are corrupted. Find and discard the corrupted lines first. |
|||
|
|||
A corrupted line is one where a chunk closes with the wrong character - that is, where the characters it opens and closes with do not form one of the four legal pairs listed above. |
|||
|
|||
Examples of corrupted chunks include (], {()()()>, (((()))}, and <([]){()}[{}]). Such a chunk can appear anywhere within a line, and its presence causes the whole line to be considered corrupted. |
|||
|
|||
For example, consider the following navigation subsystem: |
|||
|
|||
[({(<(())[]>[[{[]{<()<>> |
|||
[(()[<>])]({[<{<<[]>>( |
|||
{([(<{}[<>[]}>{[]{[(<()> |
|||
(((({<>}<{<{<>}{[]{[]{} |
|||
[[<[([]))<([[{}[[()]]] |
|||
[{[{({}]{}}([{[{{{}}([] |
|||
{<[[]]>}<{[{[{[]{()[[[] |
|||
[<(<(<(<{}))><([]([]() |
|||
<{([([[(<>()){}]>(<<{{ |
|||
<{([{{}}[<[[[<>{}]]]>[]] |
|||
|
|||
Some of the lines aren't corrupted, just incomplete; you can ignore these lines for now. The remaining five lines are corrupted: |
|||
|
|||
{([(<{}[<>[]}>{[]{[(<()> - Expected ], but found } instead. |
|||
[[<[([]))<([[{}[[()]]] - Expected ], but found ) instead. |
|||
[{[{({}]{}}([{[{{{}}([] - Expected ), but found ] instead. |
|||
[<(<(<(<{}))><([]([]() - Expected >, but found ) instead. |
|||
<{([([[(<>()){}]>(<<{{ - Expected ], but found > instead. |
|||
|
|||
Stop at the first incorrect closing character on each corrupted line. |
|||
|
|||
Did you know that syntax checkers actually have contests to see who can get the high score for syntax errors in a file? It's true! To calculate the syntax error score for a line, take the first illegal character on the line and look it up in the following table: |
|||
|
|||
): 3 points. |
|||
]: 57 points. |
|||
}: 1197 points. |
|||
>: 25137 points. |
|||
|
|||
In the above example, an illegal ) was found twice (2*3 = 6 points), an illegal ] was found once (57 points), an illegal } was found once (1197 points), and an illegal > was found once (25137 points). So, the total syntax error score for this file is 6+57+1197+25137 = 26397 points! |
|||
|
|||
Find the first illegal character in each corrupted line of the navigation subsystem. What is the total syntax error score for those errors? |
|||
|
|||
Your puzzle answer was 390993. |
|||
--- Part Two --- |
|||
|
|||
Now, discard the corrupted lines. The remaining lines are incomplete. |
|||
|
|||
Incomplete lines don't have any incorrect characters - instead, they're missing some closing characters at the end of the line. To repair the navigation subsystem, you just need to figure out the sequence of closing characters that complete all open chunks in the line. |
|||
|
|||
You can only use closing characters (), ], }, or >), and you must add them in the correct order so that only legal pairs are formed and all chunks end up closed. |
|||
|
|||
In the example above, there are five incomplete lines: |
|||
|
|||
[({(<(())[]>[[{[]{<()<>> - Complete by adding }}]])})]. |
|||
[(()[<>])]({[<{<<[]>>( - Complete by adding )}>]}). |
|||
(((({<>}<{<{<>}{[]{[]{} - Complete by adding }}>}>)))). |
|||
{<[[]]>}<{[{[{[]{()[[[] - Complete by adding ]]}}]}]}>. |
|||
<{([{{}}[<[[[<>{}]]]>[]] - Complete by adding ])}>. |
|||
|
|||
Did you know that autocomplete tools also have contests? It's true! The score is determined by considering the completion string character-by-character. Start with a total score of 0. Then, for each character, multiply the total score by 5 and then increase the total score by the point value given for the character in the following table: |
|||
|
|||
): 1 point. |
|||
]: 2 points. |
|||
}: 3 points. |
|||
>: 4 points. |
|||
|
|||
So, the last completion string above - ])}> - would be scored as follows: |
|||
|
|||
Start with a total score of 0. |
|||
Multiply the total score by 5 to get 0, then add the value of ] (2) to get a new total score of 2. |
|||
Multiply the total score by 5 to get 10, then add the value of ) (1) to get a new total score of 11. |
|||
Multiply the total score by 5 to get 55, then add the value of } (3) to get a new total score of 58. |
|||
Multiply the total score by 5 to get 290, then add the value of > (4) to get a new total score of 294. |
|||
|
|||
The five lines' completion strings have total scores as follows: |
|||
|
|||
}}]])})] - 288957 total points. |
|||
)}>]}) - 5566 total points. |
|||
}}>}>)))) - 1480781 total points. |
|||
]]}}]}]}> - 995444 total points. |
|||
])}> - 294 total points. |
|||
|
|||
Autocomplete tools are an odd bunch: the winner is found by sorting all of the scores and then taking the middle score. (There will always be an odd number of scores to consider.) In this example, the middle score is 288957 because there are the same number of scores smaller and larger than it. |
|||
|
|||
Find the completion string for each incomplete line, score the completion strings, and sort the scores. What is the middle score? |
|||
|
|||
Your puzzle answer was 2391385187. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
@ -0,0 +1,98 @@ |
|||
{<{[<((<[<({<{(){}}(()())>[<<><>>((){})]}(<<{}{}>(<><>)>))(<[(<>{}){()()}]{{{}[]}(()())}>[ |
|||
((<{[<([<<{[<(()())([]())>)<<<{}{}>{[][]}>{<<>>(()[])}>}<(((()[])[{}<>])[<[]{}>{{}[]}])[[({}{}) |
|||
({(<[([((<(<[(<>{}){()[]}]<[[]<>]<(){}]>><{(<>())[<>{}]}{(<>[])(<>{})}>)([(<(){}>[(){}]){{()[]}{<>{}}}][<<[] |
|||
{{{[(([{{{[{[(()())[<>[]]]{([]{}){()<>}}}]{{{((){})[[][]]}[[{}{}]<[]()>]}(<(<>()){{}{}>>([{}() |
|||
[<{{{[[(<[(([<{}[]>{()()}][[<>{}]]))]([<<{{}[]}>>([(<>[])<(){}>][[{}{}](()())])]{[{[<><>]}((<>{})[ |
|||
{<[<[[<<(<<<<(<>[])(<>[])>{([]())}>[{{[]()}}<({}())[<>()]>]>{[((<>{})[[]<>])([()<>]{<>()})](((<>() |
|||
([({({[{(([<[<[]>]>]<<({[]()}<[]<>>)[[()[]]{[]{}}]>>))((<<{<<><>>}{(<>{})<[]()>}>([[<>{}]<<>{}> |
|||
{(<([{{{{(((({{}[]}))){[(({}<>))({<><>}<[][]])][<<[]{}>[{}{}]>{<[]>{[]{}}}]})({[{([]<>)([]<>)} |
|||
{([{{{(([<[[[<(){}>{()[]}][([]<>)<[]{}>]]<{(<>())[[]()]}[{(){}}[()<>]]>]([({[]{}}{()[])){{<>()}{()[]}}])>[<[ |
|||
[([{<{(<({<{[[<>{}][<>[]]]<{{}<>}<{}{}>>}[({()[]])[[<>()]({}<>)]]>{<([{}<>]<[]<>>)[{[]()}{{}[]}]>[[{[][] |
|||
{{<(<{(<[<(((<[]<>><{}[]>))({(<>{}){[][]}}([[]()]({}<>))>)>[((((()<>)<<>[]>){(<>{}){<>{}}})(<({}( |
|||
{{[{<{<([{[<{[{}{}]{(){}}}{{[]<>}<()[]>}>]<[({[][]}<{}<>>)(<{}{}><[]()>)]<[{<>{}}(()())]([[]{}]<[]<>>)>>>[{[{ |
|||
<(([<<{{<(([(({}{})[[]{}])[<{}>(<>{})]]<([{}{}]{()[]})>))({(<(()<>)<<><>>>(([]<>)))}<<<[() |
|||
<<<(({{([{({({()()}<<>[]>)<{()[]}[<>()>>}){[<[<>{}][<><>]>[{()[]}[<><>]]]<<[<>[]]{<>()}>>}}[(<[[(){}](() |
|||
<<[[{{([(([([[<>{}][(){}]])]{({{()}(<>{})}{{{}<>}{<><>}})(([<><>])({{}[]}<<><>>))})([{({()<>}<[][]>)}])) |
|||
[(<<<<<{[<({[{{}[]}<()<>>]<[{}[]][[]<>]>})>[<<{(()())({}<>)}{({}())(<>[]]}><<<{}<>>([]<>)><[ |
|||
<<({({{([(<([[{}()]<[]{}>]<<<>()>>)><{(<{}<>><{}()>)<{(){}}[<>]>}{([[]{}][[]<>])<({}()){{}[ |
|||
{<{([[[[[{<<[[{}{}]([]<>)]{{{}()}[<><>]}><[<()()>[{}{}]](((){})<()>>>>}]<{({{([]()){{}<>}}<{<>{}}({}{} |
|||
{[{[[<[((<(<<{<>}{()[]}>><{<<>[]>[()[]]}{{()()}[()[]]}>)(({[[]](<>[])}{({}())<{}()>})([[{}[]]<[]()>][{ |
|||
[{[(({[{{([[[<()()>{{}{}}]{([]<>){<><>}}]](<<<(){}>(()())>{[[]]{<>{}}>>))<[<((<>{}){(){}}){[{}<>]}>([[<>< |
|||
<{<(<([(<[({<<[]()>[[]{}]>(<{}<>>)}(<[{}[]][{}[]]>{<{}[]>[(){}]}))[<(<[]<>>{{}<>}]([[][]]<()<>>)>{({{}<>}[<>[ |
|||
{({({{<({[{[{<<>()>[[]{}]}](([{}<>]{()()})[([]()){[]()}})}[[((()())[()<>])(<<>{}><{}>)]]]<([{([] |
|||
(<[([{({<([<(([]<>)<()[]>){{<>{}}[()()]}>])(([({[]()}<{}{}>)][<{{}[]}({})>[[<><>][<><>]]])<[({()[]}[[]{ |
|||
{{{<{{[[{[[<({[]()}{()[]})<[<>()][()()]>>(({{}{}}))][({[(){}](()[]]}){{<<>()>({})}{<{}[]>[{}<>]}}]]{[< |
|||
{<([((<{<<<{(({}{})<<>[]>)(((){}){[]})}{({[]<>}[[]{}])<[{}[]][()()]>}}[{([<>()][<>{}]){(<> |
|||
{([([(({[<[[[(())(<>[])]{[()()][<>]}]]>([{[(<><>)(<>())]<(()<>)[<><>]>}({{<>{}}({})}([{}][ |
|||
([[[({[{{<{{{[{}()]{(){}}}[{()}({}[])]}[{[[]<>>(()[])}<{[][]}{[]}>]}>}}]}{[<[[[[(({}{}){{}[]} |
|||
<[{<([<({((([[<>{}]([]())]<[()[]]<()<>>>){<<{}{}>[<><>]>[((){}){{}<>}]}))}({[({[()())(<>[])}{({}())}){([()[] |
|||
{([[{[<<[[<{([<>()][{}{}])<([]{})(()[])>}{{{()()}{[][]}}<[[]{}]<<>{}>>}>(({<()()>({}())}[{<>[]}({}<>)])([[< |
|||
({[<{{[<{{(((([]<>){<>()})([()<>]([]{})))){{<{()()}[{}<>]>}({<{}[]>}{([]<>)<{}[]>})}}<<([{{}()}[{}[]]]<{( |
|||
<({{([{[({<([({}())[()[]]]{([]{})})(([[]{}]{{}[]})([{}()><()<>>))>(<(({}{})<{}{}>)[{<><>}{[] |
|||
[{[{<{([[[<[[{[][]}(<>{})]{{[]<>}[{}{}]}]><{({{}()}<[]()})}>]{{(<[[][]]{[]()}>{(()())(<>[])})( |
|||
(<{(<[[<{[[<<([]<>)<{}{}>>({{}[]}({}()))>]({([[]<>]([]())){[<>{}]<{}()>}}[{({}())[(){}]}(({}{})[[]] |
|||
<[<<([{[{<{{<[[][]]<<>[]>>({<>{}}[<><>])}([[{}<>]<()()>][<[][]>(()[])])}[({[()()][[]()]}[{{}()}<[]<>>])]>{< |
|||
<(([[{(([[([[{{}()}{[]}]]<((<><>}({}[]))((()())[()[]])>)[{{<[]<>>((){})}}<(<(){}>{{}[]})({()}{{}<>})>]]<[(<{ |
|||
[{<(((<(<({(({{}()}{<><>})[{[][]}{(){}}])({{[]{}}[<>{}]>)})>((([<(<><>){{}<>}><[<>{}]>]([[<>[]][{}{} |
|||
[<{{({([({({{{()<>}([][])>}((({}<>)(()[]))<(<>()){{}<>}>)){[([()()](<>[]))]{({[]}[[]{}])([[]<> |
|||
{({[<{(<<([[[<{}{}>[{}{}]](<<>>(()))]{[([]<>)<{}{}>]<[<><>]>}]<[[{{}<>}<<>{}>][([]<>)<(){} |
|||
([{{{[[(<<[<[[<>]{[]}]((<>{})({}[]))>({{()[]}<<><>>}{{<>{}}({})})]{{{{[][]}<{}()>}}<[[<><>][{}<>]]< |
|||
[<{<{<[{{[([(([]<>))[{<>()}<{}{}>]]{[<<>{}>[(){}]){<[][]>[<><>]}})](([<([]{})[{}()]>(({}())(<>{}))] |
|||
[<[<{(<(([{<{([]{}){[][]}}><{[{}[]]([]<>)}[[()[]]<()()>]>}][{(<[(){}]{()<>}><<[]()>[[]()]>){[[<>[]](()[]) |
|||
<(<<<([[<([[({[]<>}<[]()>){{<>[]}[{}{}]}]([[[][]]<[]()>])]<{{(<><>){<>[]}}}{(<[][])(()[]))[([]{})[[ |
|||
(([{<{{([<<{({[]{}}[()[]])[<()()><()[]>]}[(<()>[()()])[[<>[]]]]>>{{{{<[]()>[()<>]}}{{<()[]>[()[]]}<[[][]] |
|||
(<<[([[{{({<[([][])<{}()]][<()()>(()())]>})}<([[{(()<>)<[]()>}((()[])[<>{}])]]([<{(){}}({}<>)>][< |
|||
[<<((<[<<{(((({}()))({<>{}}([]<>))){{<()<>><{}[]>}{(()())}}){({([]<>)<<>{}>})}}<{{<[()][<><>]>{{[] |
|||
<{[<[((([{<{{{<>[]}[[]()]}([<><>])}>((<<<>()>({}<>)><[{}[]]<()[]>>)[{{[][]}{()<>}}[{()<>}(()[])]])}(([<{{ |
|||
{<{<[(({([<[<[[][])([]{})>[{(){}}[[]<>]]][(<{}<>>{()<>}){[<><>]{{}[]}}]>([[<[][]>{[]<>}]({[][]}(()()))]{ |
|||
(<{{{[{<{(<[({{}[]})]><<{(()<>)[{}{}]}{<()()>}>>)[[(({()<>}(<>{})))([<(){}>(()<>)]{((){})([][])})] |
|||
<<[(<([<(({[{({}{})}<{()<>}{<>{}}>][([[]()](()<>))]}[[({{}()}<[]{}>)[<[]()>[()()]]]((<{}{} |
|||
<<{[{[<{{{([<<<>{}>{()[]}>({{}[]}<<>{}>)][[<()[]>[{}[]]]({()<>}(()()))])[<<<<>()>{[]{}}>><{{[]{}}<()<>>}(<<>[ |
|||
[{{<({[([({{{(()())[<><>]}{[()()][(){}]}}}{[([<>[]])[{[]()}((){})]]([<[]{}>(()<>)]{[<>]})})(< |
|||
<<<{{(({<{<[<<<>{}>>(<<>[]>{()()})]<([()<>])>>[(<({}[]){{}[]}>{[{}{}][[]()]})[<[<>[]]<()[]>>(< |
|||
[([<<<(<[[[[[([]{}){{}()}}<<[]()>{[]}>][([<>[]]({}))[(()<>){()()}]]]]]>{[([[<([]())<{}<>>>({<>()} |
|||
[([{{[[(({[<{[{}[]]{[][]]}<{<>()}[<>[]]>>(<{<>()}<[]()>>)]}))<<<<<{{()[]}{{}[]}}[<<>{}>]><{[{}<>]{( |
|||
[{{{<((([{([{[[]()][<>()]}([[]()]{{}()})]{([{}{}](<>{}))({()<>}(<>{}))})<[({(){}}[()<>])}>}( |
|||
{<<{{({[[[[[{[()]({})}<[<><>]{{}}}][[{()<>}({}{})][<<>[]>{<><>}]]]({<(<>)<<><>>>({<>()}<<> |
|||
<[[[[({([[{<[{{}()}]{(()<>)<[]()>}>{[{<>{}}(()[])][{()[]}<()()>]}}]]<{[(({<>{}}{<>()})<[[]()]<<>{}>>)<((()[]) |
|||
({{{<{[({[[[<{()<>}<<>[]>>{[[]<>][<>()]}]([(()<>)[[]()]]({{}[]}(()[]))]]][{{{<<>>({}<>)}<<<>{} |
|||
[{[((<{<([[{<<()[]>[[][]]>}<{({})}[<{}[]>[[][]}]>]]<<{(([]<>)[[]()])}<{<{}()>{[]}}{[()[]]({})}>> |
|||
[{([[{[({<[<(<<>{}>({}[]))([{}<>]{(){}})}({<[][]>}{[()()]<{}[]>})]<<[<(){}>[<>{}]][<<>{}>({}{ |
|||
[<([{<<[((([<[<>()]({}())><([]{})<{}[]>>]))[{[[[[]()]]]}{{[{[]()}([][])]{<[][]>{{}()}}}}])<(({{(<>()){ |
|||
{{[[<{{(({{{(<{}<>>{()[]})[<[]()>]}[{<[]{}>[()[]]}]}<[{[[]<>][[][]]}<<(){}>((){})>][([()<>]<<>>)< |
|||
<<{[(([{<((({([][]){[]<>}}{({}())}))({[<<>{}><<>>]}{<[<>{}](()())><<{}[]>{()<>}>)))({[<(<>[ |
|||
<[<((<<[[<[((([]<>)<(){}>)[<(){}>])({<{}{}>{<><>}}<(()())<[]{}>>)]{{({(){}}(()[]))}<({<><>}({}()))>} |
|||
[<{(<([{[({[{({}{})<{}()>}[{[]<>}({}<>)]]})[<[([{}[]][()[]])((<>()){{}<>})][[[(){}][[][]]][< |
|||
<(({([[(<[[{(<<><>><{}()>)<(()()){()[]}>}({[()<>][{}[]]}([<>{}]<<><>>)}]]{{[<[<>[]]>({<><>}([]{}))][(([][])< |
|||
{[[[[<<[{(({{{[]()}[{}[]]}}{[[()()][{}{}]]}){[{{{}()}}[[[][]]<()()>]]}){[{((()<>)[{}<>]){<<>()>[()()]}}(([{}< |
|||
[[<<<{<({[<([[()<>]]({()<>})){[{{}[]}]}>][({[<()<>>({}[])]}((<<><>>[<>])[({}())<{}{}>]))]})>}>[{{(({{[ |
|||
{{[[{{(([[[[({[]()}<{}()>)<(()[])<<>[]>>]]<(<{[][]}<{}()>>(({})[[][]]))>]<<{({()[]}[(){}]]({ |
|||
({{((<([<({<(<[]<>><<>[]>){[{}<>]}>(<[{}{}]>)}[<{{<>{}}{[]()}}[<<><>>[[][]]]>[[<()()><(){}>]{< |
|||
[[[(({{<(<{<[{()[]}]({<>{}})>[<<<>()>{{}{}}>{({}<>)<<>()>}]}<({{()()}}<(()()){<><>}>){<((){})(<>() |
|||
{<{{(<{{<[[({<<>>}<[(){}]({}())>)[<{()<>}[{}()]>[({}[])<()()>]]]]{<[({<>{}}{[][]})]{[(<>{})({}())]} |
|||
[<[<{<<({[[(((<>())[{}<>]))<(({}[])(()[])){{{}{}}[[]<>]}>]<[(<{}{}]{{}{}})<(()<>)>][[{<>{}}<[ |
|||
[({<(<[([<({([<>()]{[][]}>{<<>[]>[[]()]}}[{<()<>>([]<>)}])<<<[[]()](())>><[<<>[]>{{}()}]{<() |
|||
{{[{(<<{[{({[<[]()>{{}<>}]([()<>]{{}[]})}<<<[]()>[[]<>]><[<>{}][()()]>>)}<{<[{[]()}{<>{}}]>{({[][]}<[] |
|||
[[{[<<<[{[[<({<>()}((){})){{<>[]}<(){}>}>[<(()<>)({}<>)>{<[]()>(<>)}]]]{<<{[<>[]]>>(<<{}()>(<>())>( |
|||
{({{[([<{{{<((<><>)<()()>][<{}[]>{<>[]}]><({<>()}(()<>))({{}[]}<()[]>)>}([({{}[]})({{}()}[<>[]])])} |
|||
{<[[({{((<[{[{<>()}(<>())]<({}[])<<>{}>>}([(()())<<>[]>]((<>[]){{}{}}))]{({<()()>(()<>)}[{[][]}([]())])<<[() |
|||
([{((({<<<{<{{<><>}(()<>)}>}>)[{{[[[[][]]]][<(<>{}){[]}>([{}()][[][]])]}<{([()()][<>()])(<[]()> |
|||
<(((<(({<<[{<(()())>[[[][]]<[]{}>]}[{{<>()}(<><>)}(({}())({}()))]]>((<({{}[]}(<>())){({}[]) |
|||
<<{[(<([<(<{{[<>{}]}(<<>()>({}{}))}><({<<>()>(<><>)}<<[][]>[[]()]>)(([<>()){{}()})<[[][]]{<>{} |
|||
<<[[([{{{{[<{[(){}]<[]()>}>[[([])<[]<>>>[({}{})([][])]]]}<<({<()[]><{}<>>}<{()<>}(<><>)>)>(([ |
|||
{[[[{{[{{((<{[{}[]](()[])}<(<>{})(<><>)>>){(<<<>{}>>)(([()[]]<[]{}})[({}[])(()())])})}}]}{[{{({({([] |
|||
([{[{((([[{{([[][]][{}[]])[{[]<>}<<>[]>]}}]][<[{[(<>{})[[]<>]][{[]<>}[(){}]]}]{<[[{}[]]{{}[]}]><(({} |
|||
{(<(<{<<([<<<[{}{}]<{}{}>>><[{<><>}{{}<>}]([[]<>]{{}()})>>])>>{{[{{{<<<>()>[{}()]>{<[]()>[<>{}]}}}}<(<[( |
|||
{<[{<<({[({(([[]<>](<><>)))[[[{}()]<()[]>]<{<>{}}[()<>]>]})([<([(){}]{<>[]})<<<>()><(){}>>><([<>[]>([][]))(<< |
|||
[[[[<<(<({(<[{(){}}[()[]]][[{}[]]{[]{}}]>([{[][]}([]{})][{{}[]}<[]()>]))[{[{()()}({})]({(){}}[<>[] |
|||
{<{(<[<(<<<{<[()<>]>{{()[]}}}<<([]<>)[()<>]>>>[{[<<><>>[{}<>]][<<><>>{(){}}]}[{[[]()]{<>()}} |
|||
<[[<{<<[{{[[(([][])[[][]])<({}<>){{}[]}>]](<<({}[])[[][]]>((<><>))>[([()[]]((){}))])}}{[([((<>()) |
|||
{(<{[[((<<<{<{<>{}}([]{})><{()}>}[{(()<>)[[][]]}{<{}{}><{}{}>}]]<[[<{}()>]<([]{})>]{{[<>()]{{}{ |
|||
<{<{<{[{(((<(<[]{}>)([{}{}]({}{}))>([{[]<>}[[]{}]]<([]()){[]<>}>))<[(<[]{}>[()[]])]>)<{{[{{ |
|||
{{<([<{[(([(({[]<>}{()[]})<(()){(){}}>)[{({}<>)<[]<>>}<{{}()}<<><>>>>][{<({}<>)[()()]><<()<>>> |
|||
[[[<([<<[[[{<<[][]>{()()}>[[(){}][<><>]]}{[{<>[]}[[]{}]]}]{<<({}<>)[[]]>[(<>[])]><<[()[]]<[]>>[{[]<>}({}{})]> |
|||
{{{[{(<<{({{<{<>[]}>[{<><>}[()[]]]}[({()()})([<><>]<<>[]>)]}({[{{}[]}{{}[]}]}[(<[]()>[<>[]])({<><>}[(){}])] |
|||
(<<[{[{[({<[{{(){}}<(){}>}{{()[]}[<>{}]}]{{(<>{})<{}>}{((){})}}>[{([<>()](<>{}))<{{}[]}[[]{}]>}{(<[][ |
|||
(<[[{<<{({<([<<>()>[<>()]]{{()<>}[<>[]]))>({<<<>()><()<>>>}({{[]<>}{{}()}}{<(){}><<>{}>}))})}<([<({[[]]{{}< |
|||
([((<[((([{<((()<>))[([])]>({(()<>)([]{})}([{}<>](()<>)))}{<[[[]()]([]{})]>}]({([{[]{}}][{(){}}{(){} |
|||
(({{<[<{<{([<([]<>){()}><([]<>)<[][]>>]<<[()<>][[]<>]><{()()}>>)[(<[[]{}](<>())>{{{}()}{[]()}} |
@ -0,0 +1,10 @@ |
|||
[({(<(())[]>[[{[]{<()<>> |
|||
[(()[<>])]({[<{<<[]>>( |
|||
{([(<{}[<>[]}>{[]{[(<()> |
|||
(((({<>}<{<{<>}{[]{[]{} |
|||
[[<[([]))<([[{}[[()]]] |
|||
[{[{({}]{}}([{[{{{}}([] |
|||
{<[[]]>}<{[{[{[]{()[[[] |
|||
[<(<(<(<{}))><([]([]() |
|||
<{([([[(<>()){}]>(<<{{ |
|||
<{([{{}}[<[[[<>{}]]]>[]] |
@ -0,0 +1,51 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys |
|||
|
|||
def flash(octop, x, y): |
|||
for i in [(-1,-1), (-1,0), (-1,1), (0,-1), (0,1), (1,-1), (1,0), (1,1)]: |
|||
if -1 < y+i[0] < len(octop) and -1 < x+i[1] < len(octop): |
|||
if octop[y+i[0]][x+i[1]] > 0: octop[y+i[0]][x+i[1]] += 1 |
|||
octop[y][x] = 0 |
|||
return octop |
|||
|
|||
def flashable(octo): |
|||
for y in octo: |
|||
for x in y: |
|||
if x > 9: |
|||
return True |
|||
return False |
|||
|
|||
def step(octo): |
|||
nex = [[x+1 for x in y] for y in octo] |
|||
flashs = 0 |
|||
while flashable(nex): |
|||
for x in range(len(octo[0])): |
|||
for y in range(len(octo)): |
|||
if nex[y][x] > 9: |
|||
nex = flash(nex,x,y) |
|||
flashs += 1 |
|||
return nex, flashs |
|||
|
|||
if __name__ == '__main__': |
|||
lines = open(sys.argv[1]).read().strip('\n\n').split('\n') # or split \n\n or sth similar |
|||
octos = [[int(i) for i in l] for l in lines] |
|||
|
|||
# challenge 1 |
|||
flashes, i = 0, 0 |
|||
while True: |
|||
i += 1 |
|||
octos, f = step(octos) |
|||
if(i <= 100): |
|||
flashes += f |
|||
if sum([sum([1 for x in range(len(octos[0])) if octos[y][x] == 0]) for y in range(len(octos))]) == 100: |
|||
first = i |
|||
break |
|||
|
|||
res1 = str(flashes) |
|||
print("challenge 1:" +"\n" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
res2 = str(first) |
|||
print("challenge 2:" +"\n" + res2 + "\n") |
|||
|
@ -0,0 +1,348 @@ |
|||
--- Day 11: Dumbo Octopus --- |
|||
|
|||
You enter a large cavern full of rare bioluminescent dumbo octopuses! They seem to not like the Christmas lights on your submarine, so you turn them off for now. |
|||
|
|||
There are 100 octopuses arranged neatly in a 10 by 10 grid. Each octopus slowly gains energy over time and flashes brightly for a moment when its energy is full. Although your lights are off, maybe you could navigate through the cave without disturbing the octopuses if you could predict when the flashes of light will happen. |
|||
|
|||
Each octopus has an energy level - your submarine can remotely measure the energy level of each octopus (your puzzle input). For example: |
|||
|
|||
5483143223 |
|||
2745854711 |
|||
5264556173 |
|||
6141336146 |
|||
6357385478 |
|||
4167524645 |
|||
2176841721 |
|||
6882881134 |
|||
4846848554 |
|||
5283751526 |
|||
|
|||
The energy level of each octopus is a value between 0 and 9. Here, the top-left octopus has an energy level of 5, the bottom-right one has an energy level of 6, and so on. |
|||
|
|||
You can model the energy levels and flashes of light in steps. During a single step, the following occurs: |
|||
|
|||
First, the energy level of each octopus increases by 1. |
|||
Then, any octopus with an energy level greater than 9 flashes. This increases the energy level of all adjacent octopuses by 1, including octopuses that are diagonally adjacent. If this causes an octopus to have an energy level greater than 9, it also flashes. This process continues as long as new octopuses keep having their energy level increased beyond 9. (An octopus can only flash at most once per step.) |
|||
Finally, any octopus that flashed during this step has its energy level set to 0, as it used all of its energy to flash. |
|||
|
|||
Adjacent flashes can cause an octopus to flash on a step even if it begins that step with very little energy. Consider the middle octopus with 1 energy in this situation: |
|||
|
|||
Before any steps: |
|||
11111 |
|||
19991 |
|||
19191 |
|||
19991 |
|||
11111 |
|||
|
|||
After step 1: |
|||
34543 |
|||
40004 |
|||
50005 |
|||
40004 |
|||
34543 |
|||
|
|||
After step 2: |
|||
45654 |
|||
51115 |
|||
61116 |
|||
51115 |
|||
45654 |
|||
|
|||
An octopus is highlighted when it flashed during the given step. |
|||
|
|||
Here is how the larger example above progresses: |
|||
|
|||
Before any steps: |
|||
5483143223 |
|||
2745854711 |
|||
5264556173 |
|||
6141336146 |
|||
6357385478 |
|||
4167524645 |
|||
2176841721 |
|||
6882881134 |
|||
4846848554 |
|||
5283751526 |
|||
|
|||
After step 1: |
|||
6594254334 |
|||
3856965822 |
|||
6375667284 |
|||
7252447257 |
|||
7468496589 |
|||
5278635756 |
|||
3287952832 |
|||
7993992245 |
|||
5957959665 |
|||
6394862637 |
|||
|
|||
After step 2: |
|||
8807476555 |
|||
5089087054 |
|||
8597889608 |
|||
8485769600 |
|||
8700908800 |
|||
6600088989 |
|||
6800005943 |
|||
0000007456 |
|||
9000000876 |
|||
8700006848 |
|||
|
|||
After step 3: |
|||
0050900866 |
|||
8500800575 |
|||
9900000039 |
|||
9700000041 |
|||
9935080063 |
|||
7712300000 |
|||
7911250009 |
|||
2211130000 |
|||
0421125000 |
|||
0021119000 |
|||
|
|||
After step 4: |
|||
2263031977 |
|||
0923031697 |
|||
0032221150 |
|||
0041111163 |
|||
0076191174 |
|||
0053411122 |
|||
0042361120 |
|||
5532241122 |
|||
1532247211 |
|||
1132230211 |
|||
|
|||
After step 5: |
|||
4484144000 |
|||
2044144000 |
|||
2253333493 |
|||
1152333274 |
|||
1187303285 |
|||
1164633233 |
|||
1153472231 |
|||
6643352233 |
|||
2643358322 |
|||
2243341322 |
|||
|
|||
After step 6: |
|||
5595255111 |
|||
3155255222 |
|||
3364444605 |
|||
2263444496 |
|||
2298414396 |
|||
2275744344 |
|||
2264583342 |
|||
7754463344 |
|||
3754469433 |
|||
3354452433 |
|||
|
|||
After step 7: |
|||
6707366222 |
|||
4377366333 |
|||
4475555827 |
|||
3496655709 |
|||
3500625609 |
|||
3509955566 |
|||
3486694453 |
|||
8865585555 |
|||
4865580644 |
|||
4465574644 |
|||
|
|||
After step 8: |
|||
7818477333 |
|||
5488477444 |
|||
5697666949 |
|||
4608766830 |
|||
4734946730 |
|||
4740097688 |
|||
6900007564 |
|||
0000009666 |
|||
8000004755 |
|||
6800007755 |
|||
|
|||
After step 9: |
|||
9060000644 |
|||
7800000976 |
|||
6900000080 |
|||
5840000082 |
|||
5858000093 |
|||
6962400000 |
|||
8021250009 |
|||
2221130009 |
|||
9111128097 |
|||
7911119976 |
|||
|
|||
After step 10: |
|||
0481112976 |
|||
0031112009 |
|||
0041112504 |
|||
0081111406 |
|||
0099111306 |
|||
0093511233 |
|||
0442361130 |
|||
5532252350 |
|||
0532250600 |
|||
0032240000 |
|||
|
|||
After step 10, there have been a total of 204 flashes. Fast forwarding, here is the same configuration every 10 steps: |
|||
|
|||
After step 20: |
|||
3936556452 |
|||
5686556806 |
|||
4496555690 |
|||
4448655580 |
|||
4456865570 |
|||
5680086577 |
|||
7000009896 |
|||
0000000344 |
|||
6000000364 |
|||
4600009543 |
|||
|
|||
After step 30: |
|||
0643334118 |
|||
4253334611 |
|||
3374333458 |
|||
2225333337 |
|||
2229333338 |
|||
2276733333 |
|||
2754574565 |
|||
5544458511 |
|||
9444447111 |
|||
7944446119 |
|||
|
|||
After step 40: |
|||
6211111981 |
|||
0421111119 |
|||
0042111115 |
|||
0003111115 |
|||
0003111116 |
|||
0065611111 |
|||
0532351111 |
|||
3322234597 |
|||
2222222976 |
|||
2222222762 |
|||
|
|||
After step 50: |
|||
9655556447 |
|||
4865556805 |
|||
4486555690 |
|||
4458655580 |
|||
4574865570 |
|||
5700086566 |
|||
6000009887 |
|||
8000000533 |
|||
6800000633 |
|||
5680000538 |
|||
|
|||
After step 60: |
|||
2533334200 |
|||
2743334640 |
|||
2264333458 |
|||
2225333337 |
|||
2225333338 |
|||
2287833333 |
|||
3854573455 |
|||
1854458611 |
|||
1175447111 |
|||
1115446111 |
|||
|
|||
After step 70: |
|||
8211111164 |
|||
0421111166 |
|||
0042111114 |
|||
0004211115 |
|||
0000211116 |
|||
0065611111 |
|||
0532351111 |
|||
7322235117 |
|||
5722223475 |
|||
4572222754 |
|||
|
|||
After step 80: |
|||
1755555697 |
|||
5965555609 |
|||
4486555680 |
|||
4458655580 |
|||
4570865570 |
|||
5700086566 |
|||
7000008666 |
|||
0000000990 |
|||
0000000800 |
|||
0000000000 |
|||
|
|||
After step 90: |
|||
7433333522 |
|||
2643333522 |
|||
2264333458 |
|||
2226433337 |
|||
2222433338 |
|||
2287833333 |
|||
2854573333 |
|||
4854458333 |
|||
3387779333 |
|||
3333333333 |
|||
|
|||
After step 100: |
|||
0397666866 |
|||
0749766918 |
|||
0053976933 |
|||
0004297822 |
|||
0004229892 |
|||
0053222877 |
|||
0532222966 |
|||
9322228966 |
|||
7922286866 |
|||
6789998766 |
|||
|
|||
After 100 steps, there have been a total of 1656 flashes. |
|||
|
|||
Given the starting energy levels of the dumbo octopuses in your cavern, simulate 100 steps. How many total flashes are there after 100 steps? |
|||
|
|||
Your puzzle answer was 1705. |
|||
--- Part Two --- |
|||
|
|||
It seems like the individual flashes aren't bright enough to navigate. However, you might have a better option: the flashes seem to be synchronizing! |
|||
|
|||
In the example above, the first time all octopuses flash simultaneously is step 195: |
|||
|
|||
After step 193: |
|||
5877777777 |
|||
8877777777 |
|||
7777777777 |
|||
7777777777 |
|||
7777777777 |
|||
7777777777 |
|||
7777777777 |
|||
7777777777 |
|||
7777777777 |
|||
7777777777 |
|||
|
|||
After step 194: |
|||
6988888888 |
|||
9988888888 |
|||
8888888888 |
|||
8888888888 |
|||
8888888888 |
|||
8888888888 |
|||
8888888888 |
|||
8888888888 |
|||
8888888888 |
|||
8888888888 |
|||
|
|||
After step 195: |
|||
0000000000 |
|||
0000000000 |
|||
0000000000 |
|||
0000000000 |
|||
0000000000 |
|||
0000000000 |
|||
0000000000 |
|||
0000000000 |
|||
0000000000 |
|||
0000000000 |
|||
|
|||
If you can calculate the exact moments when the octopuses will all flash simultaneously, you should be able to navigate through the cavern. What is the first step during which all octopuses flash? |
|||
|
|||
Your puzzle answer was 265. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
@ -0,0 +1,10 @@ |
|||
3113284886 |
|||
2851876144 |
|||
2774664484 |
|||
6715112578 |
|||
7146272153 |
|||
6256656367 |
|||
3148666245 |
|||
3857446528 |
|||
7322422833 |
|||
8152175168 |
@ -0,0 +1,5 @@ |
|||
11111 |
|||
19991 |
|||
19191 |
|||
19991 |
|||
11111 |
@ -0,0 +1,10 @@ |
|||
5483143223 |
|||
2745854711 |
|||
5264556173 |
|||
6141336146 |
|||
6357385478 |
|||
4167524645 |
|||
2176841721 |
|||
6882881134 |
|||
4846848554 |
|||
5283751526 |
@ -0,0 +1,48 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys |
|||
import re |
|||
from copy import deepcopy |
|||
|
|||
def parse(l): |
|||
groups = re.compile(r"(?P<p1>\w+)-(?P<p2>\w+)").search(l) |
|||
p1, p2 = groups.groups() |
|||
for p in (p1,p2): |
|||
if not p in opts.keys(): opts[p] = set() |
|||
if not p in opts.keys(): opts[p] = set() |
|||
if p.islower() and p not in ('start', 'end'): opts['small'].add(p) |
|||
if p.islower() and p not in ('start', 'end'): opts['small'].add(p) |
|||
opts[p1].add(p2) |
|||
opts[p2].add(p1) |
|||
|
|||
def paths(p1, l, twice=''): |
|||
p = deepcopy(p1) |
|||
p.append(l) |
|||
if p.count(twice) > 1: twice = '' |
|||
if l == 'end': |
|||
pths.add(tuple(p)) |
|||
return |
|||
for n in opts[l]: |
|||
if not ((n != twice and n in p and n in opts['small']) or n == 'start'): |
|||
paths(p, n, twice) |
|||
|
|||
if __name__ == '__main__': |
|||
lines = open(sys.argv[1]).read().strip('\n\n').split('\n') # or split \n\n or sth similar |
|||
|
|||
opts = {'start': set(), 'end': set(), 'small': set()} |
|||
[parse(i) for i in lines] |
|||
|
|||
# challenge 1 |
|||
pths = set() |
|||
paths([], 'start') |
|||
|
|||
res1 = str(len(pths)) |
|||
print("challenge 1:" +"\n" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
pths = set() |
|||
[paths([], 'start', t) for t in opts['small']] |
|||
|
|||
res2 = str(len(pths)) |
|||
print("challenge 2:" +"\n" + res2 + "\n") |
|||
|
@ -0,0 +1,152 @@ |
|||
--- Day 12: Passage Pathing --- |
|||
|
|||
With your submarine's subterranean subsystems subsisting suboptimally, the only way you're getting out of this cave anytime soon is by finding a path yourself. Not just a path - the only way to know if you've found the best path is to find all of them. |
|||
|
|||
Fortunately, the sensors are still mostly working, and so you build a rough map of the remaining caves (your puzzle input). For example: |
|||
|
|||
start-A |
|||
start-b |
|||
A-c |
|||
A-b |
|||
b-d |
|||
A-end |
|||
b-end |
|||
|
|||
This is a list of how all of the caves are connected. You start in the cave named start, and your destination is the cave named end. An entry like b-d means that cave b is connected to cave d - that is, you can move between them. |
|||
|
|||
So, the above cave system looks roughly like this: |
|||
|
|||
start |
|||
/ \ |
|||
c--A-----b--d |
|||
\ / |
|||
end |
|||
|
|||
Your goal is to find the number of distinct paths that start at start, end at end, and don't visit small caves more than once. There are two types of caves: big caves (written in uppercase, like A) and small caves (written in lowercase, like b). It would be a waste of time to visit any small cave more than once, but big caves are large enough that it might be worth visiting them multiple times. So, all paths you find should visit small caves at most once, and can visit big caves any number of times. |
|||
|
|||
Given these rules, there are 10 paths through this example cave system: |
|||
|
|||
start,A,b,A,c,A,end |
|||
start,A,b,A,end |
|||
start,A,b,end |
|||
start,A,c,A,b,A,end |
|||
start,A,c,A,b,end |
|||
start,A,c,A,end |
|||
start,A,end |
|||
start,b,A,c,A,end |
|||
start,b,A,end |
|||
start,b,end |
|||
|
|||
(Each line in the above list corresponds to a single path; the caves visited by that path are listed in the order they are visited and separated by commas.) |
|||
|
|||
Note that in this cave system, cave d is never visited by any path: to do so, cave b would need to be visited twice (once on the way to cave d and a second time when returning from cave d), and since cave b is small, this is not allowed. |
|||
|
|||
Here is a slightly larger example: |
|||
|
|||
dc-end |
|||
HN-start |
|||
start-kj |
|||
dc-start |
|||
dc-HN |
|||
LN-dc |
|||
HN-end |
|||
kj-sa |
|||
kj-HN |
|||
kj-dc |
|||
|
|||
The 19 paths through it are as follows: |
|||
|
|||
start,HN,dc,HN,end |
|||
start,HN,dc,HN,kj,HN,end |
|||
start,HN,dc,end |
|||
start,HN,dc,kj,HN,end |
|||
start,HN,end |
|||
start,HN,kj,HN,dc,HN,end |
|||
start,HN,kj,HN,dc,end |
|||
start,HN,kj,HN,end |
|||
start,HN,kj,dc,HN,end |
|||
start,HN,kj,dc,end |
|||
start,dc,HN,end |
|||
start,dc,HN,kj,HN,end |
|||
start,dc,end |
|||
start,dc,kj,HN,end |
|||
start,kj,HN,dc,HN,end |
|||
start,kj,HN,dc,end |
|||
start,kj,HN,end |
|||
start,kj,dc,HN,end |
|||
start,kj,dc,end |
|||
|
|||
Finally, this even larger example has 226 paths through it: |
|||
|
|||
fs-end |
|||
he-DX |
|||
fs-he |
|||
start-DX |
|||
pj-DX |
|||
end-zg |
|||
zg-sl |
|||
zg-pj |
|||
pj-he |
|||
RW-he |
|||
fs-DX |
|||
pj-RW |
|||
zg-RW |
|||
start-pj |
|||
he-WI |
|||
zg-he |
|||
pj-fs |
|||
start-RW |
|||
|
|||
How many paths through this cave system are there that visit small caves at most once? |
|||
|
|||
Your puzzle answer was 5076. |
|||
--- Part Two --- |
|||
|
|||
After reviewing the available paths, you realize you might have time to visit a single small cave twice. Specifically, big caves can be visited any number of times, a single small cave can be visited at most twice, and the remaining small caves can be visited at most once. However, the caves named start and end can only be visited exactly once each: once you leave the start cave, you may not return to it, and once you reach the end cave, the path must end immediately. |
|||
|
|||
Now, the 36 possible paths through the first example above are: |
|||
|
|||
start,A,b,A,b,A,c,A,end |
|||
start,A,b,A,b,A,end |
|||
start,A,b,A,b,end |
|||
start,A,b,A,c,A,b,A,end |
|||
start,A,b,A,c,A,b,end |
|||
start,A,b,A,c,A,c,A,end |
|||
start,A,b,A,c,A,end |
|||
start,A,b,A,end |
|||
start,A,b,d,b,A,c,A,end |
|||
start,A,b,d,b,A,end |
|||
start,A,b,d,b,end |
|||
start,A,b,end |
|||
start,A,c,A,b,A,b,A,end |
|||
start,A,c,A,b,A,b,end |
|||
start,A,c,A,b,A,c,A,end |
|||
start,A,c,A,b,A,end |
|||
start,A,c,A,b,d,b,A,end |
|||
start,A,c,A,b,d,b,end |
|||
start,A,c,A,b,end |
|||
start,A,c,A,c,A,b,A,end |
|||
start,A,c,A,c,A,b,end |
|||
start,A,c,A,c,A,end |
|||
start,A,c,A,end |
|||
start,A,end |
|||
start,b,A,b,A,c,A,end |
|||
start,b,A,b,A,end |
|||
start,b,A,b,end |
|||
start,b,A,c,A,b,A,end |
|||
start,b,A,c,A,b,end |
|||
start,b,A,c,A,c,A,end |
|||
start,b,A,c,A,end |
|||
start,b,A,end |
|||
start,b,d,b,A,c,A,end |
|||
start,b,d,b,A,end |
|||
start,b,d,b,end |
|||
start,b,end |
|||
|
|||
The slightly larger example above now has 103 paths through it, and the even larger example now has 3509 paths through it. |
|||
|
|||
Given these new rules, how many paths through this cave system are there? |
|||
|
|||
Your puzzle answer was 145643. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
@ -0,0 +1,22 @@ |
|||
end-MY |
|||
MY-xc |
|||
ho-NF |
|||
start-ho |
|||
NF-xc |
|||
NF-yf |
|||
end-yf |
|||
xc-TP |
|||
MY-qo |
|||
yf-TP |
|||
dc-NF |
|||
dc-xc |
|||
start-dc |
|||
yf-MY |
|||
MY-ho |
|||
EM-uh |
|||
xc-yf |
|||
ho-dc |
|||
uh-NF |
|||
yf-ho |
|||
end-uh |
|||
start-NF |
@ -0,0 +1,7 @@ |
|||
start-A |
|||
start-b |
|||
A-c |
|||
A-b |
|||
b-d |
|||
A-end |
|||
b-end |
@ -0,0 +1,10 @@ |
|||
dc-end |
|||
HN-start |
|||
start-kj |
|||
dc-start |
|||
dc-HN |
|||
LN-dc |
|||
HN-end |
|||
kj-sa |
|||
kj-HN |
|||
kj-dc |
@ -0,0 +1,18 @@ |
|||
fs-end |
|||
he-DX |
|||
fs-he |
|||
start-DX |
|||
pj-DX |
|||
end-zg |
|||
zg-sl |
|||
zg-pj |
|||
pj-he |
|||
RW-he |
|||
fs-DX |
|||
pj-RW |
|||
zg-RW |
|||
start-pj |
|||
he-WI |
|||
zg-he |
|||
pj-fs |
|||
start-RW |
@ -0,0 +1,38 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys |
|||
|
|||
def printi(dots): |
|||
st = '' |
|||
for y in range(max(dots,key=lambda x: x[1])[1]+1): |
|||
for x in range(max(dots,key=lambda x: x[0])[0]+1): |
|||
if (x,y) in dots: st += '#' |
|||
else: st += '.' |
|||
print(st) |
|||
st = '' |
|||
|
|||
def fold(f, dots): |
|||
ndots, c = set(), f[1] |
|||
if f[0] == 'x': r = 0 |
|||
elif f[0] == 'y': r = 1 |
|||
for dot in dots: |
|||
if dot[r] < c: ndots.add(dot) |
|||
elif dot[r] > c: ndots.add([(c-(dot[0]-c),dot[1]), (dot[0],c-(dot[1]-c))][r]) |
|||
return ndots |
|||
|
|||
if __name__ == '__main__': |
|||
lines = open(sys.argv[1]).read().split('\n\n') |
|||
dots = set([tuple(map(int, line.split(','))) for line in lines[0].split('\n')]) |
|||
folds = [i for i in map(lambda x: (x[0],int(x[1])), [tuple(line.strip('fold along ').split('=')) for line in lines[1].split('\n')[:-1]])] |
|||
|
|||
# challenge 1 |
|||
res1 = str(sum(1 for dot in fold(folds[0], dots))) |
|||
print("challenge 1:" + "\n" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
for f in folds: dots = fold(f,dots) |
|||
printi(dots) |
|||
|
|||
res2 = "read yourself please xD" |
|||
print("challenge 2:" + "\n" + res2 + "\n") |
|||
|
@ -0,0 +1,121 @@ |
|||
--- Day 13: Transparent Origami --- |
|||
|
|||
You reach another volcanically active part of the cave. It would be nice if you could do some kind of thermal imaging so you could tell ahead of time which caves are too hot to safely enter. |
|||
|
|||
Fortunately, the submarine seems to be equipped with a thermal camera! When you activate it, you are greeted with: |
|||
|
|||
Congratulations on your purchase! To activate this infrared thermal imaging |
|||
camera system, please enter the code found on page 1 of the manual. |
|||
|
|||
Apparently, the Elves have never used this feature. To your surprise, you manage to find the manual; as you go to open it, page 1 falls out. It's a large sheet of transparent paper! The transparent paper is marked with random dots and includes instructions on how to fold it up (your puzzle input). For example: |
|||
|
|||
6,10 |
|||
0,14 |
|||
9,10 |
|||
0,3 |
|||
10,4 |
|||
4,11 |
|||
6,0 |
|||
6,12 |
|||
4,1 |
|||
0,13 |
|||
10,12 |
|||
3,4 |
|||
3,0 |
|||
8,4 |
|||
1,10 |
|||
2,14 |
|||
8,10 |
|||
9,0 |
|||
|
|||
fold along y=7 |
|||
fold along x=5 |
|||
|
|||
The first section is a list of dots on the transparent paper. 0,0 represents the top-left coordinate. The first value, x, increases to the right. The second value, y, increases downward. So, the coordinate 3,0 is to the right of 0,0, and the coordinate 0,7 is below 0,0. The coordinates in this example form the following pattern, where # is a dot on the paper and . is an empty, unmarked position: |
|||
|
|||
...#..#..#. |
|||
....#...... |
|||
........... |
|||
#.......... |
|||
...#....#.# |
|||
........... |
|||
........... |
|||
........... |
|||
........... |
|||
........... |
|||
.#....#.##. |
|||
....#...... |
|||
......#...# |
|||
#.......... |
|||
#.#........ |
|||
|
|||
Then, there is a list of fold instructions. Each instruction indicates a line on the transparent paper and wants you to fold the paper up (for horizontal y=... lines) or left (for vertical x=... lines). In this example, the first fold instruction is fold along y=7, which designates the line formed by all of the positions where y is 7 (marked here with -): |
|||
|
|||
...#..#..#. |
|||
....#...... |
|||
........... |
|||
#.......... |
|||
...#....#.# |
|||
........... |
|||
........... |
|||
----------- |
|||
........... |
|||
........... |
|||
.#....#.##. |
|||
....#...... |
|||
......#...# |
|||
#.......... |
|||
#.#........ |
|||
|
|||
Because this is a horizontal line, fold the bottom half up. Some of the dots might end up overlapping after the fold is complete, but dots will never appear exactly on a fold line. The result of doing this fold looks like this: |
|||
|
|||
#.##..#..#. |
|||
#...#...... |
|||
......#...# |
|||
#...#...... |
|||
.#.#..#.### |
|||
........... |
|||
........... |
|||
|
|||
Now, only 17 dots are visible. |
|||
|
|||
Notice, for example, the two dots in the bottom left corner before the transparent paper is folded; after the fold is complete, those dots appear in the top left corner (at 0,0 and 0,1). Because the paper is transparent, the dot just below them in the result (at 0,3) remains visible, as it can be seen through the transparent paper. |
|||
|
|||
Also notice that some dots can end up overlapping; in this case, the dots merge together and become a single dot. |
|||
|
|||
The second fold instruction is fold along x=5, which indicates this line: |
|||
|
|||
#.##.|#..#. |
|||
#...#|..... |
|||
.....|#...# |
|||
#...#|..... |
|||
.#.#.|#.### |
|||
.....|..... |
|||
.....|..... |
|||
|
|||
Because this is a vertical line, fold left: |
|||
|
|||
##### |
|||
#...# |
|||
#...# |
|||
#...# |
|||
##### |
|||
..... |
|||
..... |
|||
|
|||
The instructions made a square! |
|||
|
|||
The transparent paper is pretty big, so for now, focus on just completing the first fold. After the first fold in the example above, 17 dots are visible - dots that end up overlapping after the fold is completed count as a single dot. |
|||
|
|||
How many dots are visible after completing just the first fold instruction on your transparent paper? |
|||
|
|||
Your puzzle answer was 745. |
|||
--- Part Two --- |
|||
|
|||
Finish folding the transparent paper according to the instructions. The manual says the code is always eight capital letters. |
|||
|
|||
What code do you use to activate the infrared thermal imaging camera system? |
|||
|
|||
Your puzzle answer was ABKJFBGC. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
@ -0,0 +1,915 @@ |
|||
938,670 |
|||
246,156 |
|||
622,476 |
|||
137,296 |
|||
708,323 |
|||
1019,283 |
|||
415,505 |
|||
1043,234 |
|||
666,871 |
|||
157,893 |
|||
969,266 |
|||
1280,690 |
|||
987,260 |
|||
296,428 |
|||
1302,361 |
|||
92,168 |
|||
206,204 |
|||
937,659 |
|||
551,488 |
|||
147,456 |
|||
1279,42 |
|||
463,154 |
|||
407,266 |
|||
1153,893 |
|||
495,372 |
|||
733,459 |
|||
378,169 |
|||
48,705 |
|||
31,852 |
|||
577,571 |
|||
36,672 |
|||
1014,661 |
|||
441,880 |
|||
1305,791 |
|||
115,553 |
|||
455,267 |
|||
360,833 |
|||
915,455 |
|||
346,53 |
|||
606,367 |
|||
1014,513 |
|||
930,633 |
|||
190,350 |
|||
564,577 |
|||
1205,376 |
|||
928,462 |
|||
577,435 |
|||
825,686 |
|||
517,598 |
|||
782,119 |
|||
1110,539 |
|||
67,236 |
|||
77,185 |
|||
577,723 |
|||
808,855 |
|||
139,742 |
|||
865,414 |
|||
159,522 |
|||
1159,626 |
|||
440,58 |
|||
743,505 |
|||
252,502 |
|||
1190,659 |
|||
855,521 |
|||
1094,185 |
|||
798,176 |
|||
1114,61 |
|||
174,695 |
|||
427,581 |
|||
161,670 |
|||
74,222 |
|||
1250,829 |
|||
930,261 |
|||
398,497 |
|||
541,47 |
|||
340,102 |
|||
1057,614 |
|||
820,753 |
|||
1057,453 |
|||
1158,141 |
|||
492,499 |
|||
267,234 |
|||
642,568 |
|||
904,586 |
|||
1274,47 |
|||
169,781 |
|||
241,164 |
|||
1037,621 |
|||
50,254 |
|||
44,63 |
|||
388,561 |
|||
1099,522 |
|||
1255,809 |
|||
736,171 |
|||
1139,145 |
|||
323,708 |
|||
928,686 |
|||
527,851 |
|||
478,771 |
|||
895,505 |
|||
320,455 |
|||
156,268 |
|||
787,399 |
|||
1136,695 |
|||
150,751 |
|||
252,537 |
|||
1242,631 |
|||
468,40 |
|||
436,208 |
|||
380,261 |
|||
324,3 |
|||
954,93 |
|||
946,504 |
|||
991,817 |
|||
604,177 |
|||
565,348 |
|||
705,406 |
|||
89,38 |
|||
735,418 |
|||
234,161 |
|||
880,0 |
|||
956,553 |
|||
523,847 |
|||
654,753 |
|||
946,266 |
|||
465,822 |
|||
768,282 |
|||
3,5 |
|||
18,513 |
|||
758,737 |
|||
980,639 |
|||
1248,725 |
|||
1250,570 |
|||
807,716 |
|||
1138,375 |
|||
1076,354 |
|||
922,561 |
|||
417,434 |
|||
831,626 |
|||
115,861 |
|||
1255,710 |
|||
793,473 |
|||
77,499 |
|||
964,169 |
|||
989,343 |
|||
875,183 |
|||
758,224 |
|||
398,397 |
|||
1208,670 |
|||
903,266 |
|||
77,403 |
|||
82,176 |
|||
427,313 |
|||
139,152 |
|||
810,550 |
|||
577,619 |
|||
867,665 |
|||
443,665 |
|||
485,775 |
|||
272,686 |
|||
196,833 |
|||
291,163 |
|||
1029,387 |
|||
1221,38 |
|||
1019,611 |
|||
544,78 |
|||
299,826 |
|||
1289,854 |
|||
1160,751 |
|||
1230,469 |
|||
408,290 |
|||
1056,176 |
|||
281,507 |
|||
170,828 |
|||
18,828 |
|||
1175,329 |
|||
539,413 |
|||
698,764 |
|||
373,59 |
|||
433,376 |
|||
1020,504 |
|||
85,771 |
|||
151,716 |
|||
934,245 |
|||
172,792 |
|||
383,78 |
|||
1223,725 |
|||
348,278 |
|||
3,453 |
|||
152,525 |
|||
1037,618 |
|||
1197,686 |
|||
319,749 |
|||
328,318 |
|||
623,42 |
|||
1258,521 |
|||
441,14 |
|||
862,802 |
|||
1233,459 |
|||
1140,791 |
|||
994,509 |
|||
417,262 |
|||
517,712 |
|||
1029,507 |
|||
52,821 |
|||
984,133 |
|||
1120,96 |
|||
1186,764 |
|||
482,760 |
|||
1114,754 |
|||
190,96 |
|||
728,494 |
|||
1071,602 |
|||
1019,122 |
|||
92,726 |
|||
1221,856 |
|||
710,686 |
|||
1140,49 |
|||
485,208 |
|||
661,775 |
|||
774,511 |
|||
154,123 |
|||
383,816 |
|||
986,3 |
|||
455,409 |
|||
200,614 |
|||
584,749 |
|||
616,662 |
|||
493,353 |
|||
572,649 |
|||
80,171 |
|||
932,177 |
|||
1237,614 |
|||
574,171 |
|||
480,247 |
|||
656,193 |
|||
1153,449 |
|||
502,257 |
|||
1303,632 |
|||
733,403 |
|||
1274,672 |
|||
872,515 |
|||
219,631 |
|||
353,9 |
|||
1020,47 |
|||
683,602 |
|||
62,169 |
|||
734,586 |
|||
325,614 |
|||
482,323 |
|||
1160,143 |
|||
987,5 |
|||
982,766 |
|||
1115,495 |
|||
1086,894 |
|||
441,546 |
|||
816,675 |
|||
1272,662 |
|||
929,618 |
|||
865,480 |
|||
237,262 |
|||
729,728 |
|||
1197,159 |
|||
880,289 |
|||
68,148 |
|||
816,227 |
|||
924,198 |
|||
113,686 |
|||
704,245 |
|||
745,486 |
|||
500,550 |
|||
510,824 |
|||
817,353 |
|||
708,571 |
|||
1021,77 |
|||
929,276 |
|||
704,79 |
|||
1061,51 |
|||
1002,514 |
|||
351,152 |
|||
934,693 |
|||
216,709 |
|||
736,469 |
|||
130,385 |
|||
1221,546 |
|||
276,254 |
|||
1054,556 |
|||
1164,7 |
|||
2,107 |
|||
812,626 |
|||
610,383 |
|||
1069,164 |
|||
738,848 |
|||
462,73 |
|||
618,579 |
|||
299,516 |
|||
126,775 |
|||
415,389 |
|||
1044,113 |
|||
1115,47 |
|||
1062,586 |
|||
746,129 |
|||
976,397 |
|||
1309,166 |
|||
602,323 |
|||
494,227 |
|||
888,820 |
|||
835,662 |
|||
728,400 |
|||
1009,397 |
|||
410,718 |
|||
273,618 |
|||
253,453 |
|||
865,59 |
|||
528,775 |
|||
1002,380 |
|||
224,446 |
|||
1305,327 |
|||
364,166 |
|||
189,744 |
|||
67,658 |
|||
1307,67 |
|||
572,848 |
|||
957,9 |
|||
454,602 |
|||
743,837 |
|||
811,593 |
|||
113,882 |
|||
77,275 |
|||
1232,138 |
|||
482,326 |
|||
216,653 |
|||
987,827 |
|||
984,761 |
|||
1121,150 |
|||
90,765 |
|||
274,323 |
|||
701,123 |
|||
308,514 |
|||
1159,178 |
|||
80,723 |
|||
1154,268 |
|||
1255,16 |
|||
20,77 |
|||
745,856 |
|||
729,726 |
|||
628,229 |
|||
475,662 |
|||
120,659 |
|||
1091,711 |
|||
688,476 |
|||
500,312 |
|||
408,171 |
|||
996,543 |
|||
323,453 |
|||
826,66 |
|||
508,775 |
|||
89,632 |
|||
601,52 |
|||
686,18 |
|||
638,455 |
|||
1094,67 |
|||
562,509 |
|||
102,593 |
|||
517,312 |
|||
435,263 |
|||
594,829 |
|||
930,323 |
|||
1073,348 |
|||
524,509 |
|||
659,653 |
|||
895,690 |
|||
443,372 |
|||
1149,670 |
|||
763,408 |
|||
160,227 |
|||
36,628 |
|||
571,28 |
|||
687,70 |
|||
1307,889 |
|||
200,539 |
|||
87,243 |
|||
818,753 |
|||
1230,873 |
|||
152,173 |
|||
408,738 |
|||
219,711 |
|||
890,845 |
|||
606,79 |
|||
1168,77 |
|||
1200,78 |
|||
688,154 |
|||
335,184 |
|||
629,173 |
|||
793,712 |
|||
318,571 |
|||
769,686 |
|||
1310,141 |
|||
234,354 |
|||
3,403 |
|||
155,322 |
|||
579,516 |
|||
706,53 |
|||
977,241 |
|||
1178,652 |
|||
1054,637 |
|||
5,791 |
|||
316,593 |
|||
681,528 |
|||
226,152 |
|||
838,53 |
|||
316,301 |
|||
947,283 |
|||
647,262 |
|||
833,427 |
|||
1014,233 |
|||
1058,502 |
|||
562,207 |
|||
224,894 |
|||
836,775 |
|||
869,14 |
|||
256,273 |
|||
541,686 |
|||
1227,345 |
|||
1074,99 |
|||
92,562 |
|||
489,306 |
|||
1149,801 |
|||
172,760 |
|||
811,301 |
|||
1230,425 |
|||
512,718 |
|||
1084,152 |
|||
213,14 |
|||
813,445 |
|||
628,665 |
|||
1011,516 |
|||
850,773 |
|||
21,40 |
|||
1033,406 |
|||
783,43 |
|||
719,840 |
|||
1225,164 |
|||
219,152 |
|||
1222,173 |
|||
1038,686 |
|||
236,99 |
|||
1220,99 |
|||
761,824 |
|||
909,814 |
|||
740,756 |
|||
676,278 |
|||
219,183 |
|||
1218,168 |
|||
1233,485 |
|||
281,682 |
|||
403,465 |
|||
672,455 |
|||
1037,276 |
|||
649,775 |
|||
622,292 |
|||
1303,262 |
|||
435,94 |
|||
68,631 |
|||
402,201 |
|||
326,133 |
|||
574,51 |
|||
986,891 |
|||
1120,350 |
|||
912,621 |
|||
970,792 |
|||
549,824 |
|||
253,677 |
|||
536,292 |
|||
1290,177 |
|||
28,190 |
|||
356,93 |
|||
842,40 |
|||
769,208 |
|||
653,877 |
|||
1215,460 |
|||
803,8 |
|||
1262,245 |
|||
417,348 |
|||
865,507 |
|||
1116,325 |
|||
580,828 |
|||
314,211 |
|||
1233,185 |
|||
582,624 |
|||
818,499 |
|||
661,464 |
|||
726,749 |
|||
933,488 |
|||
77,459 |
|||
604,702 |
|||
454,7 |
|||
435,711 |
|||
416,873 |
|||
1130,439 |
|||
137,312 |
|||
113,208 |
|||
582,494 |
|||
1138,102 |
|||
924,310 |
|||
281,387 |
|||
569,663 |
|||
652,143 |
|||
353,885 |
|||
602,633 |
|||
816,219 |
|||
606,649 |
|||
191,565 |
|||
55,464 |
|||
846,96 |
|||
422,759 |
|||
253,441 |
|||
560,311 |
|||
36,679 |
|||
1290,525 |
|||
1158,173 |
|||
333,775 |
|||
704,649 |
|||
527,857 |
|||
692,579 |
|||
72,176 |
|||
584,690 |
|||
562,687 |
|||
1121,822 |
|||
599,246 |
|||
319,593 |
|||
1124,488 |
|||
657,877 |
|||
457,675 |
|||
1179,266 |
|||
668,568 |
|||
577,171 |
|||
170,845 |
|||
865,387 |
|||
452,578 |
|||
174,141 |
|||
119,203 |
|||
70,674 |
|||
745,348 |
|||
12,326 |
|||
1240,749 |
|||
239,389 |
|||
574,313 |
|||
709,52 |
|||
542,282 |
|||
31,824 |
|||
110,368 |
|||
182,219 |
|||
353,437 |
|||
755,133 |
|||
1029,212 |
|||
571,866 |
|||
494,675 |
|||
715,212 |
|||
920,844 |
|||
1181,667 |
|||
704,525 |
|||
20,369 |
|||
729,814 |
|||
1168,176 |
|||
290,119 |
|||
1196,143 |
|||
748,338 |
|||
1183,25 |
|||
221,376 |
|||
1258,883 |
|||
331,226 |
|||
700,383 |
|||
731,516 |
|||
649,430 |
|||
227,502 |
|||
783,3 |
|||
959,152 |
|||
440,836 |
|||
726,369 |
|||
70,749 |
|||
1171,152 |
|||
897,388 |
|||
154,344 |
|||
661,430 |
|||
994,385 |
|||
507,8 |
|||
800,70 |
|||
739,345 |
|||
1192,511 |
|||
478,751 |
|||
853,890 |
|||
298,821 |
|||
808,39 |
|||
687,852 |
|||
254,176 |
|||
127,473 |
|||
1195,553 |
|||
733,619 |
|||
214,58 |
|||
788,793 |
|||
723,455 |
|||
465,150 |
|||
10,471 |
|||
373,235 |
|||
623,294 |
|||
281,212 |
|||
1016,173 |
|||
912,257 |
|||
1061,388 |
|||
1190,235 |
|||
546,656 |
|||
378,389 |
|||
676,616 |
|||
1240,397 |
|||
783,409 |
|||
400,64 |
|||
569,282 |
|||
1292,841 |
|||
663,262 |
|||
1262,705 |
|||
457,4 |
|||
1232,308 |
|||
226,742 |
|||
649,327 |
|||
952,381 |
|||
567,651 |
|||
724,263 |
|||
940,316 |
|||
956,240 |
|||
53,500 |
|||
1298,326 |
|||
1016,866 |
|||
1223,690 |
|||
688,292 |
|||
1076,332 |
|||
632,782 |
|||
454,740 |
|||
131,495 |
|||
152,141 |
|||
989,653 |
|||
189,488 |
|||
1086,224 |
|||
1072,873 |
|||
651,515 |
|||
870,58 |
|||
932,169 |
|||
1258,409 |
|||
700,511 |
|||
769,735 |
|||
5,567 |
|||
321,241 |
|||
200,740 |
|||
576,586 |
|||
581,726 |
|||
303,742 |
|||
132,652 |
|||
1014,428 |
|||
380,633 |
|||
330,815 |
|||
73,280 |
|||
1207,488 |
|||
536,511 |
|||
902,604 |
|||
446,852 |
|||
448,11 |
|||
77,485 |
|||
594,65 |
|||
1039,78 |
|||
708,11 |
|||
482,550 |
|||
331,345 |
|||
373,771 |
|||
333,103 |
|||
959,742 |
|||
1220,795 |
|||
36,215 |
|||
848,821 |
|||
726,145 |
|||
482,568 |
|||
682,665 |
|||
937,771 |
|||
298,353 |
|||
774,383 |
|||
28,373 |
|||
826,49 |
|||
364,266 |
|||
716,0 |
|||
883,581 |
|||
1094,795 |
|||
212,306 |
|||
136,789 |
|||
401,814 |
|||
659,889 |
|||
422,74 |
|||
541,208 |
|||
20,817 |
|||
364,728 |
|||
785,785 |
|||
937,212 |
|||
1104,204 |
|||
74,290 |
|||
855,309 |
|||
7,856 |
|||
587,439 |
|||
663,38 |
|||
174,199 |
|||
282,679 |
|||
1120,798 |
|||
845,582 |
|||
290,847 |
|||
92,332 |
|||
1243,236 |
|||
1020,266 |
|||
443,105 |
|||
497,449 |
|||
728,270 |
|||
124,764 |
|||
1280,513 |
|||
535,203 |
|||
741,771 |
|||
278,201 |
|||
708,633 |
|||
599,269 |
|||
842,854 |
|||
994,301 |
|||
18,841 |
|||
324,891 |
|||
480,641 |
|||
740,138 |
|||
95,882 |
|||
734,308 |
|||
577,282 |
|||
793,296 |
|||
932,389 |
|||
705,488 |
|||
52,521 |
|||
180,455 |
|||
1190,540 |
|||
581,814 |
|||
420,637 |
|||
160,667 |
|||
478,359 |
|||
190,798 |
|||
150,143 |
|||
130,826 |
|||
89,348 |
|||
569,123 |
|||
771,301 |
|||
853,442 |
|||
1146,753 |
|||
733,395 |
|||
348,333 |
|||
441,287 |
|||
216,99 |
|||
3,67 |
|||
176,183 |
|||
547,856 |
|||
68,711 |
|||
605,406 |
|||
544,627 |
|||
105,152 |
|||
856,103 |
|||
1032,201 |
|||
618,131 |
|||
599,878 |
|||
604,841 |
|||
1233,275 |
|||
479,626 |
|||
1151,522 |
|||
21,854 |
|||
668,543 |
|||
1028,740 |
|||
113,159 |
|||
746,577 |
|||
586,863 |
|||
1247,840 |
|||
272,208 |
|||
201,138 |
|||
249,58 |
|||
159,372 |
|||
87,725 |
|||
776,540 |
|||
907,579 |
|||
1099,677 |
|||
468,854 |
|||
748,687 |
|||
303,152 |
|||
1094,241 |
|||
52,373 |
|||
85,739 |
|||
48,189 |
|||
52,883 |
|||
157,445 |
|||
430,0 |
|||
185,234 |
|||
127,627 |
|||
6,887 |
|||
527,627 |
|||
582,176 |
|||
1118,521 |
|||
216,67 |
|||
386,198 |
|||
1150,227 |
|||
172,344 |
|||
687,600 |
|||
120,690 |
|||
387,712 |
|||
1203,632 |
|||
888,123 |
|||
689,676 |
|||
468,488 |
|||
933,770 |
|||
199,267 |
|||
256,497 |
|||
586,263 |
|||
895,389 |
|||
110,627 |
|||
479,268 |
|||
741,730 |
|||
694,232 |
|||
666,301 |
|||
704,490 |
|||
129,667 |
|||
1242,711 |
|||
830,641 |
|||
194,325 |
|||
618,315 |
|||
910,64 |
|||
1052,298 |
|||
1171,742 |
|||
869,546 |
|||
1153,880 |
|||
1148,128 |
|||
381,173 |
|||
1233,11 |
|||
1240,130 |
|||
103,488 |
|||
274,267 |
|||
402,693 |
|||
594,381 |
|||
495,267 |
|||
246,425 |
|||
1292,268 |
|||
602,37 |
|||
539,677 |
|||
793,421 |
|||
711,16 |
|||
89,856 |
|||
1073,460 |
|||
1020,180 |
|||
763,856 |
|||
438,205 |
|||
365,817 |
|||
1210,600 |
|||
372,224 |
|||
135,565 |
|||
853,452 |
|||
239,242 |
|||
363,283 |
|||
1079,348 |
|||
142,176 |
|||
107,632 |
|||
534,242 |
|||
530,130 |
|||
142,77 |
|||
1290,77 |
|||
1218,385 |
|||
249,51 |
|||
214,57 |
|||
687,42 |
|||
972,77 |
|||
1173,296 |
|||
808,305 |
|||
813,1 |
|||
1225,155 |
|||
333,791 |
|||
774,607 |
|||
1300,23 |
|||
1140,103 |
|||
340,550 |
|||
154,582 |
|||
10,423 |
|||
38,662 |
|||
565,856 |
|||
354,688 |
|||
333,241 |
|||
1256,208 |
|||
272,656 |
|||
736,51 |
|||
880,672 |
|||
1145,894 |
|||
1022,379 |
|||
566,721 |
|||
668,102 |
|||
503,716 |
|||
912,497 |
|||
610,511 |
|||
1292,828 |
|||
282,222 |
|||
22,782 |
|||
572,718 |
|||
|
|||
fold along x=655 |
|||
fold along y=447 |
|||
fold along x=327 |
|||
fold along y=223 |
|||
fold along x=163 |
|||
fold along y=111 |
|||
fold along x=81 |
|||
fold along y=55 |
|||
fold along x=40 |
|||
fold along y=27 |
|||
fold along y=13 |
|||
fold along y=6 |
@ -0,0 +1,21 @@ |
|||
6,10 |
|||
0,14 |
|||
9,10 |
|||
0,3 |
|||
10,4 |
|||
4,11 |
|||
6,0 |
|||
6,12 |
|||
4,1 |
|||
0,13 |
|||
10,12 |
|||
3,4 |
|||
3,0 |
|||
8,4 |
|||
1,10 |
|||
2,14 |
|||
8,10 |
|||
9,0 |
|||
|
|||
fold along y=7 |
|||
fold along x=5 |
@ -0,0 +1,49 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys |
|||
from collections import Counter |
|||
from copy import deepcopy |
|||
|
|||
def step(cons,s): |
|||
for _ in range(s): |
|||
ncons = {} |
|||
for (a,b),v in cons.items(): |
|||
if (a, rules[a+b]) not in ncons: ncons[(a, rules[a+b])] = 0 |
|||
if (rules[a+b], b) not in ncons: ncons[(rules[a+b], b)] = 0 |
|||
ncons[(a, rules[a+b])] += v |
|||
ncons[(rules[a+b],b)] += v |
|||
cons = deepcopy(ncons) |
|||
return cons |
|||
|
|||
def countp(cons): |
|||
ex = {} |
|||
for k in nex.keys(): |
|||
ex[k[0]] = 0 |
|||
ex[k[1]] = 0 |
|||
ex[start[0]] += 1 |
|||
ex[start[-1]] += 1 |
|||
for k,v in nex.items(): |
|||
ex[k[0]] += v |
|||
ex[k[1]] += v |
|||
return ex |
|||
|
|||
if __name__ == '__main__': |
|||
start, rules = open(sys.argv[1]).read().split('\n\n') |
|||
rules = [r.split(' -> ') for r in rules.split('\n')] |
|||
rules = {a[0]:a[1] for a in rules[:-1]} |
|||
nex = {} |
|||
for a,b in zip(start[:-1],start[1:]): |
|||
if (a,b) not in nex: nex[(a,b)] = 0 |
|||
nex[(a,b)] +=1 |
|||
# challenge 1 |
|||
nex = step(nex,10) |
|||
res = countp(nex) |
|||
res1 = str(max(res.values())//2-min(res.values())//2) |
|||
print("challenge 1:" +"\n" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
nex = step(nex,30) |
|||
res = countp(nex) |
|||
res2 = str(max(res.values())//2-min(res.values())//2) |
|||
print("challenge 2:" +"\n" + res2 + "\n") |
|||
|
@ -0,0 +1,65 @@ |
|||
--- Day 14: Extended Polymerization --- |
|||
|
|||
The incredible pressures at this depth are starting to put a strain on your submarine. The submarine has polymerization equipment that would produce suitable materials to reinforce the submarine, and the nearby volcanically-active caves should even have the necessary input elements in sufficient quantities. |
|||
|
|||
The submarine manual contains instructions for finding the optimal polymer formula; specifically, it offers a polymer template and a list of pair insertion rules (your puzzle input). You just need to work out what polymer would result after repeating the pair insertion process a few times. |
|||
|
|||
For example: |
|||
|
|||
NNCB |
|||
|
|||
CH -> B |
|||
HH -> N |
|||
CB -> H |
|||
NH -> C |
|||
HB -> C |
|||
HC -> B |
|||
HN -> C |
|||
NN -> C |
|||
BH -> H |
|||
NC -> B |
|||
NB -> B |
|||
BN -> B |
|||
BB -> N |
|||
BC -> B |
|||
CC -> N |
|||
CN -> C |
|||
|
|||
The first line is the polymer template - this is the starting point of the process. |
|||
|
|||
The following section defines the pair insertion rules. A rule like AB -> C means that when elements A and B are immediately adjacent, element C should be inserted between them. These insertions all happen simultaneously. |
|||
|
|||
So, starting with the polymer template NNCB, the first step simultaneously considers all three pairs: |
|||
|
|||
The first pair (NN) matches the rule NN -> C, so element C is inserted between the first N and the second N. |
|||
The second pair (NC) matches the rule NC -> B, so element B is inserted between the N and the C. |
|||
The third pair (CB) matches the rule CB -> H, so element H is inserted between the C and the B. |
|||
|
|||
Note that these pairs overlap: the second element of one pair is the first element of the next pair. Also, because all pairs are considered simultaneously, inserted elements are not considered to be part of a pair until the next step. |
|||
|
|||
After the first step of this process, the polymer becomes NCNBCHB. |
|||
|
|||
Here are the results of a few steps using the above rules: |
|||
|
|||
Template: NNCB |
|||
After step 1: NCNBCHB |
|||
After step 2: NBCCNBBBCBHCB |
|||
After step 3: NBBBCNCCNBBNBNBBCHBHHBCHB |
|||
After step 4: NBBNBNBBCCNBCNCCNBBNBBNBBBNBBNBBCBHCBHHNHCBBCBHCB |
|||
|
|||
This polymer grows quickly. After step 5, it has length 97; After step 10, it has length 3073. After step 10, B occurs 1749 times, C occurs 298 times, H occurs 161 times, and N occurs 865 times; taking the quantity of the most common element (B, 1749) and subtracting the quantity of the least common element (H, 161) produces 1749 - 161 = 1588. |
|||
|
|||
Apply 10 steps of pair insertion to the polymer template and find the most and least common elements in the result. What do you get if you take the quantity of the most common element and subtract the quantity of the least common element? |
|||
|
|||
Your puzzle answer was 3697. |
|||
--- Part Two --- |
|||
|
|||
The resulting polymer isn't nearly strong enough to reinforce the submarine. You'll need to run more steps of the pair insertion process; a total of 40 steps should do it. |
|||
|
|||
In the above example, the most common element is B (occurring 2192039569602 times) and the least common element is H (occurring 3849876073 times); subtracting these produces 2188189693529. |
|||
|
|||
Apply 40 steps of pair insertion to the polymer template and find the most and least common elements in the result. What do you get if you take the quantity of the most common element and subtract the quantity of the least common element? |
|||
|
|||
Your puzzle answer was 4371307836157. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
@ -0,0 +1,102 @@ |
|||
CPSSSFCFOFVFNVPKBFVN |
|||
|
|||
NV -> V |
|||
CF -> O |
|||
BB -> F |
|||
SB -> H |
|||
KF -> O |
|||
SP -> H |
|||
CS -> V |
|||
VF -> F |
|||
PC -> H |
|||
PH -> H |
|||
SF -> F |
|||
CP -> B |
|||
BC -> H |
|||
PB -> V |
|||
KO -> B |
|||
CV -> S |
|||
ON -> B |
|||
PV -> F |
|||
OO -> B |
|||
VV -> B |
|||
NO -> B |
|||
SH -> N |
|||
FC -> C |
|||
VO -> B |
|||
NN -> C |
|||
HH -> S |
|||
CK -> C |
|||
PF -> N |
|||
SN -> K |
|||
OK -> F |
|||
FH -> S |
|||
BP -> K |
|||
HO -> K |
|||
FB -> P |
|||
HC -> N |
|||
FP -> P |
|||
NC -> H |
|||
PK -> O |
|||
BV -> P |
|||
HK -> S |
|||
PP -> N |
|||
VC -> K |
|||
CH -> C |
|||
KS -> V |
|||
KB -> V |
|||
FN -> P |
|||
BS -> O |
|||
PS -> N |
|||
NS -> B |
|||
PN -> N |
|||
NP -> H |
|||
CB -> S |
|||
SV -> O |
|||
OC -> H |
|||
BO -> C |
|||
HN -> N |
|||
HP -> N |
|||
OF -> H |
|||
FS -> S |
|||
KV -> P |
|||
HV -> S |
|||
VS -> P |
|||
BH -> N |
|||
CC -> V |
|||
VN -> H |
|||
NF -> B |
|||
NK -> N |
|||
CN -> F |
|||
FV -> P |
|||
NH -> S |
|||
OV -> H |
|||
KN -> F |
|||
SO -> H |
|||
OP -> N |
|||
KC -> P |
|||
HB -> B |
|||
BN -> V |
|||
VP -> N |
|||
HS -> S |
|||
VK -> C |
|||
VH -> H |
|||
OS -> C |
|||
FO -> B |
|||
NB -> P |
|||
KP -> V |
|||
SS -> O |
|||
BK -> F |
|||
SK -> N |
|||
HF -> O |
|||
PO -> F |
|||
OH -> B |
|||
KK -> O |
|||
FK -> S |
|||
VB -> V |
|||
OB -> C |
|||
KH -> H |
|||
SC -> F |
|||
FF -> H |
|||
CO -> V |
|||
BF -> H |
@ -0,0 +1,18 @@ |
|||
NNCB |
|||
|
|||
CH -> B |
|||
HH -> N |
|||
CB -> H |
|||
NH -> C |
|||
HB -> C |
|||
HC -> B |
|||
HN -> C |
|||
NN -> C |
|||
BH -> H |
|||
NC -> B |
|||
NB -> B |
|||
BN -> B |
|||
BB -> N |
|||
BC -> B |
|||
CC -> N |
|||
CN -> C |
@ -0,0 +1,75 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys |
|||
|
|||
def memo(f): |
|||
memo = {} |
|||
|
|||
def f2(a,x,y,c,e): |
|||
if (x,y) not in memo: memo[(x,y)] = f(a,x,y,c,e) |
|||
return memo[(x,y)] |
|||
return f2 |
|||
|
|||
def nb(sx, sy): |
|||
n = [(0,1), (1,0), (0,-1), (-1,0)] |
|||
return [(max(0,sx+x), max(0,sy+y)) for x,y in n] |
|||
|
|||
def dijkstra(graph, s): |
|||
a = {} |
|||
v = {} |
|||
Q = initG(graph, s, a, v) |
|||
lq = len(Q) |
|||
while len(Q) > 0: |
|||
u = min([u for u in Q], key=lambda x: a[x]) |
|||
Q.remove(u) |
|||
for vo in nb(*u): |
|||
if vo in Q: |
|||
distance_update(graph, u,vo,a,v) |
|||
if (len(Q)/lq * 100 % 1) == 0: |
|||
print("|", end='', flush=True) |
|||
print("\n") |
|||
return v |
|||
|
|||
def initG(graph, s, a, v): |
|||
for vo in graph.keys(): |
|||
a[vo] = 9999999999999999 |
|||
v[vo] = 'null' |
|||
a[s] = 0 |
|||
Q = [n for n in graph.keys()] |
|||
return Q |
|||
|
|||
def distance_update(g, u,vo,a,v): |
|||
alt = a[u] + g[u] |
|||
if alt < a[vo]: |
|||
a[vo] = alt |
|||
v[vo] = u |
|||
|
|||
def shortest_path(g, d, v): |
|||
w = [d] |
|||
u = d |
|||
r = 0 |
|||
while v[u] != 'null': |
|||
r += g[u] |
|||
u = v[u] |
|||
w.append(u) |
|||
return w.reverse(), r |
|||
|
|||
if __name__ == '__main__': |
|||
nums = [[int(i) for i in list(line.strip('\n'))] for line in open(sys.argv[1])] |
|||
|
|||
# challenge 1 |
|||
g1 = {(x,y) : nums[y][x] for x in range(len(nums[0])) for y in range(len(nums))} |
|||
v = dijkstra(g1, (0,0)) |
|||
w, r = shortest_path(g1, (len(nums)-1, len(nums[0])-1), v) |
|||
|
|||
res1 = str(r) |
|||
print("challenge 1:" +"\n" + res1 + "\n") |
|||
|
|||
# challenge 2 - inefficient |
|||
g2 = {(x+i*len(nums[0]),y+j*len(nums)) : (nums[y][x] + i + j if nums[y][x] + i + j < 10 else (nums[y][x] + i + j) % 10 + 1) for x in range(len(nums[0])) for y in range(len(nums)) for i in range(5) for j in range(5)} |
|||
v = dijkstra(g2, (0,0)) |
|||
w, r = shortest_path(g2, (len(nums[0])*5-1, len(nums)*5-1), v) |
|||
|
|||
res2 = str(r) |
|||
print("challenge 2:" +"\n" + res2 + "\n") |
|||
|
@ -0,0 +1,164 @@ |
|||
--- Day 15: Chiton --- |
|||
|
|||
You've almost reached the exit of the cave, but the walls are getting closer together. Your submarine can barely still fit, though; the main problem is that the walls of the cave are covered in chitons, and it would be best not to bump any of them. |
|||
|
|||
The cavern is large, but has a very low ceiling, restricting your motion to two dimensions. The shape of the cavern resembles a square; a quick scan of chiton density produces a map of risk level throughout the cave (your puzzle input). For example: |
|||
|
|||
1163751742 |
|||
1381373672 |
|||
2136511328 |
|||
3694931569 |
|||
7463417111 |
|||
1319128137 |
|||
1359912421 |
|||
3125421639 |
|||
1293138521 |
|||
2311944581 |
|||
|
|||
You start in the top left position, your destination is the bottom right position, and you cannot move diagonally. The number at each position is its risk level; to determine the total risk of an entire path, add up the risk levels of each position you enter (that is, don't count the risk level of your starting position unless you enter it; leaving it adds no risk to your total). |
|||
|
|||
Your goal is to find a path with the lowest total risk. In this example, a path with the lowest total risk is highlighted here: |
|||
|
|||
1163751742 |
|||
1381373672 |
|||
2136511328 |
|||
3694931569 |
|||
7463417111 |
|||
1319128137 |
|||
1359912421 |
|||
3125421639 |
|||
1293138521 |
|||
2311944581 |
|||
|
|||
The total risk of this path is 40 (the starting position is never entered, so its risk is not counted). |
|||
|
|||
What is the lowest total risk of any path from the top left to the bottom right? |
|||
|
|||
Your puzzle answer was 487. |
|||
--- Part Two --- |
|||
|
|||
Now that you know how to find low-risk paths in the cave, you can try to find your way out. |
|||
|
|||
The entire cave is actually five times larger in both dimensions than you thought; the area you originally scanned is just one tile in a 5x5 tile area that forms the full map. Your original map tile repeats to the right and downward; each time the tile repeats to the right or downward, all of its risk levels are 1 higher than the tile immediately up or left of it. However, risk levels above 9 wrap back around to 1. So, if your original map had some position with a risk level of 8, then that same position on each of the 25 total tiles would be as follows: |
|||
|
|||
8 9 1 2 3 |
|||
9 1 2 3 4 |
|||
1 2 3 4 5 |
|||
2 3 4 5 6 |
|||
3 4 5 6 7 |
|||
|
|||
Each single digit above corresponds to the example position with a value of 8 on the top-left tile. Because the full map is actually five times larger in both dimensions, that position appears a total of 25 times, once in each duplicated tile, with the values shown above. |
|||
|
|||
Here is the full five-times-as-large version of the first example above, with the original map in the top left corner highlighted: |
|||
|
|||
11637517422274862853338597396444961841755517295286 |
|||
13813736722492484783351359589446246169155735727126 |
|||
21365113283247622439435873354154698446526571955763 |
|||
36949315694715142671582625378269373648937148475914 |
|||
74634171118574528222968563933317967414442817852555 |
|||
13191281372421239248353234135946434524615754563572 |
|||
13599124212461123532357223464346833457545794456865 |
|||
31254216394236532741534764385264587549637569865174 |
|||
12931385212314249632342535174345364628545647573965 |
|||
23119445813422155692453326671356443778246755488935 |
|||
22748628533385973964449618417555172952866628316397 |
|||
24924847833513595894462461691557357271266846838237 |
|||
32476224394358733541546984465265719557637682166874 |
|||
47151426715826253782693736489371484759148259586125 |
|||
85745282229685639333179674144428178525553928963666 |
|||
24212392483532341359464345246157545635726865674683 |
|||
24611235323572234643468334575457944568656815567976 |
|||
42365327415347643852645875496375698651748671976285 |
|||
23142496323425351743453646285456475739656758684176 |
|||
34221556924533266713564437782467554889357866599146 |
|||
33859739644496184175551729528666283163977739427418 |
|||
35135958944624616915573572712668468382377957949348 |
|||
43587335415469844652657195576376821668748793277985 |
|||
58262537826937364893714847591482595861259361697236 |
|||
96856393331796741444281785255539289636664139174777 |
|||
35323413594643452461575456357268656746837976785794 |
|||
35722346434683345754579445686568155679767926678187 |
|||
53476438526458754963756986517486719762859782187396 |
|||
34253517434536462854564757396567586841767869795287 |
|||
45332667135644377824675548893578665991468977611257 |
|||
44961841755517295286662831639777394274188841538529 |
|||
46246169155735727126684683823779579493488168151459 |
|||
54698446526571955763768216687487932779859814388196 |
|||
69373648937148475914825958612593616972361472718347 |
|||
17967414442817852555392896366641391747775241285888 |
|||
46434524615754563572686567468379767857948187896815 |
|||
46833457545794456865681556797679266781878137789298 |
|||
64587549637569865174867197628597821873961893298417 |
|||
45364628545647573965675868417678697952878971816398 |
|||
56443778246755488935786659914689776112579188722368 |
|||
55172952866628316397773942741888415385299952649631 |
|||
57357271266846838237795794934881681514599279262561 |
|||
65719557637682166874879327798598143881961925499217 |
|||
71484759148259586125936169723614727183472583829458 |
|||
28178525553928963666413917477752412858886352396999 |
|||
57545635726865674683797678579481878968159298917926 |
|||
57944568656815567976792667818781377892989248891319 |
|||
75698651748671976285978218739618932984172914319528 |
|||
56475739656758684176786979528789718163989182927419 |
|||
67554889357866599146897761125791887223681299833479 |
|||
|
|||
Equipped with the full map, you can now find a path from the top left corner to the bottom right corner with the lowest total risk: |
|||
|
|||
11637517422274862853338597396444961841755517295286 |
|||
13813736722492484783351359589446246169155735727126 |
|||
21365113283247622439435873354154698446526571955763 |
|||
36949315694715142671582625378269373648937148475914 |
|||
74634171118574528222968563933317967414442817852555 |
|||
13191281372421239248353234135946434524615754563572 |
|||
13599124212461123532357223464346833457545794456865 |
|||
31254216394236532741534764385264587549637569865174 |
|||
12931385212314249632342535174345364628545647573965 |
|||
23119445813422155692453326671356443778246755488935 |
|||
22748628533385973964449618417555172952866628316397 |
|||
24924847833513595894462461691557357271266846838237 |
|||
32476224394358733541546984465265719557637682166874 |
|||
47151426715826253782693736489371484759148259586125 |
|||
85745282229685639333179674144428178525553928963666 |
|||
24212392483532341359464345246157545635726865674683 |
|||
24611235323572234643468334575457944568656815567976 |
|||
42365327415347643852645875496375698651748671976285 |
|||
23142496323425351743453646285456475739656758684176 |
|||
34221556924533266713564437782467554889357866599146 |
|||
33859739644496184175551729528666283163977739427418 |
|||
35135958944624616915573572712668468382377957949348 |
|||
43587335415469844652657195576376821668748793277985 |
|||
58262537826937364893714847591482595861259361697236 |
|||
96856393331796741444281785255539289636664139174777 |
|||
35323413594643452461575456357268656746837976785794 |
|||
35722346434683345754579445686568155679767926678187 |
|||
53476438526458754963756986517486719762859782187396 |
|||
34253517434536462854564757396567586841767869795287 |
|||
45332667135644377824675548893578665991468977611257 |
|||
44961841755517295286662831639777394274188841538529 |
|||
46246169155735727126684683823779579493488168151459 |
|||
54698446526571955763768216687487932779859814388196 |
|||
69373648937148475914825958612593616972361472718347 |
|||
17967414442817852555392896366641391747775241285888 |
|||
46434524615754563572686567468379767857948187896815 |
|||
46833457545794456865681556797679266781878137789298 |
|||
64587549637569865174867197628597821873961893298417 |
|||
45364628545647573965675868417678697952878971816398 |
|||
56443778246755488935786659914689776112579188722368 |
|||
55172952866628316397773942741888415385299952649631 |
|||
57357271266846838237795794934881681514599279262561 |
|||
65719557637682166874879327798598143881961925499217 |
|||
71484759148259586125936169723614727183472583829458 |
|||
28178525553928963666413917477752412858886352396999 |
|||
57545635726865674683797678579481878968159298917926 |
|||
57944568656815567976792667818781377892989248891319 |
|||
75698651748671976285978218739618932984172914319528 |
|||
56475739656758684176786979528789718163989182927419 |
|||
67554889357866599146897761125791887223681299833479 |
|||
|
|||
The total risk of this path is 315 (the starting position is still never entered, so its risk is not counted). |
|||
|
|||
Using the full map, what is the lowest total risk of any path from the top left to the bottom right? |
|||
|
|||
Your puzzle answer was 2821. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
@ -0,0 +1,100 @@ |
|||
3576219475874583191916312133474175459337114195988185136398151631965391991813219974121211251194786128 |
|||
1713881999231519357799114192443351147195293575386923868711388519361669464234397975938889146414199688 |
|||
2151922113728581598379349983928489926261239862882888968998791929828316718921297117449631496888879522 |
|||
3291722311299652548445221254456535112944431135116631433192483199481594768169444158222431199929579291 |
|||
1472287315918113113959972189351931626141472991992791413146153989481318998519171231313898962992319251 |
|||
8978798318873934543151823824117132228417869392811216547172919119998739911121199246294815175868992773 |
|||
4711149989992717728465321161611967173674239298593935117599173279267114155265393397571372124856718732 |
|||
9843245319692998612781837729915931371619886371128818266322121623171343132131239399743799827972585645 |
|||
7183211712173272827112268971459424836293613294388761928991542137194981939169315879277494581991465822 |
|||
2385721996578834579224651431411717198341139751429156637229888849181154922897746418293184413519931124 |
|||
6188313732929496115412842928273812153715747411177189187726751991191841181119822534511125656211991265 |
|||
8797112815141319881991983914861912838966446818811271274141461487947171138945321912192198815813211761 |
|||
6131514331472951494911549373681638637191295997625615885219668259269297171939941498581919718223529141 |
|||
3916711951831246219991217199412116783411218814949692281987659123812288937983969116847986196936523779 |
|||
9111121227192813382983442234171148191131821497435387936912532695293912972491131977272231919798477344 |
|||
9994893855122115213919995636978443773161196511775674783979472217917498285423121574533491643891265199 |
|||
9245818921321877317663254739619499915821162412924816263648913499811482474392667993739139899758919393 |
|||
1717618849193152316325119128859116191132672215933282127611134982961918179152189411131259943819997123 |
|||
3697848795188715264992962617223177221118919863975198881197837936258983111819488622362584888223331999 |
|||
1798259211962116675922944295117391732295963342131192112612386194749389991199821195162975124619149837 |
|||
5365696872959269494682128272373619348283964191994187749824841195582221478325111187843285531119934786 |
|||
6717218734155417511564162235845524121493736962442884479191718924594119911521121422231982184671122116 |
|||
9346412964321187889663345611132183519588187791111227269112129947122999176114184938494824342939375892 |
|||
2912811929919891428891223818529115949522464779949526791515797886471246181118183121786524127979998512 |
|||
7353285281129811915971956929718433284441492484117162562212973157265812816731843791838571691421923924 |
|||
3239161911151141369392413114665193927469988999219478935992541193184945926828911597158489999651151172 |
|||
9229716159183212219791136121569512978927999177196111291668152292896495877722611129462617229299962112 |
|||
5994461796358342348216915883991574569784887978731368749888449599246152414391635925763156831839199496 |
|||
1569319989929452917219726368583887924179117119284971126181346919789949393972171262535283921926293357 |
|||
9983673949614595396426594299567925779229751982433631919159114841538978735893759492592481573495963491 |
|||
3725632421623191323789991288299296415942162988289929992238877153268488127718372211951117951486111926 |
|||
1219319492614741819142363452974731825929485665978219725131218962626179997611254524524915768686381164 |
|||
8248145978417221154822663831966124539168641311913211295941167919583189792718599334616827916567313217 |
|||
3483959252172951953519211189255336234459522397526829492685113849198611624111948187714151963198671919 |
|||
7812289559812455122297839958719917624841136314322613942214613249662544617928521344873779598816941946 |
|||
6868958791119815122313931178313637489923479492171741443993619161318781194421239654468391996636923611 |
|||
6999166111129212624151555925991311538952878946191234511973499736237742491811348911419449161895978178 |
|||
3532973784281182181552481928144111246711742443831184236962981395142863562121961323169398316921741321 |
|||
8433727191521455193223914171391447439164791659118411391327413285243717794299999523811137619197999791 |
|||
8169125649963232439519311131691539694589231314268683691811431259295132344195953951287639889737849189 |
|||
8928161919934761971442719391119881113318323987227229831917897151155121657624142152884624176461913498 |
|||
2949199492196424164751892146395174669111921799261527568751283712133148212821261936297739912939743599 |
|||
9931616797885267969938591912672996183187926259991298429278229232257219428413174972999193796827459799 |
|||
3138768154311742899419449741617489465993174645228814938145273266941566223933119891379181296548999222 |
|||
1338961668848636157444719898575174699419997972125194827176897565699991611654214368232592793825617931 |
|||
9283643143692917314535119897889711191946688911436965194232811624712861576291987716317193114445363435 |
|||
8718611398299869991788113111214414269554542114329621286592313532782819131919527228417764279755899812 |
|||
8128249329314753847725634378737239939769913811444529224619715471961999278915341955188871714271145449 |
|||
1286217894699991715153139268991918988338684391252271254127193342854156438873836258484975151167996316 |
|||
4191439845728418348368191516746499654147257851256861534634988281199187541199892317145428248531129171 |
|||
9799283477747387253566811199414256363339122372629545249542373591951156699415998714124115397811359516 |
|||
3191985767689943186838293175311429527499612824265518522881922917119891424717751985621941995373481629 |
|||
8127933395192162886259956635985821651844893796541627799276258692298972881471991789861232424926758792 |
|||
4349683335349673317521761437148933192989961489478395417258212949865876242843242464123471244631449998 |
|||
3983861771861891251448475182984833811718959521263444111998834975935221115813839514917176912994677265 |
|||
3361812177831144971531441184671112122322312961859915722393944269211333951428175372918136112814926411 |
|||
2492891241191991149319731182431211211971267682931551534199328118919751416881458658314218331565282229 |
|||
1316191719349114251772629411233483317516143684488291792691839198723174287211241498955137331159443961 |
|||
1295632882814319179937625629218199381191127966181781921829819969815912382191294796979515315471941392 |
|||
1952318366571121641614137937116326339638859628226299126699118638171813164397332391891669798271559135 |
|||
1123676641998146639499323488991286491444174358479157916696196841912233773269986812299996975117612192 |
|||
2496461124219121332118311532239527696198787778122345883331631119147159212262659717289674149798169111 |
|||
3994915157217763242581922474512992479146377117411981999549977495462427199524334285127723311599337186 |
|||
2856249932899117429471617195415229923432185189218399415357391954728651191591964713418532917111296399 |
|||
1916415314958527255299763241981929186681257596912948977397875248189748655173819381269954513499896991 |
|||
4214987991254389723346911149661118597277889213928551947599177915888233175182921923128853579525754718 |
|||
3582279578128192231339943295188563998645998149526284997789731787116991199391984141983177825883111821 |
|||
3318115949152512995142691231324793411691198458654473675135993122216324137859959272731599996923465431 |
|||
9431374329994955614816239978928993493129129641248882311462522524447519388869238199852941551532223632 |
|||
6749132793518479891929891686579791123712167784913331559922969149125915827657111724348929978159964476 |
|||
6899888192198113996189996152913216258469182711411338723293823541574149295918323829819122941288693461 |
|||
9833728958423343229397292861582211971713299293611778961979819175799893793971822162383179128129741328 |
|||
9719459171294372288418126215914532995125999274359633129923191213332337513812761149562146497198614329 |
|||
6323381739518574154814713691189651618965915153972197836392492518147816118266818195856772641337997448 |
|||
9515391698994467556612815425651153225477392335219196697477512338938131933398177519117437353271396315 |
|||
2881769116189531115832167881372917543267529333184621316918481786111252281738298936313393416198972192 |
|||
1262821848371618529985323295192217356152412696271318793198457225899782896767339942896611231999996177 |
|||
7611115824284211421951282951346181221891123993118231772195952872865982323819415318945742389969468591 |
|||
6289176957971112617212793915412958239574931721216722823933461763146195116737161463663388274118352919 |
|||
2739192179312181318764617662499189345995579913463399176128133623751919135855775349195561978131664671 |
|||
7419179135228196296753972713643556671138381494838116814212892453118963456121883515171981991493112197 |
|||
2351962484381996196119791327953881225881124837211622273581789216339733276411173141146816794919111532 |
|||
4828494193941149581788515219884312818182198261739598611663311138255885557141492174934279519487959315 |
|||
6266441934234532987821537914696156313934795144412166199339199381197916324959558778257894958593689511 |
|||
1218836684761811498991162549547375891999161535133511817388897491266957819219117988952234747197245136 |
|||
7714718988198712181711441996373181351671962319416917816121119483959397254815953421521642116185224622 |
|||
6315878819598412161782318179586237893968466116199183185764132999388411414821117761121199725212571499 |
|||
9298381112525419214597534611761811137687414291394795245955115116482261788724982532573616634235949295 |
|||
2513837618149681781571514782119218925111312739891194994857915371836413112952729282168681511999132471 |
|||
9859244419394114469927618849921646911349163815889492121537711577378978633345419421881312649299234749 |
|||
6241913851991287776811271361777919519213726771122769111499925516752149976397933753482495291399144132 |
|||
7549785323789821947513966787125532113931855716249321712383292746672763573114656989299712174939322181 |
|||
9188852123922512181114117536955617335173328988385462159798591117758397298294919117614163738414981949 |
|||
2974419341361292817129453536824618155299993142149899966226312193848695911943416589913541194129913422 |
|||
1672761999113289962322634642122163368424955339864962951462929691975798622972131599198673671183449929 |
|||
3462285147627397867977869242451116812198183328383813959284449969199819896174618466572298882951459875 |
|||
6153638634925613615423256118159531429294172496996993184762972841759153392753653191942715379879852345 |
|||
6516291128536155113712481272992636373774429965994966353494115221979925592128929821611928492143929534 |
|||
3993993153713717844719492314391992638719111242291783837279215399219822611221331985991484863975594721 |
|||
5995891457939115884519762228128552168915218299831775259316392719113962218429351553267511523198149462 |
@ -0,0 +1,10 @@ |
|||
1163751742 |
|||
1381373672 |
|||
2136511328 |
|||
3694931569 |
|||
7463417111 |
|||
1319128137 |
|||
1359912421 |
|||
3125421639 |
|||
1293138521 |
|||
2311944581 |
@ -0,0 +1,68 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys |
|||
from bitstring import BitArray |
|||
from operator import mul |
|||
from functools import reduce |
|||
|
|||
def parse_packet(packet, s, np=100000000, length=1000000000): |
|||
nex = s |
|||
end = s+length-1 |
|||
bv = 0 |
|||
numbers = [] |
|||
while np > 0 and nex < min(len(packet)+1,end): |
|||
if (len(packet[nex:end+1]) == 0 or int(''.join(packet[nex:end+1]),2) == 0 or int(''.join(packet[nex:]),2) == 0): |
|||
if length < 1000000000: nex = end+1 |
|||
break |
|||
v = int(''.join(packet[nex:nex+3]),2) |
|||
bv += v |
|||
t = int(''.join(packet[nex+3:nex+6]),2) |
|||
nex += 6 |
|||
if t == 4: |
|||
num = [] |
|||
while (n := packet[nex]) == '1': |
|||
num.append(list(packet[nex+1:nex+5])) |
|||
nex += 5 |
|||
num.append(list(packet[nex+1:nex+5])) |
|||
nex += 5 |
|||
i = int(''.join([''.join(n) for n in num]),2) |
|||
numbers.append(i) |
|||
else: |
|||
I = packet[nex] |
|||
nex += 1 |
|||
if I == '1': |
|||
l = int(''.join(packet[nex:nex+11]),2) |
|||
nex += 11 |
|||
b, nex, numbs = parse_packet(packet, nex, np=l) |
|||
bv += b |
|||
elif I == '0': |
|||
l = int(''.join(packet[nex:nex+15]),2) |
|||
nex += 15 |
|||
b, nex, numbs = parse_packet(packet, nex, length=l) |
|||
bv += b |
|||
if t == 0: numbers.append(sum(numbs)) |
|||
elif t == 1: numbers.append(reduce(mul, numbs, 1)) |
|||
elif t == 2: numbers.append(min(numbs)) |
|||
elif t == 3: numbers.append(max(numbs)) |
|||
elif t == 5: numbers.append(int(numbs[0] > numbs[1])) |
|||
elif t == 6: numbers.append(int(numbs[0] < numbs[1])) |
|||
elif t == 7: numbers.append(int(numbs[0] == numbs[1])) |
|||
|
|||
np -= 1 |
|||
return bv, nex, numbers |
|||
|
|||
if __name__ == '__main__': |
|||
hexa = [list(line.strip('\n')) for line in open(sys.argv[1])] |
|||
bits = [list(BitArray(hex=c).bin) for c in hexa[0]] |
|||
bits = [b for l in bits for b in l] |
|||
|
|||
bv, _, num = parse_packet(bits,0,np=1) |
|||
|
|||
# challenge 1 |
|||
res1 = str(bv) |
|||
print("challenge 1:" + "\n" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
res2 = str(num[0]) |
|||
print("challenge 2:" + "\n" + res2 + "\n") |
|||
|
@ -0,0 +1,127 @@ |
|||
--- Day 16: Packet Decoder --- |
|||
|
|||
As you leave the cave and reach open waters, you receive a transmission from the Elves back on the ship. |
|||
|
|||
The transmission was sent using the Buoyancy Interchange Transmission System (BITS), a method of packing numeric expressions into a binary sequence. Your submarine's computer has saved the transmission in hexadecimal (your puzzle input). |
|||
|
|||
The first step of decoding the message is to convert the hexadecimal representation into binary. Each character of hexadecimal corresponds to four bits of binary data: |
|||
|
|||
0 = 0000 |
|||
1 = 0001 |
|||
2 = 0010 |
|||
3 = 0011 |
|||
4 = 0100 |
|||
5 = 0101 |
|||
6 = 0110 |
|||
7 = 0111 |
|||
8 = 1000 |
|||
9 = 1001 |
|||
A = 1010 |
|||
B = 1011 |
|||
C = 1100 |
|||
D = 1101 |
|||
E = 1110 |
|||
F = 1111 |
|||
|
|||
The BITS transmission contains a single packet at its outermost layer which itself contains many other packets. The hexadecimal representation of this packet might encode a few extra 0 bits at the end; these are not part of the transmission and should be ignored. |
|||
|
|||
Every packet begins with a standard header: the first three bits encode the packet version, and the next three bits encode the packet type ID. These two values are numbers; all numbers encoded in any packet are represented as binary with the most significant bit first. For example, a version encoded as the binary sequence 100 represents the number 4. |
|||
|
|||
Packets with type ID 4 represent a literal value. Literal value packets encode a single binary number. To do this, the binary number is padded with leading zeroes until its length is a multiple of four bits, and then it is broken into groups of four bits. Each group is prefixed by a 1 bit except the last group, which is prefixed by a 0 bit. These groups of five bits immediately follow the packet header. For example, the hexadecimal string D2FE28 becomes: |
|||
|
|||
110100101111111000101000 |
|||
VVVTTTAAAAABBBBBCCCCC |
|||
|
|||
Below each bit is a label indicating its purpose: |
|||
|
|||
The three bits labeled V (110) are the packet version, 6. |
|||
The three bits labeled T (100) are the packet type ID, 4, which means the packet is a literal value. |
|||
The five bits labeled A (10111) start with a 1 (not the last group, keep reading) and contain the first four bits of the number, 0111. |
|||
The five bits labeled B (11110) start with a 1 (not the last group, keep reading) and contain four more bits of the number, 1110. |
|||
The five bits labeled C (00101) start with a 0 (last group, end of packet) and contain the last four bits of the number, 0101. |
|||
The three unlabeled 0 bits at the end are extra due to the hexadecimal representation and should be ignored. |
|||
|
|||
So, this packet represents a literal value with binary representation 011111100101, which is 2021 in decimal. |
|||
|
|||
Every other type of packet (any packet with a type ID other than 4) represent an operator that performs some calculation on one or more sub-packets contained within. Right now, the specific operations aren't important; focus on parsing the hierarchy of sub-packets. |
|||
|
|||
An operator packet contains one or more packets. To indicate which subsequent binary data represents its sub-packets, an operator packet can use one of two modes indicated by the bit immediately after the packet header; this is called the length type ID: |
|||
|
|||
If the length type ID is 0, then the next 15 bits are a number that represents the total length in bits of the sub-packets contained by this packet. |
|||
If the length type ID is 1, then the next 11 bits are a number that represents the number of sub-packets immediately contained by this packet. |
|||
|
|||
Finally, after the length type ID bit and the 15-bit or 11-bit field, the sub-packets appear. |
|||
|
|||
For example, here is an operator packet (hexadecimal string 38006F45291200) with length type ID 0 that contains two sub-packets: |
|||
|
|||
00111000000000000110111101000101001010010001001000000000 |
|||
VVVTTTILLLLLLLLLLLLLLLAAAAAAAAAAABBBBBBBBBBBBBBBB |
|||
|
|||
The three bits labeled V (001) are the packet version, 1. |
|||
The three bits labeled T (110) are the packet type ID, 6, which means the packet is an operator. |
|||
The bit labeled I (0) is the length type ID, which indicates that the length is a 15-bit number representing the number of bits in the sub-packets. |
|||
The 15 bits labeled L (000000000011011) contain the length of the sub-packets in bits, 27. |
|||
The 11 bits labeled A contain the first sub-packet, a literal value representing the number 10. |
|||
The 16 bits labeled B contain the second sub-packet, a literal value representing the number 20. |
|||
|
|||
After reading 11 and 16 bits of sub-packet data, the total length indicated in L (27) is reached, and so parsing of this packet stops. |
|||
|
|||
As another example, here is an operator packet (hexadecimal string EE00D40C823060) with length type ID 1 that contains three sub-packets: |
|||
|
|||
11101110000000001101010000001100100000100011000001100000 |
|||
VVVTTTILLLLLLLLLLLAAAAAAAAAAABBBBBBBBBBBCCCCCCCCCCC |
|||
|
|||
The three bits labeled V (111) are the packet version, 7. |
|||
The three bits labeled T (011) are the packet type ID, 3, which means the packet is an operator. |
|||
The bit labeled I (1) is the length type ID, which indicates that the length is a 11-bit number representing the number of sub-packets. |
|||
The 11 bits labeled L (00000000011) contain the number of sub-packets, 3. |
|||
The 11 bits labeled A contain the first sub-packet, a literal value representing the number 1. |
|||
The 11 bits labeled B contain the second sub-packet, a literal value representing the number 2. |
|||
The 11 bits labeled C contain the third sub-packet, a literal value representing the number 3. |
|||
|
|||
After reading 3 complete sub-packets, the number of sub-packets indicated in L (3) is reached, and so parsing of this packet stops. |
|||
|
|||
For now, parse the hierarchy of the packets throughout the transmission and add up all of the version numbers. |
|||
|
|||
Here are a few more examples of hexadecimal-encoded transmissions: |
|||
|
|||
8A004A801A8002F478 represents an operator packet (version 4) which contains an operator packet (version 1) which contains an operator packet (version 5) which contains a literal value (version 6); this packet has a version sum of 16. |
|||
620080001611562C8802118E34 represents an operator packet (version 3) which contains two sub-packets; each sub-packet is an operator packet that contains two literal values. This packet has a version sum of 12. |
|||
C0015000016115A2E0802F182340 has the same structure as the previous example, but the outermost packet uses a different length type ID. This packet has a version sum of 23. |
|||
A0016C880162017C3686B18A3D4780 is an operator packet that contains an operator packet that contains an operator packet that contains five literal values; it has a version sum of 31. |
|||
|
|||
Decode the structure of your hexadecimal-encoded BITS transmission; what do you get if you add up the version numbers in all packets? |
|||
|
|||
Your puzzle answer was 971. |
|||
--- Part Two --- |
|||
|
|||
Now that you have the structure of your transmission decoded, you can calculate the value of the expression it represents. |
|||
|
|||
Literal values (type ID 4) represent a single number as described above. The remaining type IDs are more interesting: |
|||
|
|||
Packets with type ID 0 are sum packets - their value is the sum of the values of their sub-packets. If they only have a single sub-packet, their value is the value of the sub-packet. |
|||
Packets with type ID 1 are product packets - their value is the result of multiplying together the values of their sub-packets. If they only have a single sub-packet, their value is the value of the sub-packet. |
|||
Packets with type ID 2 are minimum packets - their value is the minimum of the values of their sub-packets. |
|||
Packets with type ID 3 are maximum packets - their value is the maximum of the values of their sub-packets. |
|||
Packets with type ID 5 are greater than packets - their value is 1 if the value of the first sub-packet is greater than the value of the second sub-packet; otherwise, their value is 0. These packets always have exactly two sub-packets. |
|||
Packets with type ID 6 are less than packets - their value is 1 if the value of the first sub-packet is less than the value of the second sub-packet; otherwise, their value is 0. These packets always have exactly two sub-packets. |
|||
Packets with type ID 7 are equal to packets - their value is 1 if the value of the first sub-packet is equal to the value of the second sub-packet; otherwise, their value is 0. These packets always have exactly two sub-packets. |
|||
|
|||
Using these rules, you can now work out the value of the outermost packet in your BITS transmission. |
|||
|
|||
For example: |
|||
|
|||
C200B40A82 finds the sum of 1 and 2, resulting in the value 3. |
|||
04005AC33890 finds the product of 6 and 9, resulting in the value 54. |
|||
880086C3E88112 finds the minimum of 7, 8, and 9, resulting in the value 7. |
|||
CE00C43D881120 finds the maximum of 7, 8, and 9, resulting in the value 9. |
|||
D8005AC2A8F0 produces 1, because 5 is less than 15. |
|||
F600BC2D8F produces 0, because 5 is not greater than 15. |
|||
9C005AC2F8F0 produces 0, because 5 is not equal to 15. |
|||
9C0141080250320F1802104A08 produces 1, because 1 + 3 = 2 * 2. |
|||
|
|||
What do you get if you evaluate the expression represented by your hexadecimal-encoded BITS transmission? |
|||
|
|||
Your puzzle answer was 831996589851. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
@ -0,0 +1 @@ |
|||
805311100469800804A3E488ACC0B10055D8009548874F65665AD42F60073E7338E7E5C538D820114AEA1A19927797976F8F43CD7354D66747B3005B401397C6CBA2FCEEE7AACDECC017938B3F802E000854488F70FC401F8BD09E199005B3600BCBFEEE12FFBB84FC8466B515E92B79B1003C797AEBAF53917E99FF2E953D0D284359CA0CB80193D12B3005B4017968D77EB224B46BBF591E7BEBD2FA00100622B4ED64773D0CF7816600B68020000874718E715C0010D8AF1E61CC946FB99FC2C20098275EBC0109FA14CAEDC20EB8033389531AAB14C72162492DE33AE0118012C05EEB801C0054F880102007A01192C040E100ED20035DA8018402BE20099A0020CB801AE0049801E800DD10021E4002DC7D30046C0160004323E42C8EA200DC5A87D06250C50015097FB2CFC93A101006F532EB600849634912799EF7BF609270D0802B59876F004246941091A5040402C9BD4DF654967BFDE4A6432769CED4EC3C4F04C000A895B8E98013246A6016CB3CCC94C9144A03CFAB9002033E7B24A24016DD802933AFAE48EAA3335A632013BC401D8850863A8803D1C61447A00042E3647B83F313674009E6533E158C3351F94C9902803D35C869865D564690103004E74CB001F39BEFFAAD37DFF558C012D005A5A9E851D25F76DD88A5F4BC600ACB6E1322B004E5FE1F2FF0E3005EC017969EB7AE4D1A53D07B918C0B1802F088B2C810326215CCBB6BC140C0149EE87780233E0D298C33B008C52763C9C94BF8DC886504E1ECD4E75C7E4EA00284180371362C44320043E2EC258F24008747785D10C001039F80644F201217401500043A2244B8D200085C3F8690BA78F08018394079A7A996D200806647A49E249C675C0802609D66B004658BA7F1562500366279CCBEB2600ACCA6D802C00085C658BD1DC401A8EB136100 |
@ -0,0 +1,40 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys, re |
|||
|
|||
def parse(l): |
|||
return re.compile(r"target area: x=(?P<x1>\d+)..(?P<x2>\d+), y=(?P<y1>-?\d+)..(?P<y2>-?\d+)").search(l) |
|||
|
|||
def step(cx,cy,x,y): |
|||
cx += x |
|||
cy += y |
|||
x = x-1 if x > 0 else (x+1 if x < 0 else 0) |
|||
y -= 1 |
|||
return cx,cy,x,y |
|||
|
|||
def hits_target(x,y,t): |
|||
cx, cy, rt, my = 0,0, False, 0 |
|||
while cx <= max(t[0]) and cy >= min(t[1]): |
|||
cx,cy,x,y = step(cx,cy,x,y) |
|||
my = max(my,cy) |
|||
if (min(t[0]) <= cx <= max(t[0])) and (min(t[1]) <= cy <= max(t[1])): rt = True |
|||
return my, rt |
|||
|
|||
if __name__ == '__main__': |
|||
x1,x2,y1,y2 = map(int,parse(open(sys.argv[1]).read()).groups()) |
|||
target = ((x1,x2),(y1,y2)) |
|||
|
|||
dic = {} |
|||
for x in range(target[0][1]+1): |
|||
for y in range(min(target[1]),target[0][1]+max(map(abs,target[1]))): |
|||
my,rt = hits_target(x,y,target) |
|||
if rt: dic[(x,y)] = my |
|||
|
|||
# challenge 1 |
|||
res1 = str(max(dic.values())) |
|||
print("challenge 1:" +"\n" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
res2 = str(len(dic)) |
|||
print("challenge 2:" +"\n" + res2 + "\n") |
|||
|
@ -0,0 +1,136 @@ |
|||
--- Day 17: Trick Shot --- |
|||
|
|||
You finally decode the Elves' message. HI, the message says. You continue searching for the sleigh keys. |
|||
|
|||
Ahead of you is what appears to be a large ocean trench. Could the keys have fallen into it? You'd better send a probe to investigate. |
|||
|
|||
The probe launcher on your submarine can fire the probe with any integer velocity in the x (forward) and y (upward, or downward if negative) directions. For example, an initial x,y velocity like 0,10 would fire the probe straight up, while an initial velocity like 10,-1 would fire the probe forward at a slight downward angle. |
|||
|
|||
The probe's x,y position starts at 0,0. Then, it will follow some trajectory by moving in steps. On each step, these changes occur in the following order: |
|||
|
|||
The probe's x position increases by its x velocity. |
|||
The probe's y position increases by its y velocity. |
|||
Due to drag, the probe's x velocity changes by 1 toward the value 0; that is, it decreases by 1 if it is greater than 0, increases by 1 if it is less than 0, or does not change if it is already 0. |
|||
Due to gravity, the probe's y velocity decreases by 1. |
|||
|
|||
For the probe to successfully make it into the trench, the probe must be on some trajectory that causes it to be within a target area after any step. The submarine computer has already calculated this target area (your puzzle input). For example: |
|||
|
|||
target area: x=20..30, y=-10..-5 |
|||
|
|||
This target area means that you need to find initial x,y velocity values such that after any step, the probe's x position is at least 20 and at most 30, and the probe's y position is at least -10 and at most -5. |
|||
|
|||
Given this target area, one initial velocity that causes the probe to be within the target area after any step is 7,2: |
|||
|
|||
.............#....#............ |
|||
.......#..............#........ |
|||
............................... |
|||
S........................#..... |
|||
............................... |
|||
............................... |
|||
...........................#... |
|||
............................... |
|||
....................TTTTTTTTTTT |
|||
....................TTTTTTTTTTT |
|||
....................TTTTTTTT#TT |
|||
....................TTTTTTTTTTT |
|||
....................TTTTTTTTTTT |
|||
....................TTTTTTTTTTT |
|||
|
|||
In this diagram, S is the probe's initial position, 0,0. The x coordinate increases to the right, and the y coordinate increases upward. In the bottom right, positions that are within the target area are shown as T. After each step (until the target area is reached), the position of the probe is marked with #. (The bottom-right # is both a position the probe reaches and a position in the target area.) |
|||
|
|||
Another initial velocity that causes the probe to be within the target area after any step is 6,3: |
|||
|
|||
...............#..#............ |
|||
...........#........#.......... |
|||
............................... |
|||
......#..............#......... |
|||
............................... |
|||
............................... |
|||
S....................#......... |
|||
............................... |
|||
............................... |
|||
............................... |
|||
.....................#......... |
|||
....................TTTTTTTTTTT |
|||
....................TTTTTTTTTTT |
|||
....................TTTTTTTTTTT |
|||
....................TTTTTTTTTTT |
|||
....................T#TTTTTTTTT |
|||
....................TTTTTTTTTTT |
|||
|
|||
Another one is 9,0: |
|||
|
|||
S........#..................... |
|||
.................#............. |
|||
............................... |
|||
........................#...... |
|||
............................... |
|||
....................TTTTTTTTTTT |
|||
....................TTTTTTTTTT# |
|||
....................TTTTTTTTTTT |
|||
....................TTTTTTTTTTT |
|||
....................TTTTTTTTTTT |
|||
....................TTTTTTTTTTT |
|||
|
|||
One initial velocity that doesn't cause the probe to be within the target area after any step is 17,-4: |
|||
|
|||
S.............................................................. |
|||
............................................................... |
|||
............................................................... |
|||
............................................................... |
|||
.................#............................................. |
|||
....................TTTTTTTTTTT................................ |
|||
....................TTTTTTTTTTT................................ |
|||
....................TTTTTTTTTTT................................ |
|||
....................TTTTTTTTTTT................................ |
|||
....................TTTTTTTTTTT..#............................. |
|||
....................TTTTTTTTTTT................................ |
|||
............................................................... |
|||
............................................................... |
|||
............................................................... |
|||
............................................................... |
|||
................................................#.............. |
|||
............................................................... |
|||
............................................................... |
|||
............................................................... |
|||
............................................................... |
|||
............................................................... |
|||
............................................................... |
|||
..............................................................# |
|||
|
|||
The probe appears to pass through the target area, but is never within it after any step. Instead, it continues down and to the right - only the first few steps are shown. |
|||
|
|||
If you're going to fire a highly scientific probe out of a super cool probe launcher, you might as well do it with style. How high can you make the probe go while still reaching the target area? |
|||
|
|||
In the above example, using an initial velocity of 6,9 is the best you can do, causing the probe to reach a maximum y position of 45. (Any higher initial y velocity causes the probe to overshoot the target area entirely.) |
|||
|
|||
Find the initial velocity that causes the probe to reach the highest y position and still eventually be within the target area after any step. What is the highest y position it reaches on this trajectory? |
|||
|
|||
Your puzzle answer was 11781. |
|||
--- Part Two --- |
|||
|
|||
Maybe a fancy trick shot isn't the best idea; after all, you only have one probe, so you had better not miss. |
|||
|
|||
To get the best idea of what your options are for launching the probe, you need to find every initial velocity that causes the probe to eventually be within the target area after any step. |
|||
|
|||
In the above example, there are 112 different initial velocity values that meet these criteria: |
|||
|
|||
23,-10 25,-9 27,-5 29,-6 22,-6 21,-7 9,0 27,-7 24,-5 |
|||
25,-7 26,-6 25,-5 6,8 11,-2 20,-5 29,-10 6,3 28,-7 |
|||
8,0 30,-6 29,-8 20,-10 6,7 6,4 6,1 14,-4 21,-6 |
|||
26,-10 7,-1 7,7 8,-1 21,-9 6,2 20,-7 30,-10 14,-3 |
|||
20,-8 13,-2 7,3 28,-8 29,-9 15,-3 22,-5 26,-8 25,-8 |
|||
25,-6 15,-4 9,-2 15,-2 12,-2 28,-9 12,-3 24,-6 23,-7 |
|||
25,-10 7,8 11,-3 26,-7 7,1 23,-9 6,0 22,-10 27,-6 |
|||
8,1 22,-8 13,-4 7,6 28,-6 11,-4 12,-4 26,-9 7,4 |
|||
24,-10 23,-8 30,-8 7,0 9,-1 10,-1 26,-5 22,-9 6,5 |
|||
7,5 23,-6 28,-10 10,-2 11,-1 20,-9 14,-2 29,-7 13,-3 |
|||
23,-5 24,-8 27,-9 30,-7 28,-5 21,-10 7,9 6,6 21,-5 |
|||
27,-10 7,2 30,-9 21,-8 22,-7 24,-9 20,-6 6,9 29,-5 |
|||
8,-2 27,-8 30,-5 24,-7 |
|||
|
|||
How many distinct initial velocity values cause the probe to be within the target area after any step? |
|||
|
|||
Your puzzle answer was 4531. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
@ -0,0 +1 @@ |
|||
target area: x=111..161, y=-154..-101 |
@ -0,0 +1 @@ |
|||
target area: x=20..30, y=-10..-5 |
@ -0,0 +1,100 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys, math |
|||
from functools import reduce |
|||
from copy import deepcopy |
|||
|
|||
def magn(n): |
|||
if type(n) == int: return n |
|||
return 3*magn(n[0]) + 2*magn(n[1]) |
|||
|
|||
def explode(osn): |
|||
sn = deepcopy(osn) |
|||
l = None |
|||
r = 0 |
|||
d = False |
|||
for i,n1 in enumerate(sn): |
|||
if type(n1) == int: |
|||
l = (0,i,n1) |
|||
if r != 0: |
|||
sn[i] = n1 + r |
|||
return sn |
|||
else: |
|||
for j,n2 in enumerate(n1): |
|||
if type(n2) == int: |
|||
l = (1,[i,j],n2) |
|||
if r != 0: |
|||
n1[j] = n2 + r |
|||
return sn |
|||
else: |
|||
for k,n3 in enumerate(n2): |
|||
if type(n3) == int: |
|||
l = (2,[i,j,k],n3) |
|||
if r != 0: |
|||
n2[k] = n3 + r |
|||
return sn |
|||
else: |
|||
for m,n4 in enumerate(n3): |
|||
if type(n4) == int: |
|||
l = (3,[i,j,k,m],n4) |
|||
if r != 0: |
|||
n3[m] = n4 + r |
|||
return sn |
|||
elif not d: |
|||
d = True |
|||
r = n4[1] |
|||
if l != None: |
|||
if l[0] == 0: sn[l[1]] = l[2] + n4[0] |
|||
elif l[0] == 1: sn[l[1][0]][l[1][1]] = l[2] + n4[0] |
|||
elif l[0] == 2: sn[l[1][0]][l[1][1]][l[1][2]] = l[2] + n4[0] |
|||
elif l[0] == 3: sn[l[1][0]][l[1][1]][l[1][2]][l[1][3]] = l[2] + n4[0] |
|||
n3[m] = 0 |
|||
else: |
|||
if type(n4[0]) != int: |
|||
print('help!') |
|||
n4[0] += r |
|||
return sn |
|||
|
|||
return sn |
|||
|
|||
def split(osn): |
|||
sn = deepcopy(osn) |
|||
if isinstance(sn,list): |
|||
for i,n in enumerate(sn): |
|||
o = sn[i] |
|||
sn[i] = split(n) |
|||
if sn[i] != o: return sn |
|||
elif sn > 9: |
|||
return [math.floor(sn/2),math.ceil(sn/2)] |
|||
return sn |
|||
|
|||
def snreduce(sn): |
|||
new = 0 |
|||
old = sn |
|||
while old != new: |
|||
old = new if new != 0 else old |
|||
new = explode(old) |
|||
if new != old: |
|||
continue |
|||
new = split(old) |
|||
return new |
|||
|
|||
def snadd(sn1,sn2): |
|||
sn = [sn1,sn2] |
|||
return snreduce(sn) |
|||
|
|||
if __name__ == '__main__': |
|||
nums = [eval(line.strip('\n')) for line in open(sys.argv[1])] |
|||
|
|||
# challenge 1 |
|||
res1 = str(magn(reduce(snadd,nums))) |
|||
print("challenge 1:" + "\n" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
mm = 0 |
|||
for n in nums: |
|||
for m in nums: |
|||
mm = max(mm, magn(snadd(n,m))) |
|||
res2 = str(mm) |
|||
print("challenge 2:" + "\n" + res2 + "\n") |
|||
|
@ -0,0 +1,192 @@ |
|||
--- Day 18: Snailfish --- |
|||
|
|||
You descend into the ocean trench and encounter some snailfish. They say they saw the sleigh keys! They'll even tell you which direction the keys went if you help one of the smaller snailfish with his math homework. |
|||
|
|||
Snailfish numbers aren't like regular numbers. Instead, every snailfish number is a pair - an ordered list of two elements. Each element of the pair can be either a regular number or another pair. |
|||
|
|||
Pairs are written as [x,y], where x and y are the elements within the pair. Here are some example snailfish numbers, one snailfish number per line: |
|||
|
|||
[1,2] |
|||
[[1,2],3] |
|||
[9,[8,7]] |
|||
[[1,9],[8,5]] |
|||
[[[[1,2],[3,4]],[[5,6],[7,8]]],9] |
|||
[[[9,[3,8]],[[0,9],6]],[[[3,7],[4,9]],3]] |
|||
[[[[1,3],[5,3]],[[1,3],[8,7]]],[[[4,9],[6,9]],[[8,2],[7,3]]]] |
|||
|
|||
This snailfish homework is about addition. To add two snailfish numbers, form a pair from the left and right parameters of the addition operator. For example, [1,2] + [[3,4],5] becomes [[1,2],[[3,4],5]]. |
|||
|
|||
There's only one problem: snailfish numbers must always be reduced, and the process of adding two snailfish numbers can result in snailfish numbers that need to be reduced. |
|||
|
|||
To reduce a snailfish number, you must repeatedly do the first action in this list that applies to the snailfish number: |
|||
|
|||
If any pair is nested inside four pairs, the leftmost such pair explodes. |
|||
If any regular number is 10 or greater, the leftmost such regular number splits. |
|||
|
|||
Once no action in the above list applies, the snailfish number is reduced. |
|||
|
|||
During reduction, at most one action applies, after which the process returns to the top of the list of actions. For example, if split produces a pair that meets the explode criteria, that pair explodes before other splits occur. |
|||
|
|||
To explode a pair, the pair's left value is added to the first regular number to the left of the exploding pair (if any), and the pair's right value is added to the first regular number to the right of the exploding pair (if any). Exploding pairs will always consist of two regular numbers. Then, the entire exploding pair is replaced with the regular number 0. |
|||
|
|||
Here are some examples of a single explode action: |
|||
|
|||
[[[[[9,8],1],2],3],4] becomes [[[[0,9],2],3],4] (the 9 has no regular number to its left, so it is not added to any regular number). |
|||
[7,[6,[5,[4,[3,2]]]]] becomes [7,[6,[5,[7,0]]]] (the 2 has no regular number to its right, and so it is not added to any regular number). |
|||
[[6,[5,[4,[3,2]]]],1] becomes [[6,[5,[7,0]]],3]. |
|||
[[3,[2,[1,[7,3]]]],[6,[5,[4,[3,2]]]]] becomes [[3,[2,[8,0]]],[9,[5,[4,[3,2]]]]] (the pair [3,2] is unaffected because the pair [7,3] is further to the left; [3,2] would explode on the next action). |
|||
[[3,[2,[8,0]]],[9,[5,[4,[3,2]]]]] becomes [[3,[2,[8,0]]],[9,[5,[7,0]]]]. |
|||
|
|||
To split a regular number, replace it with a pair; the left element of the pair should be the regular number divided by two and rounded down, while the right element of the pair should be the regular number divided by two and rounded up. For example, 10 becomes [5,5], 11 becomes [5,6], 12 becomes [6,6], and so on. |
|||
|
|||
Here is the process of finding the reduced result of [[[[4,3],4],4],[7,[[8,4],9]]] + [1,1]: |
|||
|
|||
after addition: [[[[[4,3],4],4],[7,[[8,4],9]]],[1,1]] |
|||
after explode: [[[[0,7],4],[7,[[8,4],9]]],[1,1]] |
|||
after explode: [[[[0,7],4],[15,[0,13]]],[1,1]] |
|||
after split: [[[[0,7],4],[[7,8],[0,13]]],[1,1]] |
|||
after split: [[[[0,7],4],[[7,8],[0,[6,7]]]],[1,1]] |
|||
after explode: [[[[0,7],4],[[7,8],[6,0]]],[8,1]] |
|||
|
|||
Once no reduce actions apply, the snailfish number that remains is the actual result of the addition operation: [[[[0,7],4],[[7,8],[6,0]]],[8,1]]. |
|||
|
|||
The homework assignment involves adding up a list of snailfish numbers (your puzzle input). The snailfish numbers are each listed on a separate line. Add the first snailfish number and the second, then add that result and the third, then add that result and the fourth, and so on until all numbers in the list have been used once. |
|||
|
|||
For example, the final sum of this list is [[[[1,1],[2,2]],[3,3]],[4,4]]: |
|||
|
|||
[1,1] |
|||
[2,2] |
|||
[3,3] |
|||
[4,4] |
|||
|
|||
The final sum of this list is [[[[3,0],[5,3]],[4,4]],[5,5]]: |
|||
|
|||
[1,1] |
|||
[2,2] |
|||
[3,3] |
|||
[4,4] |
|||
[5,5] |
|||
|
|||
The final sum of this list is [[[[5,0],[7,4]],[5,5]],[6,6]]: |
|||
|
|||
[1,1] |
|||
[2,2] |
|||
[3,3] |
|||
[4,4] |
|||
[5,5] |
|||
[6,6] |
|||
|
|||
Here's a slightly larger example: |
|||
|
|||
[[[0,[4,5]],[0,0]],[[[4,5],[2,6]],[9,5]]] |
|||
[7,[[[3,7],[4,3]],[[6,3],[8,8]]]] |
|||
[[2,[[0,8],[3,4]]],[[[6,7],1],[7,[1,6]]]] |
|||
[[[[2,4],7],[6,[0,5]]],[[[6,8],[2,8]],[[2,1],[4,5]]]] |
|||
[7,[5,[[3,8],[1,4]]]] |
|||
[[2,[2,2]],[8,[8,1]]] |
|||
[2,9] |
|||
[1,[[[9,3],9],[[9,0],[0,7]]]] |
|||
[[[5,[7,4]],7],1] |
|||
[[[[4,2],2],6],[8,7]] |
|||
|
|||
The final sum [[[[8,7],[7,7]],[[8,6],[7,7]]],[[[0,7],[6,6]],[8,7]]] is found after adding up the above snailfish numbers: |
|||
|
|||
[[[0,[4,5]],[0,0]],[[[4,5],[2,6]],[9,5]]] |
|||
+ [7,[[[3,7],[4,3]],[[6,3],[8,8]]]] |
|||
= [[[[4,0],[5,4]],[[7,7],[6,0]]],[[8,[7,7]],[[7,9],[5,0]]]] |
|||
|
|||
[[[[4,0],[5,4]],[[7,7],[6,0]]],[[8,[7,7]],[[7,9],[5,0]]]] |
|||
+ [[2,[[0,8],[3,4]]],[[[6,7],1],[7,[1,6]]]] |
|||
= [[[[6,7],[6,7]],[[7,7],[0,7]]],[[[8,7],[7,7]],[[8,8],[8,0]]]] |
|||
|
|||
[[[[6,7],[6,7]],[[7,7],[0,7]]],[[[8,7],[7,7]],[[8,8],[8,0]]]] |
|||
+ [[[[2,4],7],[6,[0,5]]],[[[6,8],[2,8]],[[2,1],[4,5]]]] |
|||
= [[[[7,0],[7,7]],[[7,7],[7,8]]],[[[7,7],[8,8]],[[7,7],[8,7]]]] |
|||
|
|||
[[[[7,0],[7,7]],[[7,7],[7,8]]],[[[7,7],[8,8]],[[7,7],[8,7]]]] |
|||
+ [7,[5,[[3,8],[1,4]]]] |
|||
= [[[[7,7],[7,8]],[[9,5],[8,7]]],[[[6,8],[0,8]],[[9,9],[9,0]]]] |
|||
|
|||
[[[[7,7],[7,8]],[[9,5],[8,7]]],[[[6,8],[0,8]],[[9,9],[9,0]]]] |
|||
+ [[2,[2,2]],[8,[8,1]]] |
|||
= [[[[6,6],[6,6]],[[6,0],[6,7]]],[[[7,7],[8,9]],[8,[8,1]]]] |
|||
|
|||
[[[[6,6],[6,6]],[[6,0],[6,7]]],[[[7,7],[8,9]],[8,[8,1]]]] |
|||
+ [2,9] |
|||
= [[[[6,6],[7,7]],[[0,7],[7,7]]],[[[5,5],[5,6]],9]] |
|||
|
|||
[[[[6,6],[7,7]],[[0,7],[7,7]]],[[[5,5],[5,6]],9]] |
|||
+ [1,[[[9,3],9],[[9,0],[0,7]]]] |
|||
= [[[[7,8],[6,7]],[[6,8],[0,8]]],[[[7,7],[5,0]],[[5,5],[5,6]]]] |
|||
|
|||
[[[[7,8],[6,7]],[[6,8],[0,8]]],[[[7,7],[5,0]],[[5,5],[5,6]]]] |
|||
+ [[[5,[7,4]],7],1] |
|||
= [[[[7,7],[7,7]],[[8,7],[8,7]]],[[[7,0],[7,7]],9]] |
|||
|
|||
[[[[7,7],[7,7]],[[8,7],[8,7]]],[[[7,0],[7,7]],9]] |
|||
+ [[[[4,2],2],6],[8,7]] |
|||
= [[[[8,7],[7,7]],[[8,6],[7,7]]],[[[0,7],[6,6]],[8,7]]] |
|||
|
|||
To check whether it's the right answer, the snailfish teacher only checks the magnitude of the final sum. The magnitude of a pair is 3 times the magnitude of its left element plus 2 times the magnitude of its right element. The magnitude of a regular number is just that number. |
|||
|
|||
For example, the magnitude of [9,1] is 3*9 + 2*1 = 29; the magnitude of [1,9] is 3*1 + 2*9 = 21. Magnitude calculations are recursive: the magnitude of [[9,1],[1,9]] is 3*29 + 2*21 = 129. |
|||
|
|||
Here are a few more magnitude examples: |
|||
|
|||
[[1,2],[[3,4],5]] becomes 143. |
|||
[[[[0,7],4],[[7,8],[6,0]]],[8,1]] becomes 1384. |
|||
[[[[1,1],[2,2]],[3,3]],[4,4]] becomes 445. |
|||
[[[[3,0],[5,3]],[4,4]],[5,5]] becomes 791. |
|||
[[[[5,0],[7,4]],[5,5]],[6,6]] becomes 1137. |
|||
[[[[8,7],[7,7]],[[8,6],[7,7]]],[[[0,7],[6,6]],[8,7]]] becomes 3488. |
|||
|
|||
So, given this example homework assignment: |
|||
|
|||
[[[0,[5,8]],[[1,7],[9,6]]],[[4,[1,2]],[[1,4],2]]] |
|||
[[[5,[2,8]],4],[5,[[9,9],0]]] |
|||
[6,[[[6,2],[5,6]],[[7,6],[4,7]]]] |
|||
[[[6,[0,7]],[0,9]],[4,[9,[9,0]]]] |
|||
[[[7,[6,4]],[3,[1,3]]],[[[5,5],1],9]] |
|||
[[6,[[7,3],[3,2]]],[[[3,8],[5,7]],4]] |
|||
[[[[5,4],[7,7]],8],[[8,3],8]] |
|||
[[9,3],[[9,9],[6,[4,9]]]] |
|||
[[2,[[7,7],7]],[[5,8],[[9,3],[0,2]]]] |
|||
[[[[5,2],5],[8,[3,7]]],[[5,[7,5]],[4,4]]] |
|||
|
|||
The final sum is: |
|||
|
|||
[[[[6,6],[7,6]],[[7,7],[7,0]]],[[[7,7],[7,7]],[[7,8],[9,9]]]] |
|||
|
|||
The magnitude of this final sum is 4140. |
|||
|
|||
Add up all of the snailfish numbers from the homework assignment in the order they appear. What is the magnitude of the final sum? |
|||
|
|||
Your puzzle answer was 3305. |
|||
--- Part Two --- |
|||
|
|||
You notice a second question on the back of the homework assignment: |
|||
|
|||
What is the largest magnitude you can get from adding only two of the snailfish numbers? |
|||
|
|||
Note that snailfish addition is not commutative - that is, x + y and y + x can produce different results. |
|||
|
|||
Again considering the last example homework assignment above: |
|||
|
|||
[[[0,[5,8]],[[1,7],[9,6]]],[[4,[1,2]],[[1,4],2]]] |
|||
[[[5,[2,8]],4],[5,[[9,9],0]]] |
|||
[6,[[[6,2],[5,6]],[[7,6],[4,7]]]] |
|||
[[[6,[0,7]],[0,9]],[4,[9,[9,0]]]] |
|||
[[[7,[6,4]],[3,[1,3]]],[[[5,5],1],9]] |
|||
[[6,[[7,3],[3,2]]],[[[3,8],[5,7]],4]] |
|||
[[[[5,4],[7,7]],8],[[8,3],8]] |
|||
[[9,3],[[9,9],[6,[4,9]]]] |
|||
[[2,[[7,7],7]],[[5,8],[[9,3],[0,2]]]] |
|||
[[[[5,2],5],[8,[3,7]]],[[5,[7,5]],[4,4]]] |
|||
|
|||
The largest magnitude of the sum of any two snailfish numbers in this list is 3993. This is the magnitude of [[2,[[7,7],7]],[[5,8],[[9,3],[0,2]]]] + [[[0,[5,8]],[[1,7],[9,6]]],[[4,[1,2]],[[1,4],2]]], which reduces to [[[[7,8],[6,6]],[[6,0],[7,7]]],[[[7,8],[8,8]],[[7,9],[0,6]]]]. |
|||
|
|||
What is the largest magnitude of any sum of two different snailfish numbers from the homework assignment? |
|||
|
|||
Your puzzle answer was 4563. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
@ -0,0 +1,100 @@ |
|||
[[[[9,5],[9,4]],[[6,5],[7,0]]],4] |
|||
[[[5,2],[[7,2],1]],[[[7,5],[0,8]],[[6,9],[7,3]]]] |
|||
[[[9,7],[0,1]],9] |
|||
[1,[[7,3],[[3,7],[3,2]]]] |
|||
[[9,[[0,8],7]],[[3,1],[[6,6],[9,0]]]] |
|||
[4,[[4,4],[[7,7],1]]] |
|||
[[[[6,2],[5,1]],[[3,3],9]],[7,[[5,7],[5,0]]]] |
|||
[[[[4,8],[4,9]],[1,[9,3]]],[1,[1,[6,1]]]] |
|||
[[[[4,7],[3,4]],[8,3]],[[3,7],[0,[1,8]]]] |
|||
[[[6,[4,8]],[4,5]],[4,[1,3]]] |
|||
[[[0,7],0],[[6,[1,8]],[9,[7,9]]]] |
|||
[[[[4,8],[3,9]],[4,5]],[1,1]] |
|||
[[[4,2],[0,[6,7]]],[[[1,8],2],[8,8]]] |
|||
[[[[1,1],7],5],[[6,[5,6]],[6,[7,5]]]] |
|||
[[[[3,2],5],[[5,3],1]],[[[0,4],[9,6]],9]] |
|||
[[6,[7,6]],9] |
|||
[[[[4,0],[0,1]],7],1] |
|||
[[[[1,3],4],6],[[1,[4,2]],[1,4]]] |
|||
[[[[6,9],[4,1]],[[6,3],[0,8]]],[[4,0],[[3,2],[2,9]]]] |
|||
[[[3,6],[[2,0],[3,2]]],[2,5]] |
|||
[[[[4,3],5],5],[[4,[4,0]],6]] |
|||
[[[[4,0],3],[[3,5],8]],[[8,[4,4]],[[9,9],[4,1]]]] |
|||
[[[2,7],6],1] |
|||
[[[[5,3],[8,4]],[0,0]],4] |
|||
[[[0,[8,1]],0],3] |
|||
[[[6,5],[8,2]],[[[6,9],[6,1]],[9,9]]] |
|||
[0,[[4,9],6]] |
|||
[[9,[[9,9],4]],[[[4,7],1],2]] |
|||
[[8,0],[[[0,7],6],[[6,4],2]]] |
|||
[[1,[[2,4],8]],1] |
|||
[[[[1,3],4],[[1,3],0]],[[[1,2],3],2]] |
|||
[[[[2,1],2],[5,[2,8]]],[2,[[6,0],2]]] |
|||
[[[8,[1,0]],[[6,7],[9,6]]],[[2,[9,7]],5]] |
|||
[[[3,[2,0]],[[3,2],[0,0]]],[[[4,6],[9,4]],[[7,8],[5,1]]]] |
|||
[[3,[[9,9],[7,2]]],[[1,3],[2,[3,2]]]] |
|||
[4,[4,[[9,5],6]]] |
|||
[[[[5,7],7],[[3,4],0]],[[9,[8,2]],[2,3]]] |
|||
[[[[2,1],[5,7]],4],[[[6,3],8],[[1,6],[5,1]]]] |
|||
[[[4,4],[[0,9],[7,8]]],[[2,[2,5]],5]] |
|||
[1,[5,[[3,7],[8,2]]]] |
|||
[[[[9,5],[8,6]],[5,5]],[[[9,2],8],[[9,3],[3,8]]]] |
|||
[0,[[9,5],[[3,7],7]]] |
|||
[[[8,[0,4]],[[2,9],6]],[[6,[8,0]],4]] |
|||
[[0,[3,5]],[[5,[0,1]],[[3,6],7]]] |
|||
[[2,[7,1]],[[[5,0],[7,7]],[[2,3],9]]] |
|||
[[5,[9,[3,9]]],[[8,[3,7]],[[7,6],[3,0]]]] |
|||
[[[4,[2,5]],5],[3,1]] |
|||
[[[[4,3],1],[[5,7],6]],[0,[3,1]]] |
|||
[[8,9],[[[0,7],5],[6,[5,7]]]] |
|||
[[6,8],[[5,8],[[8,2],[6,0]]]] |
|||
[[1,[5,6]],5] |
|||
[[[6,1],[9,[1,2]]],1] |
|||
[[5,[7,[4,8]]],[[4,[2,9]],5]] |
|||
[[[2,2],[[7,1],3]],[[[9,7],[4,6]],[1,[0,1]]]] |
|||
[[3,[6,[4,5]]],2] |
|||
[[[0,2],[[8,1],[0,6]]],[[7,[9,6]],0]] |
|||
[[[[1,0],[5,1]],[[0,6],5]],[[[1,8],8],[[0,2],5]]] |
|||
[[6,[[3,6],6]],[[[9,7],[6,4]],[[9,5],1]]] |
|||
[[[0,[5,6]],[9,0]],[[2,9],9]] |
|||
[1,[[4,[9,3]],0]] |
|||
[[1,0],[[1,9],[4,8]]] |
|||
[[[9,3],[7,0]],[[[5,1],[3,8]],9]] |
|||
[[[3,9],[[5,9],2]],[[7,2],1]] |
|||
[[1,[[3,0],[7,6]]],[7,[8,1]]] |
|||
[0,[6,[[7,1],[1,1]]]] |
|||
[[4,[[5,0],[2,1]]],[[[8,8],[8,1]],7]] |
|||
[[[[9,3],[4,3]],4],[7,5]] |
|||
[[9,[[7,4],[8,3]]],[[[1,9],7],[[1,6],[3,1]]]] |
|||
[[6,9],[5,[0,[5,1]]]] |
|||
[[[8,7],3],[[4,8],[0,7]]] |
|||
[[[[3,1],2],[[1,6],[4,3]]],[0,6]] |
|||
[[5,[[5,4],3]],[[8,8],9]] |
|||
[[5,[3,[4,5]]],[[2,[6,0]],[6,1]]] |
|||
[[[[9,5],3],6],[[8,[1,9]],[[5,2],5]]] |
|||
[[[7,5],[[3,6],4]],[6,[[5,1],[0,1]]]] |
|||
[[1,[[4,8],[1,3]]],7] |
|||
[[4,[[4,0],5]],[[[6,2],7],[[4,8],[4,9]]]] |
|||
[[[[2,3],[0,9]],[7,2]],[4,5]] |
|||
[[[[7,7],[8,0]],[7,7]],[[[6,6],[3,2]],[4,[4,3]]]] |
|||
[[[[8,7],6],[[5,5],0]],[[6,[7,3]],[[4,1],[1,7]]]] |
|||
[[[2,[2,2]],[[5,2],1]],[[9,[9,2]],6]] |
|||
[[[[1,7],6],[[8,8],5]],[6,[1,[1,7]]]] |
|||
[[[[8,6],[3,2]],[[5,2],[2,0]]],[[[8,7],2],[[5,5],2]]] |
|||
[[[8,[9,0]],[[9,5],[7,5]]],[[5,1],[[1,1],[4,6]]]] |
|||
[5,[9,[[0,2],7]]] |
|||
[8,[[0,[4,9]],[[7,4],9]]] |
|||
[[[[2,9],5],[[0,6],[6,6]]],[[0,6],[[4,2],[9,9]]]] |
|||
[7,[[[4,3],3],[[5,4],[6,0]]]] |
|||
[[0,[8,[1,1]]],5] |
|||
[[[1,8],[[4,6],[9,7]]],[[[6,6],[2,6]],[4,3]]] |
|||
[[0,[[7,5],[9,9]]],[[9,7],[6,2]]] |
|||
[[[9,[3,0]],[[1,4],0]],[[1,1],1]] |
|||
[[[0,7],[[3,0],8]],[[6,[8,0]],[[4,5],[4,0]]]] |
|||
[[[[2,9],[4,2]],[5,[9,3]]],[4,[2,[3,4]]]] |
|||
[[[1,[7,3]],[[5,7],0]],[6,[[6,5],2]]] |
|||
[4,5] |
|||
[[7,9],[6,[[6,5],[1,0]]]] |
|||
[[4,[[7,5],8]],[[4,0],[[6,6],[0,4]]]] |
|||
[[[9,[7,7]],[[4,2],7]],4] |
|||
[[0,[0,3]],5] |
@ -0,0 +1,10 @@ |
|||
[[[0,[4,5]],[0,0]],[[[4,5],[2,6]],[9,5]]] |
|||
[7,[[[3,7],[4,3]],[[6,3],[8,8]]]] |
|||
[[2,[[0,8],[3,4]]],[[[6,7],1],[7,[1,6]]]] |
|||
[[[[2,4],7],[6,[0,5]]],[[[6,8],[2,8]],[[2,1],[4,5]]]] |
|||
[7,[5,[[3,8],[1,4]]]] |
|||
[[2,[2,2]],[8,[8,1]]] |
|||
[2,9] |
|||
[1,[[[9,3],9],[[9,0],[0,7]]]] |
|||
[[[5,[7,4]],7],1] |
|||
[[[[4,2],2],6],[8,7]] |
@ -0,0 +1,94 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys, math |
|||
import numpy as np |
|||
|
|||
def rotations(x,y,z): |
|||
r = [ |
|||
# x is facing x |
|||
[x, y, z], |
|||
[x, -z, y], |
|||
[x, -y, -z], |
|||
[x, z, -y], |
|||
# x is facing -x |
|||
[-x, -y, z], |
|||
[-x, -z, -y], |
|||
[-x, y, -z], |
|||
[-x, z, y], |
|||
# x is facing y |
|||
[-z, x, -y], |
|||
[y, x, -z], |
|||
[z, x, y], |
|||
[-y, x, z], |
|||
# x is facing -y |
|||
[z, -x, -y], |
|||
[y, -x, z], |
|||
[-z, -x, y], |
|||
[-y, -x, -z], |
|||
# x is facing z |
|||
[-y, -z, x], |
|||
[z, -y, x], |
|||
[y, z, x], |
|||
[-z, y, x], |
|||
# x is facing -z |
|||
[z, y, -x], |
|||
[-y, z, -x], |
|||
[-z, -y, -x], |
|||
[y, -z, -x] |
|||
] |
|||
for point in r: |
|||
yield np.array(point) |
|||
|
|||
def overlap(s1,s2,off): |
|||
se1 = set([tuple(p) for p in s1]) |
|||
se2 = set([tuple(p-off) for p in s2]) |
|||
return len(se1.intersection(se2)) |
|||
|
|||
def test(s1,s2): |
|||
rot = [[r for r in rotations(*p)] for p in s2] |
|||
rot2 = [[r[i] for r in rot] for i in range(24)] |
|||
mc = 0 |
|||
for i in range(24): |
|||
for p1 in s1: |
|||
for p2 in rot2[i]: |
|||
dif = p2 - p1 |
|||
com = overlap(s1,rot2[i],dif) |
|||
if com > mc: |
|||
mc = com |
|||
if mc >= 12: |
|||
return [r - dif for r in rot2[i]], dif |
|||
return None, None |
|||
|
|||
if __name__ == '__main__': |
|||
nums = [[np.array([i for i in map(int,n.split(','))]) for n in line.split('\n')[1:] if n != ''] for line in open(sys.argv[1]).read().split('\n\n')] |
|||
|
|||
scanners = [] |
|||
matched = {} |
|||
matched[0] = nums[0] |
|||
al = set([tuple(i) for i in matched[0]]) |
|||
while len(matched) != len(nums): |
|||
for i in range(len(nums)): |
|||
if i in matched: continue |
|||
r = None |
|||
r, d = test(al,nums[i]) |
|||
scanners.append(d) |
|||
if r != None: |
|||
matched[i] = r |
|||
al = al.union(set([tuple(i) for i in matched[i]])) |
|||
break |
|||
|
|||
m = 0 |
|||
for a in scanners: |
|||
for b in scanners: |
|||
n = sum(abs(a[i] - b[i]) for i in range(3)) |
|||
if n > m: |
|||
m = n |
|||
|
|||
# challenge 1 |
|||
res1 = str(len(al)) |
|||
print("challenge 1:" + "\n" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
res2 = str(m) |
|||
print("challenge 2:" + "\n" + res2 + "\n") |
|||
|
@ -0,0 +1,378 @@ |
|||
--- Day 19: Beacon Scanner --- |
|||
|
|||
As your probe drifted down through this area, it released an assortment of beacons and scanners into the water. It's difficult to navigate in the pitch black open waters of the ocean trench, but if you can build a map of the trench using data from the scanners, you should be able to safely reach the bottom. |
|||
|
|||
The beacons and scanners float motionless in the water; they're designed to maintain the same position for long periods of time. Each scanner is capable of detecting all beacons in a large cube centered on the scanner; beacons that are at most 1000 units away from the scanner in each of the three axes (x, y, and z) have their precise position determined relative to the scanner. However, scanners cannot detect other scanners. The submarine has automatically summarized the relative positions of beacons detected by each scanner (your puzzle input). |
|||
|
|||
For example, if a scanner is at x,y,z coordinates 500,0,-500 and there are beacons at -500,1000,-1500 and 1501,0,-500, the scanner could report that the first beacon is at -1000,1000,-1000 (relative to the scanner) but would not detect the second beacon at all. |
|||
|
|||
Unfortunately, while each scanner can report the positions of all detected beacons relative to itself, the scanners do not know their own position. You'll need to determine the positions of the beacons and scanners yourself. |
|||
|
|||
The scanners and beacons map a single contiguous 3d region. This region can be reconstructed by finding pairs of scanners that have overlapping detection regions such that there are at least 12 beacons that both scanners detect within the overlap. By establishing 12 common beacons, you can precisely determine where the scanners are relative to each other, allowing you to reconstruct the beacon map one scanner at a time. |
|||
|
|||
For a moment, consider only two dimensions. Suppose you have the following scanner reports: |
|||
|
|||
--- scanner 0 --- |
|||
0,2 |
|||
4,1 |
|||
3,3 |
|||
|
|||
--- scanner 1 --- |
|||
-1,-1 |
|||
-5,0 |
|||
-2,1 |
|||
|
|||
Drawing x increasing rightward, y increasing upward, scanners as S, and beacons as B, scanner 0 detects this: |
|||
|
|||
...B. |
|||
B.... |
|||
....B |
|||
S.... |
|||
|
|||
Scanner 1 detects this: |
|||
|
|||
...B.. |
|||
B....S |
|||
....B. |
|||
|
|||
For this example, assume scanners only need 3 overlapping beacons. Then, the beacons visible to both scanners overlap to produce the following complete map: |
|||
|
|||
...B.. |
|||
B....S |
|||
....B. |
|||
S..... |
|||
|
|||
Unfortunately, there's a second problem: the scanners also don't know their rotation or facing direction. Due to magnetic alignment, each scanner is rotated some integer number of 90-degree turns around all of the x, y, and z axes. That is, one scanner might call a direction positive x, while another scanner might call that direction negative y. Or, two scanners might agree on which direction is positive x, but one scanner might be upside-down from the perspective of the other scanner. In total, each scanner could be in any of 24 different orientations: facing positive or negative x, y, or z, and considering any of four directions "up" from that facing. |
|||
|
|||
For example, here is an arrangement of beacons as seen from a scanner in the same position but in different orientations: |
|||
|
|||
--- scanner 0 --- |
|||
-1,-1,1 |
|||
-2,-2,2 |
|||
-3,-3,3 |
|||
-2,-3,1 |
|||
5,6,-4 |
|||
8,0,7 |
|||
|
|||
--- scanner 0 --- |
|||
1,-1,1 |
|||
2,-2,2 |
|||
3,-3,3 |
|||
2,-1,3 |
|||
-5,4,-6 |
|||
-8,-7,0 |
|||
|
|||
--- scanner 0 --- |
|||
-1,-1,-1 |
|||
-2,-2,-2 |
|||
-3,-3,-3 |
|||
-1,-3,-2 |
|||
4,6,5 |
|||
-7,0,8 |
|||
|
|||
--- scanner 0 --- |
|||
1,1,-1 |
|||
2,2,-2 |
|||
3,3,-3 |
|||
1,3,-2 |
|||
-4,-6,5 |
|||
7,0,8 |
|||
|
|||
--- scanner 0 --- |
|||
1,1,1 |
|||
2,2,2 |
|||
3,3,3 |
|||
3,1,2 |
|||
-6,-4,-5 |
|||
0,7,-8 |
|||
|
|||
By finding pairs of scanners that both see at least 12 of the same beacons, you can assemble the entire map. For example, consider the following report: |
|||
|
|||
--- scanner 0 --- |
|||
404,-588,-901 |
|||
528,-643,409 |
|||
-838,591,734 |
|||
390,-675,-793 |
|||
-537,-823,-458 |
|||
-485,-357,347 |
|||
-345,-311,381 |
|||
-661,-816,-575 |
|||
-876,649,763 |
|||
-618,-824,-621 |
|||
553,345,-567 |
|||
474,580,667 |
|||
-447,-329,318 |
|||
-584,868,-557 |
|||
544,-627,-890 |
|||
564,392,-477 |
|||
455,729,728 |
|||
-892,524,684 |
|||
-689,845,-530 |
|||
423,-701,434 |
|||
7,-33,-71 |
|||
630,319,-379 |
|||
443,580,662 |
|||
-789,900,-551 |
|||
459,-707,401 |
|||
|
|||
--- scanner 1 --- |
|||
686,422,578 |
|||
605,423,415 |
|||
515,917,-361 |
|||
-336,658,858 |
|||
95,138,22 |
|||
-476,619,847 |
|||
-340,-569,-846 |
|||
567,-361,727 |
|||
-460,603,-452 |
|||
669,-402,600 |
|||
729,430,532 |
|||
-500,-761,534 |
|||
-322,571,750 |
|||
-466,-666,-811 |
|||
-429,-592,574 |
|||
-355,545,-477 |
|||
703,-491,-529 |
|||
-328,-685,520 |
|||
413,935,-424 |
|||
-391,539,-444 |
|||
586,-435,557 |
|||
-364,-763,-893 |
|||
807,-499,-711 |
|||
755,-354,-619 |
|||
553,889,-390 |
|||
|
|||
--- scanner 2 --- |
|||
649,640,665 |
|||
682,-795,504 |
|||
-784,533,-524 |
|||
-644,584,-595 |
|||
-588,-843,648 |
|||
-30,6,44 |
|||
-674,560,763 |
|||
500,723,-460 |
|||
609,671,-379 |
|||
-555,-800,653 |
|||
-675,-892,-343 |
|||
697,-426,-610 |
|||
578,704,681 |
|||
493,664,-388 |
|||
-671,-858,530 |
|||
-667,343,800 |
|||
571,-461,-707 |
|||
-138,-166,112 |
|||
-889,563,-600 |
|||
646,-828,498 |
|||
640,759,510 |
|||
-630,509,768 |
|||
-681,-892,-333 |
|||
673,-379,-804 |
|||
-742,-814,-386 |
|||
577,-820,562 |
|||
|
|||
--- scanner 3 --- |
|||
-589,542,597 |
|||
605,-692,669 |
|||
-500,565,-823 |
|||
-660,373,557 |
|||
-458,-679,-417 |
|||
-488,449,543 |
|||
-626,468,-788 |
|||
338,-750,-386 |
|||
528,-832,-391 |
|||
562,-778,733 |
|||
-938,-730,414 |
|||
543,643,-506 |
|||
-524,371,-870 |
|||
407,773,750 |
|||
-104,29,83 |
|||
378,-903,-323 |
|||
-778,-728,485 |
|||
426,699,580 |
|||
-438,-605,-362 |
|||
-469,-447,-387 |
|||
509,732,623 |
|||
647,635,-688 |
|||
-868,-804,481 |
|||
614,-800,639 |
|||
595,780,-596 |
|||
|
|||
--- scanner 4 --- |
|||
727,592,562 |
|||
-293,-554,779 |
|||
441,611,-461 |
|||
-714,465,-776 |
|||
-743,427,-804 |
|||
-660,-479,-426 |
|||
832,-632,460 |
|||
927,-485,-438 |
|||
408,393,-506 |
|||
466,436,-512 |
|||
110,16,151 |
|||
-258,-428,682 |
|||
-393,719,612 |
|||
-211,-452,876 |
|||
808,-476,-593 |
|||
-575,615,604 |
|||
-485,667,467 |
|||
-680,325,-822 |
|||
-627,-443,-432 |
|||
872,-547,-609 |
|||
833,512,582 |
|||
807,604,487 |
|||
839,-516,451 |
|||
891,-625,532 |
|||
-652,-548,-490 |
|||
30,-46,-14 |
|||
|
|||
Because all coordinates are relative, in this example, all "absolute" positions will be expressed relative to scanner 0 (using the orientation of scanner 0 and as if scanner 0 is at coordinates 0,0,0). |
|||
|
|||
Scanners 0 and 1 have overlapping detection cubes; the 12 beacons they both detect (relative to scanner 0) are at the following coordinates: |
|||
|
|||
-618,-824,-621 |
|||
-537,-823,-458 |
|||
-447,-329,318 |
|||
404,-588,-901 |
|||
544,-627,-890 |
|||
528,-643,409 |
|||
-661,-816,-575 |
|||
390,-675,-793 |
|||
423,-701,434 |
|||
-345,-311,381 |
|||
459,-707,401 |
|||
-485,-357,347 |
|||
|
|||
These same 12 beacons (in the same order) but from the perspective of scanner 1 are: |
|||
|
|||
686,422,578 |
|||
605,423,415 |
|||
515,917,-361 |
|||
-336,658,858 |
|||
-476,619,847 |
|||
-460,603,-452 |
|||
729,430,532 |
|||
-322,571,750 |
|||
-355,545,-477 |
|||
413,935,-424 |
|||
-391,539,-444 |
|||
553,889,-390 |
|||
|
|||
Because of this, scanner 1 must be at 68,-1246,-43 (relative to scanner 0). |
|||
|
|||
Scanner 4 overlaps with scanner 1; the 12 beacons they both detect (relative to scanner 0) are: |
|||
|
|||
459,-707,401 |
|||
-739,-1745,668 |
|||
-485,-357,347 |
|||
432,-2009,850 |
|||
528,-643,409 |
|||
423,-701,434 |
|||
-345,-311,381 |
|||
408,-1815,803 |
|||
534,-1912,768 |
|||
-687,-1600,576 |
|||
-447,-329,318 |
|||
-635,-1737,486 |
|||
|
|||
So, scanner 4 is at -20,-1133,1061 (relative to scanner 0). |
|||
|
|||
Following this process, scanner 2 must be at 1105,-1205,1229 (relative to scanner 0) and scanner 3 must be at -92,-2380,-20 (relative to scanner 0). |
|||
|
|||
The full list of beacons (relative to scanner 0) is: |
|||
|
|||
-892,524,684 |
|||
-876,649,763 |
|||
-838,591,734 |
|||
-789,900,-551 |
|||
-739,-1745,668 |
|||
-706,-3180,-659 |
|||
-697,-3072,-689 |
|||
-689,845,-530 |
|||
-687,-1600,576 |
|||
-661,-816,-575 |
|||
-654,-3158,-753 |
|||
-635,-1737,486 |
|||
-631,-672,1502 |
|||
-624,-1620,1868 |
|||
-620,-3212,371 |
|||
-618,-824,-621 |
|||
-612,-1695,1788 |
|||
-601,-1648,-643 |
|||
-584,868,-557 |
|||
-537,-823,-458 |
|||
-532,-1715,1894 |
|||
-518,-1681,-600 |
|||
-499,-1607,-770 |
|||
-485,-357,347 |
|||
-470,-3283,303 |
|||
-456,-621,1527 |
|||
-447,-329,318 |
|||
-430,-3130,366 |
|||
-413,-627,1469 |
|||
-345,-311,381 |
|||
-36,-1284,1171 |
|||
-27,-1108,-65 |
|||
7,-33,-71 |
|||
12,-2351,-103 |
|||
26,-1119,1091 |
|||
346,-2985,342 |
|||
366,-3059,397 |
|||
377,-2827,367 |
|||
390,-675,-793 |
|||
396,-1931,-563 |
|||
404,-588,-901 |
|||
408,-1815,803 |
|||
423,-701,434 |
|||
432,-2009,850 |
|||
443,580,662 |
|||
455,729,728 |
|||
456,-540,1869 |
|||
459,-707,401 |
|||
465,-695,1988 |
|||
474,580,667 |
|||
496,-1584,1900 |
|||
497,-1838,-617 |
|||
527,-524,1933 |
|||
528,-643,409 |
|||
534,-1912,768 |
|||
544,-627,-890 |
|||
553,345,-567 |
|||
564,392,-477 |
|||
568,-2007,-577 |
|||
605,-1665,1952 |
|||
612,-1593,1893 |
|||
630,319,-379 |
|||
686,-3108,-505 |
|||
776,-3184,-501 |
|||
846,-3110,-434 |
|||
1135,-1161,1235 |
|||
1243,-1093,1063 |
|||
1660,-552,429 |
|||
1693,-557,386 |
|||
1735,-437,1738 |
|||
1749,-1800,1813 |
|||
1772,-405,1572 |
|||
1776,-675,371 |
|||
1779,-442,1789 |
|||
1780,-1548,337 |
|||
1786,-1538,337 |
|||
1847,-1591,415 |
|||
1889,-1729,1762 |
|||
1994,-1805,1792 |
|||
|
|||
In total, there are 79 beacons. |
|||
|
|||
Assemble the full map of beacons. How many beacons are there? |
|||
|
|||
Your puzzle answer was 323. |
|||
--- Part Two --- |
|||
|
|||
Sometimes, it's a good idea to appreciate just how big the ocean is. Using the Manhattan distance, how far apart do the scanners get? |
|||
|
|||
In the above example, scanners 2 (1105,-1205,1229) and 3 (-92,-2380,-20) are the largest Manhattan distance apart. In total, they are 1197 + 1175 + 1249 = 3621 units apart. |
|||
|
|||
What is the largest Manhattan distance between any two scanners? |
|||
|
|||
Your puzzle answer was 10685. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
@ -0,0 +1,780 @@ |
|||
--- scanner 0 --- |
|||
-757,414,492 |
|||
-593,762,-478 |
|||
-608,779,-508 |
|||
-761,323,468 |
|||
-583,-536,626 |
|||
539,660,453 |
|||
745,-932,544 |
|||
419,509,439 |
|||
62,-24,118 |
|||
338,-793,-584 |
|||
-775,808,-521 |
|||
708,771,-798 |
|||
-90,-99,12 |
|||
400,-811,-639 |
|||
850,-816,468 |
|||
715,652,-760 |
|||
-820,276,460 |
|||
737,-883,437 |
|||
716,659,-718 |
|||
-619,-458,-521 |
|||
-551,-451,-643 |
|||
477,574,399 |
|||
-653,-464,-508 |
|||
-596,-505,704 |
|||
438,-706,-637 |
|||
-589,-621,598 |
|||
|
|||
--- scanner 1 --- |
|||
-386,481,-530 |
|||
568,822,748 |
|||
56,78,41 |
|||
-653,837,672 |
|||
-825,-465,-698 |
|||
-842,-495,-683 |
|||
517,-321,717 |
|||
401,-495,-638 |
|||
442,717,-695 |
|||
-661,-765,361 |
|||
558,611,-702 |
|||
-871,-508,-516 |
|||
-339,473,-471 |
|||
-709,-772,450 |
|||
441,-376,741 |
|||
-477,505,-534 |
|||
388,-630,-740 |
|||
473,639,-708 |
|||
-528,845,807 |
|||
-610,763,777 |
|||
583,809,645 |
|||
502,-587,734 |
|||
395,-508,-672 |
|||
-37,-6,-116 |
|||
-623,-735,471 |
|||
505,810,757 |
|||
|
|||
--- scanner 2 --- |
|||
-695,364,-810 |
|||
-642,483,453 |
|||
745,-960,-441 |
|||
743,235,-394 |
|||
15,-139,-14 |
|||
-452,-639,536 |
|||
635,652,646 |
|||
810,-702,549 |
|||
700,-762,505 |
|||
-453,-534,569 |
|||
621,-860,-431 |
|||
695,501,604 |
|||
-510,489,384 |
|||
-706,370,-596 |
|||
-536,388,405 |
|||
-628,402,-625 |
|||
633,540,465 |
|||
802,-735,390 |
|||
606,-923,-539 |
|||
578,271,-459 |
|||
105,-2,-130 |
|||
-517,-596,-542 |
|||
-571,-576,-529 |
|||
-486,-440,473 |
|||
654,315,-514 |
|||
-443,-634,-618 |
|||
|
|||
--- scanner 3 --- |
|||
812,-526,-776 |
|||
447,879,691 |
|||
-2,88,14 |
|||
-853,-613,-699 |
|||
868,-612,-712 |
|||
-746,793,-620 |
|||
-860,-681,-577 |
|||
491,-498,660 |
|||
-529,-701,302 |
|||
502,814,567 |
|||
-540,613,383 |
|||
445,628,-447 |
|||
355,810,596 |
|||
403,-351,685 |
|||
-807,800,-831 |
|||
-33,-43,-159 |
|||
-731,776,-886 |
|||
583,616,-432 |
|||
-582,553,534 |
|||
-602,-816,250 |
|||
471,485,-398 |
|||
872,-622,-827 |
|||
-568,-778,372 |
|||
377,-461,620 |
|||
-721,615,495 |
|||
-847,-579,-712 |
|||
|
|||
--- scanner 4 --- |
|||
-383,-542,-722 |
|||
703,879,-598 |
|||
587,-459,579 |
|||
-424,322,707 |
|||
-398,371,564 |
|||
113,1,1 |
|||
629,-610,639 |
|||
-400,-767,313 |
|||
-455,-643,378 |
|||
777,869,-619 |
|||
-308,-672,382 |
|||
793,544,399 |
|||
-536,356,576 |
|||
828,-723,-592 |
|||
-389,-498,-592 |
|||
768,-571,577 |
|||
854,755,392 |
|||
-621,489,-516 |
|||
-611,512,-432 |
|||
849,-622,-566 |
|||
-443,-593,-655 |
|||
753,753,-624 |
|||
778,810,416 |
|||
780,-628,-698 |
|||
-654,590,-372 |
|||
|
|||
--- scanner 5 --- |
|||
366,-674,-398 |
|||
646,574,-495 |
|||
810,-712,775 |
|||
-776,-616,-664 |
|||
709,499,-484 |
|||
538,832,519 |
|||
-851,-513,601 |
|||
330,-736,-449 |
|||
-832,-477,488 |
|||
754,549,-531 |
|||
534,-704,-421 |
|||
589,756,371 |
|||
-769,699,-884 |
|||
742,-698,801 |
|||
-608,351,427 |
|||
616,920,401 |
|||
-821,-527,-723 |
|||
-149,-42,-32 |
|||
-775,702,-638 |
|||
-576,337,535 |
|||
-750,-560,-579 |
|||
-717,658,-756 |
|||
632,-708,837 |
|||
-18,44,105 |
|||
-824,-294,581 |
|||
-538,374,539 |
|||
|
|||
--- scanner 6 --- |
|||
-670,706,-858 |
|||
342,376,641 |
|||
405,-867,-344 |
|||
-768,-540,-416 |
|||
-591,518,863 |
|||
-711,414,845 |
|||
-776,-509,-579 |
|||
281,-922,466 |
|||
-464,-713,728 |
|||
378,352,-541 |
|||
288,342,-625 |
|||
287,-929,-439 |
|||
-757,-508,-659 |
|||
-18,-130,-81 |
|||
-577,685,-840 |
|||
371,-842,552 |
|||
-550,433,837 |
|||
-523,-701,877 |
|||
303,376,-402 |
|||
247,-928,631 |
|||
-659,-686,773 |
|||
333,388,704 |
|||
445,389,626 |
|||
-433,677,-834 |
|||
358,-840,-351 |
|||
|
|||
--- scanner 7 --- |
|||
-608,662,-491 |
|||
-421,395,723 |
|||
537,400,-654 |
|||
-801,-707,334 |
|||
-716,-378,-908 |
|||
-606,481,-603 |
|||
-691,-669,364 |
|||
722,-794,-779 |
|||
-712,-755,327 |
|||
-551,-443,-872 |
|||
-64,-119,-13 |
|||
50,75,-130 |
|||
590,472,837 |
|||
655,-609,-741 |
|||
-668,620,-642 |
|||
-445,471,778 |
|||
569,546,847 |
|||
-428,456,512 |
|||
595,496,721 |
|||
733,-580,-773 |
|||
563,421,-755 |
|||
669,469,-660 |
|||
-627,-498,-828 |
|||
799,-779,496 |
|||
860,-721,542 |
|||
820,-593,474 |
|||
|
|||
--- scanner 8 --- |
|||
529,-663,-800 |
|||
519,-548,-804 |
|||
-429,-739,586 |
|||
271,298,-446 |
|||
-718,433,-595 |
|||
505,549,874 |
|||
562,-663,915 |
|||
615,-599,-744 |
|||
-729,576,-465 |
|||
351,484,-448 |
|||
-529,-792,673 |
|||
305,358,-378 |
|||
-68,-144,62 |
|||
498,443,758 |
|||
528,-676,921 |
|||
-836,389,447 |
|||
-828,282,496 |
|||
-796,-643,-252 |
|||
-491,-794,568 |
|||
-652,604,-655 |
|||
492,471,843 |
|||
-653,-636,-220 |
|||
460,-798,928 |
|||
-941,313,563 |
|||
-115,1,182 |
|||
-609,-662,-266 |
|||
|
|||
--- scanner 9 --- |
|||
819,-614,-852 |
|||
-394,-498,662 |
|||
-568,774,-852 |
|||
-488,737,-781 |
|||
-672,-417,-703 |
|||
-664,-337,-815 |
|||
652,-627,-823 |
|||
498,457,699 |
|||
595,-492,407 |
|||
-568,636,624 |
|||
645,572,-483 |
|||
575,387,738 |
|||
47,-73,82 |
|||
-546,514,691 |
|||
697,-627,420 |
|||
-442,625,-847 |
|||
-356,-496,767 |
|||
-671,-375,-696 |
|||
460,335,665 |
|||
745,655,-394 |
|||
663,-614,414 |
|||
865,584,-431 |
|||
637,-657,-806 |
|||
-700,627,697 |
|||
-294,-551,749 |
|||
|
|||
--- scanner 10 --- |
|||
12,120,-29 |
|||
-342,-679,-939 |
|||
530,-282,501 |
|||
-809,684,-468 |
|||
489,-308,416 |
|||
572,350,621 |
|||
-403,-504,359 |
|||
577,584,627 |
|||
403,-417,-730 |
|||
-66,14,-156 |
|||
414,664,-519 |
|||
598,-372,-703 |
|||
650,-300,397 |
|||
-506,-519,372 |
|||
-884,650,-644 |
|||
-765,612,-643 |
|||
-394,-441,371 |
|||
462,-268,-718 |
|||
-374,674,418 |
|||
-308,-514,-945 |
|||
398,839,-455 |
|||
-344,592,336 |
|||
363,708,-493 |
|||
-479,717,344 |
|||
623,433,604 |
|||
-432,-593,-859 |
|||
|
|||
--- scanner 11 --- |
|||
891,-554,-721 |
|||
-666,637,-444 |
|||
-607,-541,-415 |
|||
29,2,4 |
|||
162,154,-54 |
|||
-404,-217,531 |
|||
532,510,-451 |
|||
713,-606,830 |
|||
928,-640,-742 |
|||
-654,574,-435 |
|||
-681,-584,-520 |
|||
-609,441,448 |
|||
-689,-459,-385 |
|||
-398,-451,536 |
|||
743,571,-458 |
|||
921,-592,-831 |
|||
534,611,565 |
|||
477,586,-475 |
|||
781,-478,790 |
|||
408,661,539 |
|||
-653,652,-547 |
|||
759,-664,769 |
|||
-524,415,489 |
|||
418,587,560 |
|||
-421,-300,582 |
|||
-628,433,609 |
|||
|
|||
--- scanner 12 --- |
|||
-377,614,-406 |
|||
-552,-831,694 |
|||
527,-699,-733 |
|||
-754,618,829 |
|||
-411,-958,-621 |
|||
745,422,-840 |
|||
509,-816,-841 |
|||
-425,703,-413 |
|||
849,417,-798 |
|||
605,657,787 |
|||
-689,453,793 |
|||
-338,-820,700 |
|||
772,341,-775 |
|||
649,784,719 |
|||
670,-589,575 |
|||
-539,-918,-553 |
|||
-353,-897,-575 |
|||
-463,593,-443 |
|||
463,-695,-855 |
|||
130,-179,-79 |
|||
513,-525,626 |
|||
-634,529,749 |
|||
703,610,736 |
|||
45,-46,33 |
|||
661,-442,574 |
|||
-523,-753,662 |
|||
|
|||
--- scanner 13 --- |
|||
909,550,-668 |
|||
112,-89,-14 |
|||
-273,384,725 |
|||
824,456,386 |
|||
-373,374,601 |
|||
-793,-530,-506 |
|||
-594,-593,-472 |
|||
787,-689,-321 |
|||
-657,472,-591 |
|||
717,-801,-298 |
|||
821,591,-739 |
|||
-310,482,586 |
|||
-637,485,-537 |
|||
493,-740,530 |
|||
749,-693,-284 |
|||
724,419,337 |
|||
474,-627,566 |
|||
-531,-606,790 |
|||
-33,37,38 |
|||
-471,-562,680 |
|||
501,-647,347 |
|||
618,425,401 |
|||
-699,-626,-473 |
|||
944,544,-718 |
|||
-498,-447,782 |
|||
-599,561,-463 |
|||
|
|||
--- scanner 14 --- |
|||
551,-821,-732 |
|||
-578,-311,780 |
|||
558,-481,467 |
|||
-688,548,475 |
|||
743,667,230 |
|||
628,740,282 |
|||
-667,-431,700 |
|||
384,-850,-719 |
|||
-866,523,-640 |
|||
608,409,-597 |
|||
-743,-376,744 |
|||
-94,25,-89 |
|||
458,-392,550 |
|||
-849,538,-906 |
|||
566,-804,-762 |
|||
506,422,-732 |
|||
-493,-640,-462 |
|||
-603,-602,-492 |
|||
705,701,352 |
|||
-582,-688,-455 |
|||
338,-429,479 |
|||
-873,462,-851 |
|||
540,416,-719 |
|||
-626,687,514 |
|||
-686,729,363 |
|||
|
|||
--- scanner 15 --- |
|||
-702,-746,443 |
|||
739,592,-374 |
|||
597,814,559 |
|||
763,-590,-410 |
|||
-670,658,-388 |
|||
682,788,518 |
|||
727,655,-365 |
|||
-335,568,609 |
|||
-345,642,630 |
|||
-858,-671,-565 |
|||
-459,719,-381 |
|||
-404,643,-405 |
|||
438,-883,401 |
|||
-843,-533,-553 |
|||
701,796,679 |
|||
-892,-559,-696 |
|||
409,-907,638 |
|||
-725,-756,527 |
|||
-624,-789,383 |
|||
430,-889,545 |
|||
726,577,-477 |
|||
-80,-67,-39 |
|||
-461,618,635 |
|||
773,-674,-320 |
|||
58,23,81 |
|||
739,-451,-335 |
|||
|
|||
--- scanner 16 --- |
|||
-755,578,-603 |
|||
487,691,-754 |
|||
593,698,-638 |
|||
20,82,-38 |
|||
-923,-807,452 |
|||
382,-791,415 |
|||
-559,792,522 |
|||
-834,-736,364 |
|||
-836,-723,-539 |
|||
552,845,568 |
|||
-922,-847,-618 |
|||
-610,838,475 |
|||
-739,456,-638 |
|||
394,-761,-691 |
|||
678,891,498 |
|||
358,-716,554 |
|||
382,-752,-628 |
|||
738,925,566 |
|||
565,704,-723 |
|||
348,-806,638 |
|||
-667,922,511 |
|||
-779,551,-493 |
|||
-916,-813,-453 |
|||
-153,145,64 |
|||
-861,-689,357 |
|||
395,-649,-613 |
|||
|
|||
--- scanner 17 --- |
|||
664,-630,-754 |
|||
805,704,436 |
|||
-431,686,597 |
|||
-587,-662,388 |
|||
-631,-532,382 |
|||
569,439,-825 |
|||
400,-738,620 |
|||
-717,-556,-781 |
|||
-461,651,805 |
|||
-984,750,-627 |
|||
423,-822,610 |
|||
-711,-688,-850 |
|||
459,413,-747 |
|||
674,775,343 |
|||
780,-635,-778 |
|||
790,-656,-704 |
|||
-840,657,-649 |
|||
-53,56,-150 |
|||
-812,-662,-829 |
|||
451,333,-808 |
|||
-112,-109,-68 |
|||
-936,553,-605 |
|||
-682,-599,442 |
|||
708,813,465 |
|||
501,-882,653 |
|||
-541,612,682 |
|||
|
|||
--- scanner 18 --- |
|||
552,283,-704 |
|||
606,-679,-568 |
|||
33,2,166 |
|||
471,-600,469 |
|||
15,-169,53 |
|||
-565,601,731 |
|||
-501,373,-422 |
|||
-680,574,833 |
|||
846,372,668 |
|||
634,306,-684 |
|||
-534,478,-421 |
|||
563,-505,400 |
|||
703,258,-627 |
|||
-665,-549,-505 |
|||
-466,-662,726 |
|||
618,-629,465 |
|||
552,-774,-505 |
|||
-521,541,841 |
|||
-617,-644,-611 |
|||
-605,-701,664 |
|||
804,401,618 |
|||
-686,-650,-479 |
|||
-424,-813,666 |
|||
893,472,557 |
|||
-597,279,-455 |
|||
546,-730,-635 |
|||
|
|||
--- scanner 19 --- |
|||
835,-511,-678 |
|||
895,455,462 |
|||
650,-578,-640 |
|||
-505,-664,948 |
|||
-359,-696,-553 |
|||
161,-95,23 |
|||
790,538,-336 |
|||
749,472,-391 |
|||
888,283,439 |
|||
30,-35,133 |
|||
-384,431,727 |
|||
-455,-638,822 |
|||
-462,405,617 |
|||
820,-434,597 |
|||
-380,-670,-654 |
|||
784,307,460 |
|||
699,385,-327 |
|||
621,-500,-672 |
|||
-401,325,609 |
|||
-428,-564,-559 |
|||
-560,649,-682 |
|||
762,-373,643 |
|||
-604,545,-778 |
|||
-431,-643,938 |
|||
634,-413,575 |
|||
-582,742,-826 |
|||
|
|||
--- scanner 20 --- |
|||
-600,-782,533 |
|||
596,577,-670 |
|||
620,550,-780 |
|||
-646,690,-519 |
|||
286,-347,543 |
|||
763,-848,-655 |
|||
-541,-753,-645 |
|||
413,595,320 |
|||
321,586,395 |
|||
-752,697,-635 |
|||
-75,63,-4 |
|||
677,-724,-734 |
|||
-518,-812,451 |
|||
-554,-650,-660 |
|||
-526,-677,576 |
|||
-882,525,309 |
|||
-724,703,-550 |
|||
-890,466,262 |
|||
-24,138,-191 |
|||
461,-391,471 |
|||
-175,5,-154 |
|||
462,-272,509 |
|||
-553,-762,-582 |
|||
-858,529,400 |
|||
373,551,219 |
|||
580,455,-635 |
|||
757,-814,-820 |
|||
|
|||
--- scanner 21 --- |
|||
-377,-514,-910 |
|||
844,-627,-723 |
|||
759,-599,-717 |
|||
-445,-454,-944 |
|||
-402,821,411 |
|||
929,642,-755 |
|||
749,-810,733 |
|||
734,-797,630 |
|||
812,-798,742 |
|||
-294,-810,772 |
|||
-514,787,542 |
|||
-376,772,554 |
|||
875,-705,-710 |
|||
876,388,726 |
|||
-447,-640,-864 |
|||
916,507,-653 |
|||
800,333,702 |
|||
-433,-834,697 |
|||
-803,392,-696 |
|||
-517,-844,787 |
|||
922,520,-687 |
|||
-743,443,-600 |
|||
22,-64,-168 |
|||
160,4,-35 |
|||
815,599,719 |
|||
-799,507,-686 |
|||
|
|||
--- scanner 22 --- |
|||
817,529,-684 |
|||
728,823,688 |
|||
-473,-503,418 |
|||
-72,102,143 |
|||
-547,657,684 |
|||
559,-544,861 |
|||
-476,801,651 |
|||
821,-620,-435 |
|||
699,781,638 |
|||
-521,742,740 |
|||
628,870,577 |
|||
-465,-410,601 |
|||
526,-703,853 |
|||
622,-557,-401 |
|||
-721,-457,-213 |
|||
727,-524,-402 |
|||
-528,962,-575 |
|||
499,-588,751 |
|||
-580,834,-534 |
|||
-689,-349,-227 |
|||
66,6,64 |
|||
794,611,-664 |
|||
842,680,-607 |
|||
-446,-523,637 |
|||
-522,716,-578 |
|||
-759,-461,-250 |
|||
|
|||
--- scanner 23 --- |
|||
-352,-697,-348 |
|||
432,569,514 |
|||
-44,-72,111 |
|||
-406,627,809 |
|||
-581,-621,391 |
|||
-473,788,-390 |
|||
819,-664,596 |
|||
877,399,-834 |
|||
566,-655,-584 |
|||
782,-784,667 |
|||
366,523,626 |
|||
473,-689,-636 |
|||
-378,729,728 |
|||
-410,628,711 |
|||
730,-564,679 |
|||
-673,698,-393 |
|||
-334,-673,-384 |
|||
-432,-525,427 |
|||
361,649,477 |
|||
-528,-485,420 |
|||
-310,-680,-500 |
|||
151,90,68 |
|||
-518,655,-370 |
|||
946,312,-770 |
|||
592,-590,-584 |
|||
865,328,-773 |
|||
|
|||
--- scanner 24 --- |
|||
-519,780,-365 |
|||
634,802,-649 |
|||
-674,902,562 |
|||
105,13,-47 |
|||
-667,878,446 |
|||
-662,-634,635 |
|||
-479,684,-358 |
|||
465,-735,700 |
|||
-522,-563,-663 |
|||
704,539,455 |
|||
430,-788,740 |
|||
757,-463,-300 |
|||
-606,-678,-646 |
|||
677,-509,-447 |
|||
794,739,452 |
|||
-657,-639,463 |
|||
-706,-723,627 |
|||
735,834,-666 |
|||
-595,-597,-832 |
|||
575,-753,793 |
|||
661,694,432 |
|||
-62,53,53 |
|||
633,806,-747 |
|||
678,-478,-454 |
|||
-691,860,410 |
|||
-615,631,-329 |
|||
|
|||
--- scanner 25 --- |
|||
183,2,-88 |
|||
656,638,481 |
|||
894,-843,430 |
|||
-325,-646,403 |
|||
-658,-347,-552 |
|||
619,806,-682 |
|||
657,512,589 |
|||
562,876,-811 |
|||
5,-20,46 |
|||
-679,-329,-645 |
|||
-650,-353,-408 |
|||
-315,-562,313 |
|||
536,-608,-751 |
|||
586,835,-891 |
|||
-759,588,-782 |
|||
701,481,532 |
|||
-639,600,608 |
|||
867,-836,383 |
|||
-349,-785,328 |
|||
567,-771,-743 |
|||
956,-748,312 |
|||
535,-528,-732 |
|||
-702,558,533 |
|||
-554,511,-793 |
|||
-765,497,-720 |
|||
-786,627,617 |
|||
|
|||
--- scanner 26 --- |
|||
568,-612,-772 |
|||
-494,-703,-776 |
|||
689,-640,-900 |
|||
512,-573,342 |
|||
765,568,275 |
|||
-699,525,741 |
|||
508,448,-580 |
|||
558,403,-627 |
|||
-458,-494,437 |
|||
58,44,-10 |
|||
-695,623,-517 |
|||
-620,-556,487 |
|||
-452,-603,-788 |
|||
-689,415,705 |
|||
929,541,305 |
|||
675,-619,407 |
|||
479,-562,414 |
|||
-703,347,679 |
|||
-665,791,-494 |
|||
-527,-407,477 |
|||
128,-52,-173 |
|||
583,511,-591 |
|||
698,-517,-736 |
|||
-727,827,-545 |
|||
-409,-773,-839 |
|||
841,619,423 |
|||
|
|||
--- scanner 27 --- |
|||
743,-494,-529 |
|||
20,142,-6 |
|||
374,-668,657 |
|||
-568,-551,-817 |
|||
374,719,-731 |
|||
-538,-500,730 |
|||
-515,-415,-788 |
|||
-385,-491,820 |
|||
-427,-538,747 |
|||
-393,697,-399 |
|||
411,815,380 |
|||
-365,799,-480 |
|||
530,822,418 |
|||
420,-486,700 |
|||
-702,757,526 |
|||
-419,-455,-781 |
|||
403,-501,670 |
|||
-626,716,631 |
|||
-397,698,-497 |
|||
157,78,120 |
|||
379,593,-582 |
|||
523,823,460 |
|||
445,639,-694 |
|||
832,-594,-612 |
|||
-640,682,457 |
|||
795,-714,-541 |
@ -0,0 +1,136 @@ |
|||
--- scanner 0 --- |
|||
404,-588,-901 |
|||
528,-643,409 |
|||
-838,591,734 |
|||
390,-675,-793 |
|||
-537,-823,-458 |
|||
-485,-357,347 |
|||
-345,-311,381 |
|||
-661,-816,-575 |
|||
-876,649,763 |
|||
-618,-824,-621 |
|||
553,345,-567 |
|||
474,580,667 |
|||
-447,-329,318 |
|||
-584,868,-557 |
|||
544,-627,-890 |
|||
564,392,-477 |
|||
455,729,728 |
|||
-892,524,684 |
|||
-689,845,-530 |
|||
423,-701,434 |
|||
7,-33,-71 |
|||
630,319,-379 |
|||
443,580,662 |
|||
-789,900,-551 |
|||
459,-707,401 |
|||
|
|||
--- scanner 1 --- |
|||
686,422,578 |
|||
605,423,415 |
|||
515,917,-361 |
|||
-336,658,858 |
|||
95,138,22 |
|||
-476,619,847 |
|||
-340,-569,-846 |
|||
567,-361,727 |
|||
-460,603,-452 |
|||
669,-402,600 |
|||
729,430,532 |
|||
-500,-761,534 |
|||
-322,571,750 |
|||
-466,-666,-811 |
|||
-429,-592,574 |
|||
-355,545,-477 |
|||
703,-491,-529 |
|||
-328,-685,520 |
|||
413,935,-424 |
|||
-391,539,-444 |
|||
586,-435,557 |
|||
-364,-763,-893 |
|||
807,-499,-711 |
|||
755,-354,-619 |
|||
553,889,-390 |
|||
|
|||
--- scanner 2 --- |
|||
649,640,665 |
|||
682,-795,504 |
|||
-784,533,-524 |
|||
-644,584,-595 |
|||
-588,-843,648 |
|||
-30,6,44 |
|||
-674,560,763 |
|||
500,723,-460 |
|||
609,671,-379 |
|||
-555,-800,653 |
|||
-675,-892,-343 |
|||
697,-426,-610 |
|||
578,704,681 |
|||
493,664,-388 |
|||
-671,-858,530 |
|||
-667,343,800 |
|||
571,-461,-707 |
|||
-138,-166,112 |
|||
-889,563,-600 |
|||
646,-828,498 |
|||
640,759,510 |
|||
-630,509,768 |
|||
-681,-892,-333 |
|||
673,-379,-804 |
|||
-742,-814,-386 |
|||
577,-820,562 |
|||
|
|||
--- scanner 3 --- |
|||
-589,542,597 |
|||
605,-692,669 |
|||
-500,565,-823 |
|||
-660,373,557 |
|||
-458,-679,-417 |
|||
-488,449,543 |
|||
-626,468,-788 |
|||
338,-750,-386 |
|||
528,-832,-391 |
|||
562,-778,733 |
|||
-938,-730,414 |
|||
543,643,-506 |
|||
-524,371,-870 |
|||
407,773,750 |
|||
-104,29,83 |
|||
378,-903,-323 |
|||
-778,-728,485 |
|||
426,699,580 |
|||
-438,-605,-362 |
|||
-469,-447,-387 |
|||
509,732,623 |
|||
647,635,-688 |
|||
-868,-804,481 |
|||
614,-800,639 |
|||
595,780,-596 |
|||
|
|||
--- scanner 4 --- |
|||
727,592,562 |
|||
-293,-554,779 |
|||
441,611,-461 |
|||
-714,465,-776 |
|||
-743,427,-804 |
|||
-660,-479,-426 |
|||
832,-632,460 |
|||
927,-485,-438 |
|||
408,393,-506 |
|||
466,436,-512 |
|||
110,16,151 |
|||
-258,-428,682 |
|||
-393,719,612 |
|||
-211,-452,876 |
|||
808,-476,-593 |
|||
-575,615,604 |
|||
-485,667,467 |
|||
-680,325,-822 |
|||
-627,-443,-432 |
|||
872,-547,-609 |
|||
833,512,582 |
|||
807,604,487 |
|||
839,-516,451 |
|||
891,-625,532 |
|||
-652,-548,-490 |
|||
30,-46,-14 |
@ -0,0 +1,53 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys |
|||
from copy import deepcopy |
|||
|
|||
def imagine(im): |
|||
for y in im: |
|||
l = '' |
|||
for x in y: l += x |
|||
print(l) |
|||
|
|||
def n(im,x,y,o): |
|||
index = '' |
|||
h = [(-1,-1), (-1,0), (-1,1), (0,-1), (0,0), (0,1), (1,-1), (1,0), (1,1)] |
|||
for j,i in h: |
|||
if (0 <= x+i < len(im[0]) and 0 <= y+j < len(im)): index += '0' if im[y+j][x+i] == '.' else '1' |
|||
else: index += '0' if o == '.' else '1' |
|||
return algo[int(index,2)] |
|||
|
|||
def enhance(im, o): |
|||
nex = deepcopy(im) |
|||
for y in range(len(im)): |
|||
for x in range(len(im[0])): |
|||
nex[y][x] = n(im,x,y,o) |
|||
return nex, '.' if o == '#' or mode == 'k' else '#' |
|||
|
|||
if __name__ == '__main__': |
|||
|
|||
algo, im = open(sys.argv[1]).read().split('\n\n') |
|||
algo = list(algo.strip('\n')) |
|||
im = [list(i) for i in im.split('\n') if i != ''] |
|||
|
|||
print('------------------ start -------------------') |
|||
bim = [[im[i-50][j-50] if (49 < i <= len(im)+49 and 49 < j <= len(im[0])+49) else '.' for j in range(len(im[0]) + 100)] for i in range(len(im) + 100)] |
|||
imagine(bim) |
|||
|
|||
mode = 's' if algo[0] == '#' else 'k' |
|||
|
|||
nim, o = bim, '.' |
|||
for i in range(50): |
|||
print('-------------------- ' + str(i) + ' ---------------------') |
|||
nim, o = enhance(nim,o) |
|||
imagine(nim) |
|||
if i == 1: c1 = nim |
|||
|
|||
# challenge 1 |
|||
res1 = str(sum(sum(1 if i == '#' else 0 for i in j) for j in c1)) |
|||
print("challenge 1:" + "\n" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
res2 = str(sum(sum(1 if i == '#' else 0 for i in j) for j in nim)) |
|||
print("challenge 2:" + "\n" + res2 + "\n") |
|||
|
@ -0,0 +1,118 @@ |
|||
--- Day 20: Trench Map --- |
|||
|
|||
With the scanners fully deployed, you turn their attention to mapping the floor of the ocean trench. |
|||
|
|||
When you get back the image from the scanners, it seems to just be random noise. Perhaps you can combine an image enhancement algorithm and the input image (your puzzle input) to clean it up a little. |
|||
|
|||
For example: |
|||
|
|||
..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..## |
|||
#..######.###...####..#..#####..##..#.#####...##.#.#..#.##..#.#......#.### |
|||
.######.###.####...#.##.##..#..#..#####.....#.#....###..#.##......#.....#. |
|||
.#..#..##..#...##.######.####.####.#.#...#.......#..#.#.#...####.##.#..... |
|||
.#..#...##.#.##..#...##.#.##..###.#......#.#.......#.#.#.####.###.##...#.. |
|||
...####.#..#..#.##.#....##..#.####....##...##..#...#......#.#.......#..... |
|||
..##..####..#...#.#.#...##..#.#..###..#####........#..####......#..# |
|||
|
|||
#..#. |
|||
#.... |
|||
##..# |
|||
..#.. |
|||
..### |
|||
|
|||
The first section is the image enhancement algorithm. It is normally given on a single line, but it has been wrapped to multiple lines in this example for legibility. The second section is the input image, a two-dimensional grid of light pixels (#) and dark pixels (.). |
|||
|
|||
The image enhancement algorithm describes how to enhance an image by simultaneously converting all pixels in the input image into an output image. Each pixel of the output image is determined by looking at a 3x3 square of pixels centered on the corresponding input image pixel. So, to determine the value of the pixel at (5,10) in the output image, nine pixels from the input image need to be considered: (4,9), (4,10), (4,11), (5,9), (5,10), (5,11), (6,9), (6,10), and (6,11). These nine input pixels are combined into a single binary number that is used as an index in the image enhancement algorithm string. |
|||
|
|||
For example, to determine the output pixel that corresponds to the very middle pixel of the input image, the nine pixels marked by [...] would need to be considered: |
|||
|
|||
# . . # . |
|||
#[. . .]. |
|||
#[# . .]# |
|||
.[. # .]. |
|||
. . # # # |
|||
|
|||
Starting from the top-left and reading across each row, these pixels are ..., then #.., then .#.; combining these forms ...#...#.. By turning dark pixels (.) into 0 and light pixels (#) into 1, the binary number 000100010 can be formed, which is 34 in decimal. |
|||
|
|||
The image enhancement algorithm string is exactly 512 characters long, enough to match every possible 9-bit binary number. The first few characters of the string (numbered starting from zero) are as follows: |
|||
|
|||
0 10 20 30 34 40 50 60 70 |
|||
| | | | | | | | | |
|||
..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..## |
|||
|
|||
In the middle of this first group of characters, the character at index 34 can be found: #. So, the output pixel in the center of the output image should be #, a light pixel. |
|||
|
|||
This process can then be repeated to calculate every pixel of the output image. |
|||
|
|||
Through advances in imaging technology, the images being operated on here are infinite in size. Every pixel of the infinite output image needs to be calculated exactly based on the relevant pixels of the input image. The small input image you have is only a small region of the actual infinite input image; the rest of the input image consists of dark pixels (.). For the purposes of the example, to save on space, only a portion of the infinite-sized input and output images will be shown. |
|||
|
|||
The starting input image, therefore, looks something like this, with more dark pixels (.) extending forever in every direction not shown here: |
|||
|
|||
............... |
|||
............... |
|||
............... |
|||
............... |
|||
............... |
|||
.....#..#...... |
|||
.....#......... |
|||
.....##..#..... |
|||
.......#....... |
|||
.......###..... |
|||
............... |
|||
............... |
|||
............... |
|||
............... |
|||
............... |
|||
|
|||
By applying the image enhancement algorithm to every pixel simultaneously, the following output image can be obtained: |
|||
|
|||
............... |
|||
............... |
|||
............... |
|||
............... |
|||
.....##.##..... |
|||
....#..#.#..... |
|||
....##.#..#.... |
|||
....####..#.... |
|||
.....#..##..... |
|||
......##..#.... |
|||
.......#.#..... |
|||
............... |
|||
............... |
|||
............... |
|||
............... |
|||
|
|||
Through further advances in imaging technology, the above output image can also be used as an input image! This allows it to be enhanced a second time: |
|||
|
|||
............... |
|||
............... |
|||
............... |
|||
..........#.... |
|||
....#..#.#..... |
|||
...#.#...###... |
|||
...#...##.#.... |
|||
...#.....#.#... |
|||
....#.#####.... |
|||
.....#.#####... |
|||
......##.##.... |
|||
.......###..... |
|||
............... |
|||
............... |
|||
............... |
|||
|
|||
Truly incredible - now the small details are really starting to come through. After enhancing the original input image twice, 35 pixels are lit. |
|||
|
|||
Start with the original input image and apply the image enhancement algorithm twice, being careful to account for the infinite size of the images. How many pixels are lit in the resulting image? |
|||
|
|||
Your puzzle answer was 5391. |
|||
--- Part Two --- |
|||
|
|||
You still can't quite make out the details in the image. Maybe you just didn't enhance it enough. |
|||
|
|||
If you enhance the starting input image in the above example a total of 50 times, 3351 pixels are lit in the final output image. |
|||
|
|||
Start again with the original input image and apply the image enhancement algorithm 50 times. How many pixels are lit in the resulting image? |
|||
|
|||
Your puzzle answer was 16383. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
@ -0,0 +1,102 @@ |
|||
##.##.#.####.#.###.#...##.#..####.##.##..###.####.###.#...###..##.####.##.#..#........####..###....#.#..###.##.######..#####.#.##...#.#.#.####.#.##.#.#.#.#.#....#.###.##...##.####.#.#...#..#.##...##.##....##...##...######.####.#.....####..#.#..#..###..####..###...#.##..#.....###..#.##..#....#.#.#..#.####..#..##...#.##.#......#.###..##...#...##.##...#.##...##.....####.#...........#.#.#..####...###...#.....#.#.#.....###.....###.#.#..##..#.##...####.##..#..#...#.##..#######.#.###..#..##...#.###.#.###.##.##.#.. |
|||
|
|||
..#..##..#..#.####..##..#..######.####......#...#..#.##..#..###...#...#..##....#.##.......#######..# |
|||
.#.#..####...###.#..##.####..##.##.##.#######.#.#.....##.#..#..#.####.##...#.#..#....##.####.#...#.. |
|||
...#........####..#.##..##...#......##.###.##.###....####.#.....#.....#..#.#...##.#.#.#..##..##..##. |
|||
.#.#.####..#..##....##.##.#.#####.###.##.###....##....#.#.#.#...##.#..#...#....###...#.##.#........# |
|||
###...#.##.#..###...#..####...#..###..#...###...###..#...##....#.#..#...#..#..##..#..#.######...#.#. |
|||
##..#.#.###.#..#..#.....#####.#.......#.##.##...#.##.##...##..#.#########.#.....#..##.##.###..#..#.# |
|||
..##.####.###.#..#...#..#.##...##..####.##.##..#..#...#..#.##.###.#.....#..#.##...####.#.###...##... |
|||
.#.####.##.###..###..###.#....#####.###.#...#..##..##..#.#...#.#.##.##.##.#...#...##.#..#..#...#.#.. |
|||
..###.##..#####.##.#.#..#..##..##.##...##.#....######.#.##.#......#..#.##...###.#.##.#.#######.##..# |
|||
##..#.#.##..####..#...#.#....##.#.#.#..##.#..#..####.....###..##...#..##.#.#.#.##.....###....#..#### |
|||
#.#####..###.#.....##.#.#.#..#.#.#.#...#.#.##..####....#.###.###...#...#.#.##...#..#.#.#.....###..#. |
|||
.#.#.#...##..##..##.##...###...#..#.#...#.#..#####......###########.##...######....#..#.#..#.#..#... |
|||
##.########...#..##..#..####..##...#.#.....##.###..#.##.#....##..#.#.###..###..###.##.#.####...###.# |
|||
###...##.#...##.#..#.###..###.#..##.#.#..#..#...#.###.##...#..###.#.#....#.#.##.####..####..##.#.### |
|||
.#..#.#.##.....#.###...#.###....##.####...##.#........###..#.###.#.#.#.###..#.#.####.##.##.....#.##. |
|||
##.#.##..###.#....#.#...#.#..####.###..#...#.#...##..###.#...##..#...#..#.####...#..##..##......#... |
|||
#.###.####.##.#..#..........#........#########.##..####.#..##.#.#...#...#...##.##..#..######.....#.# |
|||
#####.....##.#####..###.###.###.####........#####.###.#.######.##.#.##...####..#..##.##.####.....#.# |
|||
..##..#.##...#.##.#.#....#...#.......##........####.##...######.#.#...######..##..#..#.#.#..###.##.. |
|||
...######..##...###.#...##...#.###.###..#.#..##....#..##..####..#..###...#.......#.#.#.#.##...###.## |
|||
###..#.####....###.#.#..#..#..####....##.#.#..#.#.#.#...##..##.#.##..##....#..##..#.####.#.........# |
|||
#......#.#....#.######..#.#...##...#.#.#.#...##......###...#....#..######..#.#.###..#..####.##.###.# |
|||
.######..###....#...##..###.##........###...#..#.###...#...#..#..###.#..#..##....####.#.#.#.#...##.. |
|||
.....##.#.###..#.#.#..###.##.#.######.#.####.#.##..##...#..####.#.###..##.##..#..##.####.##...#.#... |
|||
#.#...#.#..##........##########.#.#.#.#.##..#.##.##..#..#####...........#..#.###...#####.###....##.# |
|||
.##.##.###...#.##.##.#..#.#...#.##....#.##.##.##..#.#.#..##...#######.#.#...#.####.##..#.#...##..### |
|||
##.#..#..#.#..#.#...###.#..#.#...#.####.#..#...##....###.###.#.#..###.#..###..##...#..###.####...#.. |
|||
##..##..#..#...##.##...#...#....##..###.#.#.....#.####..#......##.###.###...###...#####.###..#..###. |
|||
....###...#......#####....#.#.#..#..#...#...####.########..##...#..######.###.#.#.....###....#.##### |
|||
.###..#.#.........####.##.##..#.#..#..####.##.##........#..###..###.#.....##..##..##.#..###.##.###.# |
|||
.#.####.###.#..#...#####.###.#....##.#.....##.##.#...###..#...#.#...##.####..##..#.#..##.#.#....###. |
|||
##.#.###..##..#.#.####.##.##.####.##......####....#####.##.###..#.####...#.####..####.##.#......##.. |
|||
#.#.#.##.#..#..####.#.#..##..#.##..#..#####......#.#..###.#.####.##.##..####...#..###.#...#..##.#... |
|||
###..#####....#...#...####.....#####...####.###...#.#..##.###.#.##.##.#.###..##.#.####.......#.#.#.# |
|||
.##.#...##..#.##.##.....###.##..#.###....##..####.##.#........##.#..##....###.....###...#..##.....#. |
|||
.#####..#######.##.####..#...#.##.######..#.#...#.#.##.###.##........#####......#####..#.#.##...#### |
|||
.#.#.##......####...##..######...###..##..#.#..#...###..##.#.#...######.####.#.........####...#...#. |
|||
##.#...##.#.#.#...#..##.###..###....###..#.#...##.###...#.###..#.##.##.##..##.##.#..#####.#..####..# |
|||
##.#.#.....#.#..#.####.###.....###.#.......#..#..##..##.##.#.##..###..#.#..#.#####.####..####.#####. |
|||
.#..##..#.##..#...###..#...#..#......#.#..#.#######.#.#.####.###...#####....#.###.###.#.##...###.#.# |
|||
###.#....##.###.###.###.##.###..#######....#####..###.#..####...#...#.##.#...#.......#.....##.#.#### |
|||
#.##.#.#########...##..###..#.####...#.####.#...##.###.#......###.###.##.####..#.#.##.##.#..###..### |
|||
.##......##.##.....#####.....#.##..##.#.#.#.##.##..###..######.###.#.###..#...##.####...##..#..####. |
|||
....###.#####...##.####.#...#....##.#..#.###.#.###...##....#.##...###..##..........###..#.###.####.# |
|||
..#.###.#.#.#.#..##....#####..#..####.#######.#..#####.#.#.#####..####.##.#..#.#.###..##.####......# |
|||
#.#.##.....#..##....##.#.#.##....#....##..####.##..###....##.##.#..##.######..#...#...#.###...#...#. |
|||
##...##.#....#.####..######...#...#.###....###....#.####.#...#...####.##.#.#.##....######.###.###..# |
|||
#.###.#...##...##..###.#.##..#..#..##....####.#.##.#.####..##..#..#...#..##.#####.#..#.......##.##.# |
|||
..#...##.#.....#.##.###.........#.###....##..#........#....###.##.###.###.....#..####.##....#...#..# |
|||
#.###.#.#.#.....##.#.#...##.####.##....##.##..#...##..###.#####..###.#.#.#####.#.###...#####.....##. |
|||
.##..##..#.####.#####...###.#####..#..####..#..###.##..#....##.#...#.#..##.#.#.#....#....#...#..#..# |
|||
#.....#..#..#.#.#...#.##.#.###.#.##..##.#.#....#####...#.#..#.#...........#..##.....###.##.###.##..# |
|||
#.#..#..##..#..##..#..#.##.##..####....#####..###.#...##.##....#...##.##.#.#.##.##.#.##...#......### |
|||
..#...#..#.##.#.###..####..##....#....#.##.#.##.####.#.#.###..#.##..#..####..#..#..#..##.#.##..#..#. |
|||
.....##.##....####....##..##...##..###.##...#..##..#..#....#...###..#.....#.....#######.#..###.#.##. |
|||
#.#.#..###.#.#.##.#.#....#.#.##.###.##.#.##.#####..#.#.#..####..#...####..###.##...#.#####....#####. |
|||
##..#....####.#.#..#....#.##.#....##.#....#.#..##..#...#..#.#..#...#.#.#..###..####..#..#.#..#...#.. |
|||
.#....#.##..##.###.##..#....#...#..#.#.#..###..#......#...#####.#..#.......##..######...#.###.#..... |
|||
#.#...#...###.#####.#..#.....#...#...####..#.#.##..##...#......#....#.###.######......#.###.#.#.#### |
|||
.#####.#.#.##..##.##.#...##.#.##.#...###..#######..#..#.###....#....#.....#.#.#.#...#.#.....##.###.. |
|||
##........##...#.###.##....###...#..#...#.##..#######...####..#.#.#...###.###..####.##..#.#.####..## |
|||
#..#.#.########..##.....##.##...#.#.#.##.###.#...###.##.###..###.#.####....###....#..##.#....##..... |
|||
##########.##########.###.....#.....####..##.#.#.######.#.#....####.##.##...#...#..#.##.##...#.....# |
|||
.......##.####......##..#...#..#..##........####.#.#.#.#.##..##...###.##...##....#.##.####.####..... |
|||
#####.....#..#..##.######...#.....###.####.#.#####..#####.#.##..#.#.##.#..#.#..##.#..######.#..#..## |
|||
#....##.#.#.####..###.##.#.###.##..##....##..##..........###.#..######....#..#.##.#.####..##..##..## |
|||
...##.####.#..#..####.#....##..##..##.....#########..###..###.#.#..##.#.##..#...##.#..#.#.#.######## |
|||
#######..#..#.###....###....##..#####.#####.####.#######.###.#..#...#..#..##.#.####....#..#.#..##.#. |
|||
.##.#.#.#.#..#.####..#..##.#..#..##..#.##..#..#.##..#...#..#.###..#.#..##..##.#.....##...#....##.#.. |
|||
##.#.#.#.#.#.####.##..#.#..#.###.###..#..###...#..##.##.####..#.....####...#....###..####.##.#..#... |
|||
....##..###.##.###.#..####.#.##.##.##.##.#.#.####..#..##..#..#...####.#######...##..###.##.##..##.#. |
|||
...#####..##.###.#.#...#.##...####...##..###.#.#####....##.##....###.#..#.#..##....#.#####.##.#..### |
|||
.#.#.#..#..#..##.###.###..#.#..###....##..##.#.....#..#.#....#####......#####.#.##...#..#....##..#.# |
|||
...#.######..####..##.....#.#....#####.#...#....#.#.#.#...####.#.#.#.###.###...##..###.###.###.##... |
|||
#..####.#####.###.#....#####.#.###.###.##.###...##.##....####.#.##..#.#.#..#....#..#..#.#...######.. |
|||
.##..##..#####.#..###..#.##....##.#....##..##.#..##.#.###.....##..##.#...#..#.##.#.###.###.#......## |
|||
####.#.#..#######.###.#..#.###.#.#.#.##..#..#...#####.##....#.##.####.#..##...#.#....#....##..#..#.# |
|||
.......#.#.#...##.#...#.#.#..###....#..##..###..#.#.#.#.##.#....#....#..#..##......###.##.#..#...##. |
|||
#.##.###...#..#...#.#.##..####.......#.......###...######...##.#.....#..#............#.#.#....###..# |
|||
......#.#.#..####....##.###.##...###..#.#.###.#####..####.###.#.##..#....##.##....#.#.#.#.#.##..#.## |
|||
....#.#.......##..##..#.##...#...#.##...#.#.##.#.#...###..#####.###.#.##.....##..#..#.#.#.##...#.#.# |
|||
#..###..#.#.#.#..#.#....#.##..##.#..#..###..#.#.....###..#####.#######.#...#.####.#..#.#..#######..# |
|||
...#.#.##...#...###..#######..##.#.#.#.###.#.##.#.##..####..#..###..#.##.##.######.#####.####.#.#..# |
|||
.###.###.###.###..######.#.#..###..#.#.....#.#...##..##.#.###...##....#.##.##.###...#.#.#..##.#.#.## |
|||
##..#..#..#.###.##....####....##.#..#######.#..#.###..#.####.#####...#..#.##......#...#.###..#...##. |
|||
#.###..##.#.#....#.##..##.##.#.#.###.##..#......####.###....###..#.#.##...#.#.#.#.#..##....##...#.#. |
|||
...#.###..#..#.##.###.#...#..#..#.##.##....#.#.#.#..###...#.###..#..#..####...#....#..####..#...##.. |
|||
.......##..#...###.#.....#...###..##.###.##..#..#.#...#.###.#.#.###.#.......#####.##..##......#.##.# |
|||
.#.....#.###.#.#####..#.##.#.#.#.#.###..#.#..##.###..##.##..#....#.###....#....#..#..###..#..#.##.## |
|||
#####.#.##.###.##...#.##.##.#.#....#.##.#.#..#.#.##...##.########..#.#....#####.#######........#..#. |
|||
#...###..####.##.#.#####..##.###...###.##..#..##...##.....####...#.......#....#.#.###..#......#..##. |
|||
....##...####..##.###..###......###.#..#....####...###....#.#.#..#.#....#####.....##...#.......#.#.. |
|||
.....#.#.#.##..####.#...#...##.###..##.#.##.....###.##.##..#.##.##..#.#....#.##.####..##.#.####.##.. |
|||
.##..###...##.#.#..#.#.#..###...#...##.##.##.#.#....###..##...###...#..#.#.##..##..#..#..#.#.##..... |
|||
###..#......###.##..##.###...#.##.######.###..#...##.#....#..####..###...###.#.#######.#.####.#.##.. |
|||
#.#.#.#####.##...#..#.#...#......##.###..#.#...###......#..#..###..#..#.#.#####.#....##.#.###....##. |
|||
...##...##.#....#.##.#..####...#.##.##..#.######..#..#######.#...####.####....##.##.#.....#..####.## |
|||
#...##.#.#.....##..##.###..#.#..#.#.##.....#.#..#.#.#..#.....#.###.#.#.#.#...###..#..#.#.###..#.#.#. |
|||
..#.#..#.##.#.##.####.#.##.#..##.##.#...#.....##.#..##.#..##..#####.#......#.##....#...##..####.###. |
|||
#...###..#####...#...##.##......#.#......#..#.###...#....####.##.####......##..#..###...##.######.## |
@ -0,0 +1,7 @@ |
|||
..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..###..######.###...####..#..#####..##..#.#####...##.#.#..#.##..#.#......#.###.######.###.####...#.##.##..#..#..#####.....#.#....###..#.##......#.....#..#..#..##..#...##.######.####.####.#.#...#.......#..#.#.#...####.##.#......#..#...##.#.##..#...##.#.##..###.#......#.#.......#.#.#.####.###.##...#.....####.#..#..#.##.#....##..#.####....##...##..#...#......#.#.......#.......##..####..#...#.#.#...##..#.#..###..#####........#..####......#..# |
|||
|
|||
#..#. |
|||
#.... |
|||
##..# |
|||
..#.. |
|||
..### |
@ -0,0 +1,83 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys, re |
|||
|
|||
def memo(fc): |
|||
memo = {} |
|||
def f2(a,b,c,d,e,f,g): |
|||
if (a,b,c,d,e,f,g) not in memo: memo[(a,b,c,d,e,f,g)] = fc(a,b,c,d,e,f,g) |
|||
return memo[(a,b,c,d,e,f,g)] |
|||
return f2 |
|||
|
|||
def parse(line): |
|||
groups = re.compile(r"Player 1 starting position: (?P<p1>\d+)\nPlayer 2 starting position: (?P<p2>\d+)").search(line) |
|||
return groups |
|||
|
|||
def step(p1,p2): |
|||
d,s1,s2,die,dr = 0,0,0,0,0 |
|||
t = 1 |
|||
while s1 < 1000 and s2 < 1000: |
|||
mv = d*3 + 6 |
|||
d = d + 3 % 100 |
|||
dr += 3 |
|||
if t == 1: |
|||
p1 = (p1 + mv - 1) % 10 + 1 |
|||
s1 += p1 |
|||
if t == 2: |
|||
p2 = (p2 + mv - 1) % 10 + 1 |
|||
s2 += p2 |
|||
t = t%2+1 |
|||
return dr*s2 if s2 < 1000 else dr*s1 |
|||
|
|||
@memo |
|||
def qstep(p1,p2,s1,s2,dv,t,dt): |
|||
if s1 >= 21: |
|||
return {1:1,2:0} |
|||
elif s2 >= 21: |
|||
return {1:0,2:1} |
|||
wins = {1: 0, 2: 0} |
|||
if t == 1: |
|||
if dt == 3: |
|||
nt = t%2+1 |
|||
np1 = (p1 + dv - 1) % 10 + 1 |
|||
ns1 = s1+np1 |
|||
win = qstep(np1,p2,ns1,s2,0,nt,0) |
|||
wins[1] += win[1] |
|||
wins[2] += win[2] |
|||
else: |
|||
dt += 1 |
|||
for d in range(1,4): |
|||
ndv = dv+d |
|||
win = qstep(p1,p2,s1,s2,ndv,t,dt) |
|||
wins[1] += win[1] |
|||
wins[2] += win[2] |
|||
if t == 2: |
|||
if dt == 3: |
|||
nt = t%2+1 |
|||
np2 = (p2 + dv - 1) % 10 + 1 |
|||
ns2 = s2+np2 |
|||
win = qstep(p1,np2,s1,ns2,0,nt,0) |
|||
wins[1] += win[1] |
|||
wins[2] += win[2] |
|||
else: |
|||
dt += 1 |
|||
for d in range(1,4): |
|||
ndv = dv+d |
|||
win = qstep(p1,p2,s1,s2,ndv,t,dt) |
|||
wins[1] += win[1] |
|||
wins[2] += win[2] |
|||
return wins |
|||
|
|||
if __name__ == '__main__': |
|||
p1,p2 = map(int,parse(open(sys.argv[1]).read()).groups()) |
|||
|
|||
# challenge 1 |
|||
res1 = str(step(p1,p2)) |
|||
print("challenge 1:" + "\n" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
results = qstep(p1,p2,0,0,0,1,0) |
|||
|
|||
res2 = str(max(results.values())) |
|||
print("challenge 2:" + "\n" + res2 + "\n") |
|||
|
@ -0,0 +1,57 @@ |
|||
--- Day 21: Dirac Dice --- |
|||
|
|||
There's not much to do as you slowly descend to the bottom of the ocean. The submarine computer challenges you to a nice game of Dirac Dice. |
|||
|
|||
This game consists of a single die, two pawns, and a game board with a circular track containing ten spaces marked 1 through 10 clockwise. Each player's starting space is chosen randomly (your puzzle input). Player 1 goes first. |
|||
|
|||
Players take turns moving. On each player's turn, the player rolls the die three times and adds up the results. Then, the player moves their pawn that many times forward around the track (that is, moving clockwise on spaces in order of increasing value, wrapping back around to 1 after 10). So, if a player is on space 7 and they roll 2, 2, and 1, they would move forward 5 times, to spaces 8, 9, 10, 1, and finally stopping on 2. |
|||
|
|||
After each player moves, they increase their score by the value of the space their pawn stopped on. Players' scores start at 0. So, if the first player starts on space 7 and rolls a total of 5, they would stop on space 2 and add 2 to their score (for a total score of 2). The game immediately ends as a win for any player whose score reaches at least 1000. |
|||
|
|||
Since the first game is a practice game, the submarine opens a compartment labeled deterministic dice and a 100-sided die falls out. This die always rolls 1 first, then 2, then 3, and so on up to 100, after which it starts over at 1 again. Play using this die. |
|||
|
|||
For example, given these starting positions: |
|||
|
|||
Player 1 starting position: 4 |
|||
Player 2 starting position: 8 |
|||
|
|||
This is how the game would go: |
|||
|
|||
Player 1 rolls 1+2+3 and moves to space 10 for a total score of 10. |
|||
Player 2 rolls 4+5+6 and moves to space 3 for a total score of 3. |
|||
Player 1 rolls 7+8+9 and moves to space 4 for a total score of 14. |
|||
Player 2 rolls 10+11+12 and moves to space 6 for a total score of 9. |
|||
Player 1 rolls 13+14+15 and moves to space 6 for a total score of 20. |
|||
Player 2 rolls 16+17+18 and moves to space 7 for a total score of 16. |
|||
Player 1 rolls 19+20+21 and moves to space 6 for a total score of 26. |
|||
Player 2 rolls 22+23+24 and moves to space 6 for a total score of 22. |
|||
|
|||
...after many turns... |
|||
|
|||
Player 2 rolls 82+83+84 and moves to space 6 for a total score of 742. |
|||
Player 1 rolls 85+86+87 and moves to space 4 for a total score of 990. |
|||
Player 2 rolls 88+89+90 and moves to space 3 for a total score of 745. |
|||
Player 1 rolls 91+92+93 and moves to space 10 for a final score, 1000. |
|||
|
|||
Since player 1 has at least 1000 points, player 1 wins and the game ends. At this point, the losing player had 745 points and the die had been rolled a total of 993 times; 745 * 993 = 739785. |
|||
|
|||
Play a practice game using the deterministic 100-sided die. The moment either player wins, what do you get if you multiply the score of the losing player by the number of times the die was rolled during the game? |
|||
|
|||
Your puzzle answer was 913560. |
|||
--- Part Two --- |
|||
|
|||
Now that you're warmed up, it's time to play the real game. |
|||
|
|||
A second compartment opens, this time labeled Dirac dice. Out of it falls a single three-sided die. |
|||
|
|||
As you experiment with the die, you feel a little strange. An informational brochure in the compartment explains that this is a quantum die: when you roll it, the universe splits into multiple copies, one copy for each possible outcome of the die. In this case, rolling the die always splits the universe into three copies: one where the outcome of the roll was 1, one where it was 2, and one where it was 3. |
|||
|
|||
The game is played the same as before, although to prevent things from getting too far out of hand, the game now ends when either player's score reaches at least 21. |
|||
|
|||
Using the same starting positions as in the example above, player 1 wins in 444356092776315 universes, while player 2 merely wins in 341960390180808 universes. |
|||
|
|||
Using your given starting positions, determine every possible outcome. Find the player that wins in more universes; in how many universes does that player win? |
|||
|
|||
Your puzzle answer was 110271560863819. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
@ -0,0 +1,2 @@ |
|||
Player 1 starting position: 4 |
|||
Player 2 starting position: 1 |
@ -0,0 +1,2 @@ |
|||
Player 1 starting position: 4 |
|||
Player 2 starting position: 8 |
@ -0,0 +1,91 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys,re |
|||
from collections import Counter |
|||
|
|||
def parse(l): |
|||
return re.compile(r"(?P<mode>\w+) x=(?P<x1>-?\d+)..(?P<x2>-?\d+),y=(?P<y1>-?\d+)..(?P<y2>-?\d+),z=(?P<z1>-?\d+)..(?P<z2>-?\d+)").search(l) |
|||
|
|||
def volume(k): |
|||
if k[1]-k[0] < 0 or k[3]-k[2] < 0 or k[5]-k[4] < 0: return 0 |
|||
return (k[1]-k[0]+1)*(k[3]-k[2]+1)*(k[5]-k[4]+1) |
|||
|
|||
def count_cubes(c): |
|||
o = 0 |
|||
for k,v in c.items(): |
|||
if v == 'on': |
|||
o += volume(k) |
|||
return o |
|||
|
|||
def intersect(c1,c2): |
|||
x1,x2,y1,y2,z1,z2 = c1 |
|||
lx,hx,ly,hy,lz,hz = c2 |
|||
xos = max(lx,x1) |
|||
xoe = min(hx,x2) |
|||
yos = max(ly,y1) |
|||
yoe = min(hy,y2) |
|||
zos = max(lz,z1) |
|||
zoe = min(hz,z2) |
|||
return volume((xos,xoe,yos,yoe,zos,zoe)) > 0 |
|||
#return (c1[0] in range(c2[0],c2[1]+1) or c1[1] in range(c2[0],c2[1]+1)) and (c1[2] in range(c2[2],c2[3]+1) or c1[3] in range(c2[2],c2[3]+1)) and (c1[4] in range(c2[4],c2[5]+1) or c1[5] in range(c2[4],c2[5]+1)) |
|||
|
|||
def split(c1,c2): |
|||
x1,x2,y1,y2,z1,z2 = c1 |
|||
lx,hx,ly,hy,lz,hz = c2 |
|||
xos = max(lx,x1) |
|||
xoe = min(hx,x2) |
|||
yos = max(ly,y1) |
|||
yoe = min(hy,y2) |
|||
zos = max(lz,z1) |
|||
zoe = min(hz,z2) |
|||
v = 0 |
|||
for x in [(lx,xos-1),(xos,xoe),(xoe+1,hx)]: |
|||
for y in [(ly,yos-1),(yos,yoe),(yoe+1,hy)]: |
|||
for z in [(lz,zos-1),(zos,zoe),(zoe+1,hz)]: |
|||
v += volume((*x,*y,*z)) |
|||
if volume((*x,*y,*z)) > 0 and (x,y,z) != ((xos,xoe),(yos,yoe),(zos,zoe)): |
|||
yield (*x,*y,*z) |
|||
|
|||
def init(steps): |
|||
cubes = {} |
|||
for m,x1,x2,y1,y2,z1,z2 in steps: |
|||
if not (-50 <= x1 <= 50 and -50 <= x2 <= 50): continue |
|||
for x in range(x1,x2+1): |
|||
if not (-50 <= y1 <= 50 and -50 <= y2 <= 50): continue |
|||
for y in range(y1,y2+1): |
|||
if not (-50 <= z1 <= 50 and -50 <= z2 <= 50): continue |
|||
for z in range(z1,z2+1): |
|||
cubes[(x,y,z)] = m |
|||
return cubes |
|||
|
|||
def reboot(steps): |
|||
cubes = {} |
|||
for c1 in steps: |
|||
m,c1 = c1[0],c1[1:] |
|||
atm = [k for k in cubes.keys()] |
|||
for c2 in atm: |
|||
om = cubes[c2] |
|||
if intersect(c1,c2) or intersect(c2,c1): |
|||
for c in split(c1,c2): |
|||
if not (intersect(c,c1) or intersect(c1,c)): |
|||
cubes[c] = om |
|||
cubes.pop(c2) |
|||
cubes[c1] = m |
|||
return cubes |
|||
|
|||
if __name__ == '__main__': |
|||
nums = map(lambda x: (x[0],int(x[1]),int(x[2]),int(x[3]),int(x[4]),int(x[5]),int(x[6])),[parse(l).groups() for l in open(sys.argv[1])]) |
|||
nums = [n for n in nums] |
|||
|
|||
# challenge 1 |
|||
cubes1 = init(nums) |
|||
c = Counter([v for k,v in cubes1.items() if -50 <= k[0] <= 50 and -50 <= k[1] <= 50 and -50 <= k[2] <= 50]) |
|||
res1 = str(c.most_common(2)) |
|||
|
|||
print("challenge 1:" + "\n" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
cubes2 = reboot(nums) |
|||
res2 = str(count_cubes(cubes2)) |
|||
print("challenge 2:" + "\n" + res2 + "\n") |
|||
|
@ -0,0 +1,188 @@ |
|||
--- Day 22: Reactor Reboot --- |
|||
|
|||
Operating at these extreme ocean depths has overloaded the submarine's reactor; it needs to be rebooted. |
|||
|
|||
The reactor core is made up of a large 3-dimensional grid made up entirely of cubes, one cube per integer 3-dimensional coordinate (x,y,z). Each cube can be either on or off; at the start of the reboot process, they are all off. (Could it be an old model of a reactor you've seen before?) |
|||
|
|||
To reboot the reactor, you just need to set all of the cubes to either on or off by following a list of reboot steps (your puzzle input). Each step specifies a cuboid (the set of all cubes that have coordinates which fall within ranges for x, y, and z) and whether to turn all of the cubes in that cuboid on or off. |
|||
|
|||
For example, given these reboot steps: |
|||
|
|||
on x=10..12,y=10..12,z=10..12 |
|||
on x=11..13,y=11..13,z=11..13 |
|||
off x=9..11,y=9..11,z=9..11 |
|||
on x=10..10,y=10..10,z=10..10 |
|||
|
|||
The first step (on x=10..12,y=10..12,z=10..12) turns on a 3x3x3 cuboid consisting of 27 cubes: |
|||
|
|||
10,10,10 |
|||
10,10,11 |
|||
10,10,12 |
|||
10,11,10 |
|||
10,11,11 |
|||
10,11,12 |
|||
10,12,10 |
|||
10,12,11 |
|||
10,12,12 |
|||
11,10,10 |
|||
11,10,11 |
|||
11,10,12 |
|||
11,11,10 |
|||
11,11,11 |
|||
11,11,12 |
|||
11,12,10 |
|||
11,12,11 |
|||
11,12,12 |
|||
12,10,10 |
|||
12,10,11 |
|||
12,10,12 |
|||
12,11,10 |
|||
12,11,11 |
|||
12,11,12 |
|||
12,12,10 |
|||
12,12,11 |
|||
12,12,12 |
|||
|
|||
The second step (on x=11..13,y=11..13,z=11..13) turns on a 3x3x3 cuboid that overlaps with the first. As a result, only 19 additional cubes turn on; the rest are already on from the previous step: |
|||
|
|||
11,11,13 |
|||
11,12,13 |
|||
11,13,11 |
|||
11,13,12 |
|||
11,13,13 |
|||
12,11,13 |
|||
12,12,13 |
|||
12,13,11 |
|||
12,13,12 |
|||
12,13,13 |
|||
13,11,11 |
|||
13,11,12 |
|||
13,11,13 |
|||
13,12,11 |
|||
13,12,12 |
|||
13,12,13 |
|||
13,13,11 |
|||
13,13,12 |
|||
13,13,13 |
|||
|
|||
The third step (off x=9..11,y=9..11,z=9..11) turns off a 3x3x3 cuboid that overlaps partially with some cubes that are on, ultimately turning off 8 cubes: |
|||
|
|||
10,10,10 |
|||
10,10,11 |
|||
10,11,10 |
|||
10,11,11 |
|||
11,10,10 |
|||
11,10,11 |
|||
11,11,10 |
|||
11,11,11 |
|||
|
|||
The final step (on x=10..10,y=10..10,z=10..10) turns on a single cube, 10,10,10. After this last step, 39 cubes are on. |
|||
|
|||
The initialization procedure only uses cubes that have x, y, and z positions of at least -50 and at most 50. For now, ignore cubes outside this region. |
|||
|
|||
Here is a larger example: |
|||
|
|||
on x=-20..26,y=-36..17,z=-47..7 |
|||
on x=-20..33,y=-21..23,z=-26..28 |
|||
on x=-22..28,y=-29..23,z=-38..16 |
|||
on x=-46..7,y=-6..46,z=-50..-1 |
|||
on x=-49..1,y=-3..46,z=-24..28 |
|||
on x=2..47,y=-22..22,z=-23..27 |
|||
on x=-27..23,y=-28..26,z=-21..29 |
|||
on x=-39..5,y=-6..47,z=-3..44 |
|||
on x=-30..21,y=-8..43,z=-13..34 |
|||
on x=-22..26,y=-27..20,z=-29..19 |
|||
off x=-48..-32,y=26..41,z=-47..-37 |
|||
on x=-12..35,y=6..50,z=-50..-2 |
|||
off x=-48..-32,y=-32..-16,z=-15..-5 |
|||
on x=-18..26,y=-33..15,z=-7..46 |
|||
off x=-40..-22,y=-38..-28,z=23..41 |
|||
on x=-16..35,y=-41..10,z=-47..6 |
|||
off x=-32..-23,y=11..30,z=-14..3 |
|||
on x=-49..-5,y=-3..45,z=-29..18 |
|||
off x=18..30,y=-20..-8,z=-3..13 |
|||
on x=-41..9,y=-7..43,z=-33..15 |
|||
on x=-54112..-39298,y=-85059..-49293,z=-27449..7877 |
|||
on x=967..23432,y=45373..81175,z=27513..53682 |
|||
|
|||
The last two steps are fully outside the initialization procedure area; all other steps are fully within it. After executing these steps in the initialization procedure region, 590784 cubes are on. |
|||
|
|||
Execute the reboot steps. Afterward, considering only cubes in the region x=-50..50,y=-50..50,z=-50..50, how many cubes are on? |
|||
|
|||
Your puzzle answer was 580810. |
|||
--- Part Two --- |
|||
|
|||
Now that the initialization procedure is complete, you can reboot the reactor. |
|||
|
|||
Starting with all cubes off, run all of the reboot steps for all cubes in the reactor. |
|||
|
|||
Consider the following reboot steps: |
|||
|
|||
on x=-5..47,y=-31..22,z=-19..33 |
|||
on x=-44..5,y=-27..21,z=-14..35 |
|||
on x=-49..-1,y=-11..42,z=-10..38 |
|||
on x=-20..34,y=-40..6,z=-44..1 |
|||
off x=26..39,y=40..50,z=-2..11 |
|||
on x=-41..5,y=-41..6,z=-36..8 |
|||
off x=-43..-33,y=-45..-28,z=7..25 |
|||
on x=-33..15,y=-32..19,z=-34..11 |
|||
off x=35..47,y=-46..-34,z=-11..5 |
|||
on x=-14..36,y=-6..44,z=-16..29 |
|||
on x=-57795..-6158,y=29564..72030,z=20435..90618 |
|||
on x=36731..105352,y=-21140..28532,z=16094..90401 |
|||
on x=30999..107136,y=-53464..15513,z=8553..71215 |
|||
on x=13528..83982,y=-99403..-27377,z=-24141..23996 |
|||
on x=-72682..-12347,y=18159..111354,z=7391..80950 |
|||
on x=-1060..80757,y=-65301..-20884,z=-103788..-16709 |
|||
on x=-83015..-9461,y=-72160..-8347,z=-81239..-26856 |
|||
on x=-52752..22273,y=-49450..9096,z=54442..119054 |
|||
on x=-29982..40483,y=-108474..-28371,z=-24328..38471 |
|||
on x=-4958..62750,y=40422..118853,z=-7672..65583 |
|||
on x=55694..108686,y=-43367..46958,z=-26781..48729 |
|||
on x=-98497..-18186,y=-63569..3412,z=1232..88485 |
|||
on x=-726..56291,y=-62629..13224,z=18033..85226 |
|||
on x=-110886..-34664,y=-81338..-8658,z=8914..63723 |
|||
on x=-55829..24974,y=-16897..54165,z=-121762..-28058 |
|||
on x=-65152..-11147,y=22489..91432,z=-58782..1780 |
|||
on x=-120100..-32970,y=-46592..27473,z=-11695..61039 |
|||
on x=-18631..37533,y=-124565..-50804,z=-35667..28308 |
|||
on x=-57817..18248,y=49321..117703,z=5745..55881 |
|||
on x=14781..98692,y=-1341..70827,z=15753..70151 |
|||
on x=-34419..55919,y=-19626..40991,z=39015..114138 |
|||
on x=-60785..11593,y=-56135..2999,z=-95368..-26915 |
|||
on x=-32178..58085,y=17647..101866,z=-91405..-8878 |
|||
on x=-53655..12091,y=50097..105568,z=-75335..-4862 |
|||
on x=-111166..-40997,y=-71714..2688,z=5609..50954 |
|||
on x=-16602..70118,y=-98693..-44401,z=5197..76897 |
|||
on x=16383..101554,y=4615..83635,z=-44907..18747 |
|||
off x=-95822..-15171,y=-19987..48940,z=10804..104439 |
|||
on x=-89813..-14614,y=16069..88491,z=-3297..45228 |
|||
on x=41075..99376,y=-20427..49978,z=-52012..13762 |
|||
on x=-21330..50085,y=-17944..62733,z=-112280..-30197 |
|||
on x=-16478..35915,y=36008..118594,z=-7885..47086 |
|||
off x=-98156..-27851,y=-49952..43171,z=-99005..-8456 |
|||
off x=2032..69770,y=-71013..4824,z=7471..94418 |
|||
on x=43670..120875,y=-42068..12382,z=-24787..38892 |
|||
off x=37514..111226,y=-45862..25743,z=-16714..54663 |
|||
off x=25699..97951,y=-30668..59918,z=-15349..69697 |
|||
off x=-44271..17935,y=-9516..60759,z=49131..112598 |
|||
on x=-61695..-5813,y=40978..94975,z=8655..80240 |
|||
off x=-101086..-9439,y=-7088..67543,z=33935..83858 |
|||
off x=18020..114017,y=-48931..32606,z=21474..89843 |
|||
off x=-77139..10506,y=-89994..-18797,z=-80..59318 |
|||
off x=8476..79288,y=-75520..11602,z=-96624..-24783 |
|||
on x=-47488..-1262,y=24338..100707,z=16292..72967 |
|||
off x=-84341..13987,y=2429..92914,z=-90671..-1318 |
|||
off x=-37810..49457,y=-71013..-7894,z=-105357..-13188 |
|||
off x=-27365..46395,y=31009..98017,z=15428..76570 |
|||
off x=-70369..-16548,y=22648..78696,z=-1892..86821 |
|||
on x=-53470..21291,y=-120233..-33476,z=-44150..38147 |
|||
off x=-93533..-4276,y=-16170..68771,z=-104985..-24507 |
|||
|
|||
After running the above reboot steps, 2758514936282235 cubes are on. (Just for fun, 474140 of those are also in the initialization procedure region.) |
|||
|
|||
Starting again with all cubes off, execute all reboot steps. Afterward, considering all cubes, how many cubes are on? |
|||
|
|||
Your puzzle answer was 1265621119006734. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
@ -0,0 +1,420 @@ |
|||
on x=-22..28,y=-12..37,z=-34..11 |
|||
on x=-35..15,y=-10..40,z=-48..-2 |
|||
on x=-31..19,y=-4..43,z=-22..28 |
|||
on x=-48..-2,y=-36..13,z=-29..20 |
|||
on x=0..49,y=-14..30,z=-39..6 |
|||
on x=-8..41,y=-9..41,z=-42..7 |
|||
on x=-22..25,y=-16..28,z=-40..9 |
|||
on x=-11..33,y=-22..26,z=0..44 |
|||
on x=-13..39,y=-26..19,z=-31..15 |
|||
on x=-7..47,y=-1..44,z=-40..13 |
|||
off x=-47..-31,y=12..24,z=4..19 |
|||
on x=-23..30,y=-22..27,z=-9..35 |
|||
off x=-49..-33,y=36..46,z=28..42 |
|||
on x=0..48,y=-41..7,z=-18..31 |
|||
off x=-48..-34,y=-33..-18,z=-32..-23 |
|||
on x=-16..29,y=0..48,z=-12..37 |
|||
off x=-48..-32,y=-47..-31,z=-24..-8 |
|||
on x=-35..18,y=-11..42,z=-23..21 |
|||
off x=-5..5,y=-47..-31,z=-18..-4 |
|||
on x=-41..10,y=-39..8,z=-45..5 |
|||
on x=57743..70226,y=-61040..-49730,z=-9481..1779 |
|||
on x=34469..59935,y=-19657..-15459,z=52982..68107 |
|||
on x=2032..20175,y=43518..62126,z=58508..71090 |
|||
on x=31229..48351,y=22846..46374,z=58775..63336 |
|||
on x=50790..81085,y=-43836..-24658,z=16376..45716 |
|||
on x=28957..62666,y=-63812..-43726,z=-21518..-20032 |
|||
on x=-79145..-53125,y=-58835..-40328,z=-34032..-1191 |
|||
on x=-39963..-30908,y=61052..76815,z=-14209..4001 |
|||
on x=30995..46213,y=-188..23074,z=48848..73955 |
|||
on x=-30327..817,y=-92891..-71382,z=-556..15570 |
|||
on x=-66084..-49749,y=-70089..-44721,z=543..18051 |
|||
on x=-10435..875,y=1868..22100,z=-90712..-72390 |
|||
on x=-6457..23401,y=39789..59388,z=-64029..-59562 |
|||
on x=-48891..-19571,y=-60094..-41210,z=-63314..-59729 |
|||
on x=-84053..-64052,y=2084..16189,z=-31207..-1454 |
|||
on x=-52377..-25969,y=-90697..-66004,z=-17839..-5215 |
|||
on x=-7876..16576,y=25156..48291,z=-78019..-63073 |
|||
on x=-70710..-54783,y=28572..57892,z=2846..14577 |
|||
on x=69353..93836,y=-32370..-11069,z=-15941..8778 |
|||
on x=-92783..-71784,y=-17812..17198,z=2761..27075 |
|||
on x=45799..59502,y=-51290..-23552,z=35610..57193 |
|||
on x=-50227..-17040,y=46996..74417,z=28330..44175 |
|||
on x=8914..26079,y=-50911..-30028,z=-67490..-43942 |
|||
on x=-10960..6571,y=-75351..-66572,z=21851..44569 |
|||
on x=22699..44190,y=-83751..-52386,z=20341..36226 |
|||
on x=58542..77668,y=47268..63235,z=-3866..26621 |
|||
on x=73780..79320,y=-13674..519,z=-25349..-12369 |
|||
on x=61440..79923,y=7960..26241,z=-27706..-15327 |
|||
on x=38043..50418,y=44221..51183,z=-65245..-45723 |
|||
on x=22702..31491,y=-17144..312,z=-85339..-53805 |
|||
on x=21638..55787,y=44959..61008,z=-47808..-39438 |
|||
on x=-63113..-41252,y=-67744..-41914,z=-26758..-4882 |
|||
on x=63367..92148,y=30084..48195,z=-5852..-3181 |
|||
on x=11847..30590,y=66766..73165,z=19550..26333 |
|||
on x=-82252..-43217,y=16642..33032,z=31779..53160 |
|||
on x=376..8916,y=-85149..-77287,z=-3825..28320 |
|||
on x=-11778..4687,y=-65208..-43505,z=-56839..-41330 |
|||
on x=-59599..-26799,y=-43262..-22054,z=53184..68929 |
|||
on x=27880..45230,y=31092..48118,z=53472..65470 |
|||
on x=66503..87392,y=14887..44613,z=5640..29076 |
|||
on x=-18992..15785,y=70329..84705,z=-11543..3900 |
|||
on x=26450..55691,y=33724..51544,z=-67288..-47510 |
|||
on x=-55101..-20607,y=-54336..-50167,z=-63808..-39985 |
|||
on x=-58662..-44430,y=23514..35998,z=-57391..-35888 |
|||
on x=-30686..-14789,y=52951..78131,z=23020..30026 |
|||
on x=59723..89386,y=-1973..20344,z=-23466..16370 |
|||
on x=-28704..-19628,y=-26635..-10672,z=67912..92984 |
|||
on x=34109..52603,y=6207..33762,z=-78531..-54945 |
|||
on x=6969..35234,y=12510..46591,z=-88613..-51919 |
|||
on x=-16819..13310,y=-78286..-72895,z=-40672..-15821 |
|||
on x=12715..44649,y=59413..85803,z=12932..25405 |
|||
on x=39882..72763,y=-29701..-24955,z=30035..53183 |
|||
on x=61861..91147,y=-22736..-7422,z=4820..7751 |
|||
on x=25793..39413,y=46741..82626,z=5326..33146 |
|||
on x=-6107..19053,y=68420..92110,z=-36318..-16459 |
|||
on x=28551..40390,y=68467..76382,z=-16632..-2714 |
|||
on x=-45969..-23239,y=-62699..-36719,z=38811..56336 |
|||
on x=-76366..-72346,y=21237..38131,z=-10669..22165 |
|||
on x=44705..59494,y=6680..11337,z=49501..61061 |
|||
on x=2597..24468,y=14065..37612,z=61022..74073 |
|||
on x=35904..59720,y=-8301..13166,z=59515..64632 |
|||
on x=-19466..2821,y=54015..73358,z=37279..67387 |
|||
on x=22671..24877,y=-78893..-54761,z=30577..49365 |
|||
on x=-61910..-30004,y=-48658..-30216,z=-63277..-39443 |
|||
on x=31804..62778,y=-10031..4607,z=53321..66647 |
|||
on x=35353..59793,y=-64800..-45779,z=-45954..-25389 |
|||
on x=-54351..-23056,y=-85690..-64612,z=-11671..9856 |
|||
on x=46643..60469,y=-72975..-45242,z=-27257..-9772 |
|||
on x=-1587..22614,y=42774..64311,z=-75051..-55436 |
|||
on x=43500..63874,y=57617..69803,z=-9587..20014 |
|||
on x=-84644..-71132,y=20240..38502,z=20664..34375 |
|||
on x=40993..55870,y=-67190..-52687,z=-33480..-19778 |
|||
on x=-47052..-17260,y=-89061..-56609,z=-1611..29297 |
|||
on x=25170..40430,y=-74511..-62273,z=-42240..-11723 |
|||
on x=20724..48041,y=-49570..-30648,z=-65320..-52402 |
|||
on x=18971..41779,y=-74384..-55955,z=21290..42401 |
|||
on x=12372..25040,y=-19897..8311,z=-92628..-74366 |
|||
on x=-41481..-9209,y=-30115..-3165,z=61616..78046 |
|||
on x=-60608..-23394,y=-77847..-59531,z=23434..37967 |
|||
on x=-71858..-50069,y=-57588..-41250,z=-50072..-33315 |
|||
on x=37501..71584,y=31996..53811,z=27365..52251 |
|||
on x=-56165..-38552,y=44724..61002,z=23249..44903 |
|||
on x=33227..40766,y=61266..72042,z=-40028..-30190 |
|||
on x=-11144..9046,y=20660..52650,z=61730..86031 |
|||
on x=21865..39875,y=46084..72027,z=-41788..-32094 |
|||
on x=-30545..-4677,y=44278..74009,z=-59990..-47040 |
|||
on x=-48012..-35017,y=-70818..-58672,z=16398..44578 |
|||
on x=-60425..-50019,y=-59529..-42076,z=-36601..-4347 |
|||
on x=-5505..16222,y=77230..83177,z=-12302..11122 |
|||
on x=18568..47510,y=62799..88600,z=-6696..22060 |
|||
on x=34553..42144,y=67458..85473,z=-20865..3279 |
|||
on x=-70604..-50638,y=-37855..-14331,z=-37538..-26619 |
|||
on x=-18955..-3382,y=-15846..1586,z=65846..86641 |
|||
on x=-36618..-11388,y=-38199..-8026,z=-84356..-55275 |
|||
on x=14279..42431,y=39293..56427,z=50099..77725 |
|||
on x=28773..43843,y=51502..73850,z=4898..32973 |
|||
on x=-78414..-50811,y=-51353..-20494,z=170..25282 |
|||
on x=-2690..8500,y=42310..58100,z=45997..59275 |
|||
on x=-51673..-35241,y=-69072..-48834,z=23583..43079 |
|||
on x=-17870..16848,y=-3928..15129,z=-84692..-79036 |
|||
on x=-87341..-71032,y=-20078..212,z=1818..30236 |
|||
on x=71091..85417,y=-5563..16629,z=22831..30523 |
|||
on x=28443..44534,y=53772..78417,z=-11050..19315 |
|||
on x=-58440..-40362,y=-36161..-21536,z=51262..64247 |
|||
on x=-43628..-14975,y=21749..39527,z=-87409..-62207 |
|||
on x=-83544..-75074,y=-33970..-17359,z=-13538..9135 |
|||
on x=18355..46439,y=17596..51653,z=49322..73971 |
|||
on x=-10768..10856,y=-209..18736,z=-79866..-77867 |
|||
on x=-64915..-38455,y=-33420..-19423,z=-57336..-36896 |
|||
on x=-59594..-49691,y=39386..53637,z=-61118..-42358 |
|||
on x=22547..44540,y=41783..75825,z=-53800..-26170 |
|||
on x=52927..63056,y=-20945..13569,z=50274..69604 |
|||
on x=29639..47649,y=51463..74979,z=29464..61363 |
|||
on x=-62445..-46494,y=39646..59555,z=-47592..-26239 |
|||
on x=-30926..-7219,y=-76422..-53700,z=19664..37575 |
|||
on x=8068..25595,y=-15448..15190,z=-95311..-75741 |
|||
on x=-2315..14899,y=-94702..-78498,z=6767..13841 |
|||
on x=52658..77574,y=-1925..7965,z=37088..62731 |
|||
on x=-71749..-51034,y=-41036..-23998,z=-25383..-2310 |
|||
on x=-72935..-52021,y=4145..31708,z=28168..44264 |
|||
on x=-38524..-29058,y=54203..87398,z=-4270..8719 |
|||
on x=-18458..-547,y=-41938..-28075,z=55353..85466 |
|||
on x=63334..86680,y=-8977..5737,z=3089..23619 |
|||
on x=-76522..-51279,y=51711..63609,z=-1119..11074 |
|||
on x=43978..67672,y=-46119..-36350,z=-54348..-32116 |
|||
on x=-61977..-39979,y=48805..66908,z=-4087..15443 |
|||
on x=-38393..-15142,y=34482..45895,z=51707..73387 |
|||
on x=-15098..5245,y=64504..86193,z=11660..42572 |
|||
on x=20462..32546,y=67335..88945,z=-23808..-12174 |
|||
on x=-45710..-29866,y=-48713..-40225,z=36191..72881 |
|||
on x=-80647..-72347,y=6003..19378,z=6018..26968 |
|||
on x=-30135..-907,y=-40352..-17385,z=-74550..-69713 |
|||
on x=25651..40752,y=25704..44767,z=-69419..-53995 |
|||
on x=-65351..-49165,y=-665..33203,z=-58077..-53439 |
|||
on x=27847..41886,y=-57196..-51432,z=-60041..-31392 |
|||
on x=-74571..-65726,y=18936..34595,z=-14994..8307 |
|||
on x=3420..18201,y=59080..63744,z=-50796..-37402 |
|||
on x=-59725..-52919,y=25233..56324,z=36770..52550 |
|||
on x=25084..37742,y=-22473..13416,z=61111..89517 |
|||
on x=-31123..-9929,y=-38982..-28408,z=-76197..-54610 |
|||
on x=26239..39855,y=-67171..-50065,z=34490..46827 |
|||
on x=-31113..-2705,y=59178..87794,z=8623..21865 |
|||
on x=64246..81862,y=13839..27162,z=-37512..803 |
|||
on x=-38914..-20811,y=-35350..-18517,z=62773..89363 |
|||
on x=-79546..-58914,y=39361..40589,z=-23746..-1521 |
|||
on x=-92264..-60845,y=-16477..-4211,z=-34296..-15581 |
|||
on x=-81598..-55814,y=-8529..14390,z=-50600..-33531 |
|||
on x=50748..66514,y=56968..76774,z=-9752..13820 |
|||
on x=-80025..-55789,y=-41134..-19361,z=28348..54979 |
|||
on x=-28896..-19805,y=-68202..-37931,z=49748..61021 |
|||
on x=57234..73263,y=-37712..-1405,z=13150..46160 |
|||
on x=7376..29616,y=-8620..20535,z=-83248..-62090 |
|||
on x=44553..56109,y=32850..57714,z=25785..52790 |
|||
on x=-7717..25102,y=-7725..12431,z=59010..93276 |
|||
on x=-3663..20480,y=31992..48881,z=-80967..-61519 |
|||
on x=-54684..-38284,y=33082..51001,z=-47536..-31488 |
|||
on x=-24421..-10049,y=-73142..-50307,z=-47158..-25659 |
|||
on x=41005..51559,y=54743..68960,z=-32157..-19293 |
|||
on x=-8763..26625,y=66264..86593,z=-57863..-26158 |
|||
on x=39695..57854,y=-10327..960,z=-81724..-65077 |
|||
on x=41233..63655,y=-37542..-11744,z=-67651..-49824 |
|||
on x=-18469..-14312,y=36071..63118,z=56475..75090 |
|||
on x=-28731..-15639,y=-72916..-60994,z=17355..48092 |
|||
on x=-29016..-17872,y=1691..28301,z=-80313..-74087 |
|||
on x=-24861..-2063,y=-29881..-11428,z=-74927..-54438 |
|||
on x=-2908..8218,y=68593..71825,z=-42304..-36475 |
|||
on x=27546..51021,y=4696..22461,z=56219..85387 |
|||
on x=39005..55338,y=48826..72635,z=-24709..-1 |
|||
on x=47727..73855,y=-63059..-41116,z=-9038..23091 |
|||
on x=-19884..6774,y=-33156..-8931,z=72725..87601 |
|||
on x=-72461..-53556,y=-27699..-14981,z=19211..41822 |
|||
on x=63249..81403,y=-40188..-14765,z=6931..37685 |
|||
on x=63142..82981,y=-25106..-3270,z=20101..29453 |
|||
on x=31130..58947,y=3173..21337,z=-74916..-68397 |
|||
on x=-58714..-42813,y=11593..34345,z=34118..58810 |
|||
on x=-49518..-27875,y=-29607..-21358,z=-75178..-53370 |
|||
on x=69461..77175,y=15448..36416,z=-34182..-22402 |
|||
on x=35551..54657,y=-69428..-42048,z=-17045..6812 |
|||
on x=27635..38793,y=45411..69203,z=-50135..-43361 |
|||
on x=16688..38446,y=-61396..-37075,z=-64966..-31030 |
|||
on x=-35814..-19493,y=63372..81491,z=27500..54462 |
|||
on x=10356..30411,y=-74284..-55629,z=39846..45049 |
|||
on x=-38328..-4710,y=64415..79565,z=-43116..-22145 |
|||
on x=-29835..-5671,y=-90310..-76428,z=277..1869 |
|||
on x=48292..76832,y=37381..49402,z=34886..43306 |
|||
on x=19066..33779,y=-3597..8757,z=-76149..-71976 |
|||
on x=-26733..-12570,y=-35681..-26828,z=62655..71618 |
|||
on x=50628..68591,y=-51527..-24729,z=25316..59839 |
|||
on x=59379..62742,y=-57334..-46510,z=3134..10600 |
|||
on x=55393..77648,y=4221..37143,z=44784..65699 |
|||
on x=-15390..-5126,y=-3381..11074,z=73410..86424 |
|||
on x=-26889..-7086,y=-77791..-41328,z=-66410..-29235 |
|||
on x=-43347..-21552,y=57590..64785,z=28677..49316 |
|||
on x=-67247..-37242,y=-28533..-8487,z=-69945..-48320 |
|||
on x=-2207..27139,y=71426..90772,z=11875..24958 |
|||
on x=-7365..22762,y=-96133..-73290,z=-30621..-6784 |
|||
on x=44813..66334,y=-20573..-2018,z=-64230..-53722 |
|||
on x=51196..58944,y=-60144..-41259,z=18880..45821 |
|||
on x=-60386..-32399,y=-36568..-12315,z=40586..67416 |
|||
on x=-665..20331,y=-17403..-11184,z=-87940..-72839 |
|||
off x=32946..48821,y=-28974..-15614,z=64401..84617 |
|||
on x=-55785..-28569,y=65269..75512,z=-21176..-6442 |
|||
off x=32390..46916,y=-82938..-68118,z=-13863..21900 |
|||
off x=53888..71942,y=-46568..-32979,z=-34248..-19326 |
|||
off x=-81837..-78163,y=-5392..9087,z=-2450..18903 |
|||
off x=21995..44453,y=-40185..-33499,z=62135..76283 |
|||
on x=10308..40463,y=59540..77174,z=-61333..-36739 |
|||
off x=-94177..-61603,y=-22758..11823,z=-38788..-12954 |
|||
on x=53438..75655,y=25126..43060,z=-14518..7932 |
|||
on x=-19531..3177,y=4045..27930,z=-94265..-64178 |
|||
off x=-77480..-62456,y=41988..53394,z=-3296..5224 |
|||
on x=17779..35549,y=-83981..-44676,z=24943..61118 |
|||
on x=-71879..-58513,y=11898..41686,z=-30305..-14377 |
|||
on x=49017..68249,y=-15129..18976,z=48060..66574 |
|||
on x=-11838..7348,y=47553..63542,z=-67414..-47164 |
|||
on x=29088..44545,y=-50912..-15959,z=-70395..-57574 |
|||
off x=-43388..-23603,y=45905..62609,z=27676..53750 |
|||
off x=8215..38810,y=62437..78852,z=-38209..-33224 |
|||
on x=-64059..-27171,y=-60727..-35326,z=-61026..-43427 |
|||
off x=20457..53119,y=-60711..-47679,z=23184..55606 |
|||
on x=-70978..-46394,y=-65589..-44877,z=-10372..7338 |
|||
on x=-59744..-39936,y=48445..55988,z=-44347..-26762 |
|||
on x=-36717..-8107,y=26844..43311,z=-80832..-66912 |
|||
off x=72293..96031,y=3700..25701,z=-37561..-4131 |
|||
on x=-15500..16913,y=-79205..-68966,z=-39173..-4379 |
|||
off x=-756..21231,y=10628..37269,z=73578..82977 |
|||
on x=32058..55455,y=-6957..7461,z=45838..80279 |
|||
off x=-24364..-772,y=-85720..-66735,z=-48781..-36855 |
|||
on x=46435..56654,y=43815..66941,z=-25404..-13767 |
|||
off x=-88068..-77674,y=-10771..13874,z=-12402..-4509 |
|||
on x=-89131..-61902,y=-26569..-6043,z=-27916..-14242 |
|||
on x=32210..52737,y=-40074..-9230,z=42872..76038 |
|||
on x=56737..79302,y=24768..45359,z=-19322..4672 |
|||
on x=1759..24409,y=46620..57152,z=-71066..-48445 |
|||
on x=35478..60734,y=-39693..-22719,z=41724..51793 |
|||
on x=42961..64758,y=-12522..3554,z=52646..69182 |
|||
on x=-11351..-502,y=-40082..-24124,z=-75980..-63117 |
|||
off x=-40962..-6900,y=-5118..14251,z=-82423..-57286 |
|||
on x=-49095..-30797,y=1882..6948,z=-83530..-55361 |
|||
off x=-37135..-22299,y=-90205..-63314,z=-24970..4150 |
|||
on x=66749..74930,y=-44446..-9795,z=-16854..-4579 |
|||
on x=-63254..-52331,y=-68192..-44209,z=-35685..-8323 |
|||
on x=-78284..-55858,y=-43922..-30639,z=18437..29177 |
|||
off x=54114..79875,y=-17857..-2753,z=34356..52806 |
|||
on x=-4442..14186,y=29328..43813,z=-80985..-51107 |
|||
off x=-58292..-34166,y=35200..44230,z=-69669..-55147 |
|||
on x=18045..42192,y=-78983..-70509,z=1260..35570 |
|||
on x=37675..59839,y=-51270..-39433,z=-37248..-29925 |
|||
off x=-22757..-7114,y=-84027..-59378,z=-24973..-14829 |
|||
on x=24241..36320,y=52369..65837,z=31303..51099 |
|||
off x=5979..23857,y=9333..31171,z=-87793..-57399 |
|||
off x=49574..65617,y=-38214..-7290,z=-50479..-28030 |
|||
off x=-73979..-66980,y=-798..7274,z=-45325..-25314 |
|||
on x=-8945..-1295,y=-59463..-41375,z=52225..73615 |
|||
off x=18015..39217,y=32056..50406,z=-75587..-63271 |
|||
on x=-53213..-30694,y=-55350..-31907,z=49198..70681 |
|||
on x=-9682..8872,y=-52795..-28009,z=-82757..-59017 |
|||
off x=-83110..-67560,y=-37952..-10775,z=-19407..13655 |
|||
on x=-39964..-17588,y=52065..72360,z=4014..37773 |
|||
off x=56122..79842,y=-5178..21833,z=31724..59969 |
|||
on x=-20183..-4251,y=-12930..11778,z=77653..97600 |
|||
off x=31458..67825,y=9649..32029,z=41670..71827 |
|||
on x=-47523..-37181,y=-9554..-5366,z=-71284..-54135 |
|||
off x=-79907..-51809,y=-39505..-26324,z=-21886..8622 |
|||
on x=-49722..-26739,y=-4492..20265,z=-80362..-69563 |
|||
off x=30956..62691,y=22770..49749,z=57837..73923 |
|||
off x=63665..78972,y=-9429..11537,z=-61063..-23216 |
|||
off x=22797..28866,y=-83267..-52609,z=-50008..-23447 |
|||
off x=-9433..6781,y=-15625..9568,z=72480..99132 |
|||
on x=-39178..-2942,y=61606..79222,z=-12921..17911 |
|||
on x=-27409..-12810,y=-52323..-14724,z=70950..84284 |
|||
off x=25852..56927,y=-36323..-17730,z=-59374..-41271 |
|||
on x=-25411..1430,y=-71359..-48805,z=-54737..-38627 |
|||
off x=14921..35377,y=-63995..-41674,z=42383..70707 |
|||
on x=-81958..-63608,y=22908..36352,z=28840..42388 |
|||
off x=16786..42211,y=-73540..-54273,z=24103..37846 |
|||
on x=6690..26003,y=-68391..-40681,z=-57692..-53952 |
|||
off x=61396..83789,y=17549..42812,z=30784..43751 |
|||
on x=64100..88074,y=14435..30275,z=-26170..-9208 |
|||
off x=-21535..-16329,y=43013..49150,z=-80307..-58327 |
|||
off x=43392..60791,y=-67760..-57740,z=-3562..18983 |
|||
on x=53803..85117,y=-30851..-20415,z=11800..29393 |
|||
off x=-60548..-44088,y=-74749..-57558,z=-16897..-13294 |
|||
on x=-49335..-21672,y=-28001..3992,z=58205..86850 |
|||
on x=71619..75833,y=-41210..-28321,z=-3506..23850 |
|||
on x=-59162..-51706,y=-50779..-26256,z=-49407..-29710 |
|||
on x=-52052..-32903,y=16989..38661,z=-62750..-44298 |
|||
on x=27603..37228,y=-16325..-9791,z=51369..78290 |
|||
off x=-79181..-55186,y=26844..41675,z=-48211..-20069 |
|||
on x=-13372..-2778,y=-87434..-58366,z=13997..33615 |
|||
off x=-15866..1555,y=47047..63001,z=42221..60961 |
|||
on x=36372..49160,y=29641..52191,z=50265..54610 |
|||
off x=-50..22846,y=24999..49002,z=-90397..-70826 |
|||
off x=-53637..-33631,y=-70839..-47506,z=-40320..-30176 |
|||
on x=57782..80982,y=-13986..8709,z=-42185..-18601 |
|||
on x=-51683..-23658,y=-6359..15179,z=-75206..-63727 |
|||
off x=370..30490,y=44410..64293,z=49151..65936 |
|||
off x=46915..58565,y=-69733..-44180,z=-41213..-17210 |
|||
on x=28837..55823,y=-13583..10313,z=-85499..-50397 |
|||
on x=45884..74879,y=4208..23505,z=-57225..-37365 |
|||
on x=-16055..2075,y=-98025..-64232,z=404..15021 |
|||
off x=-6697..-284,y=-52120..-14644,z=61108..88330 |
|||
on x=-73126..-42133,y=-14478..-770,z=-67159..-42210 |
|||
on x=-78746..-55031,y=21688..48503,z=-43668..-17650 |
|||
off x=13011..19587,y=-76531..-58192,z=-21056..-6942 |
|||
on x=-3906..16882,y=38223..63854,z=-65796..-44021 |
|||
off x=75643..77858,y=-402..29624,z=-29755..-2860 |
|||
on x=18431..37928,y=-50506..-31706,z=65280..75113 |
|||
on x=-82626..-59287,y=-50984..-29586,z=-15689..-4450 |
|||
on x=35196..53027,y=26428..54765,z=57751..62588 |
|||
off x=23336..31485,y=-1303..18746,z=-94682..-64565 |
|||
on x=-3825..10918,y=-98053..-71932,z=865..16121 |
|||
off x=42549..65012,y=26302..54316,z=35324..58055 |
|||
off x=-30637..-826,y=69704..92482,z=8957..37872 |
|||
on x=9789..45193,y=-58252..-25098,z=55030..75560 |
|||
on x=-9204..9530,y=71096..78338,z=20937..35152 |
|||
off x=49102..65728,y=27717..54106,z=-51279..-22263 |
|||
off x=-73112..-53014,y=-17888..2555,z=34313..45513 |
|||
off x=19481..39159,y=-19753..16672,z=-84120..-70512 |
|||
off x=29245..51208,y=55393..75349,z=-26693..-9367 |
|||
off x=-32408..-12470,y=-86513..-71371,z=11659..34621 |
|||
on x=3836..19984,y=72474..77290,z=28159..42009 |
|||
off x=-65810..-45330,y=-40192..-17201,z=-36860..-23230 |
|||
on x=8693..27534,y=-32382..-13972,z=58478..81189 |
|||
on x=-43704..-20018,y=-33808..-23372,z=-78637..-61326 |
|||
off x=51547..78372,y=12517..15861,z=30172..52291 |
|||
on x=-33603..-11175,y=-36898..-7873,z=-90188..-68980 |
|||
off x=68965..88379,y=-35199..-18501,z=-16736..13433 |
|||
off x=-92562..-58792,y=-20585..-13928,z=7579..22007 |
|||
on x=-15258..-2610,y=69924..96628,z=-12430..15797 |
|||
off x=-30519..-8339,y=-12995..4240,z=63439..83735 |
|||
off x=-17707..10709,y=-26922..-18807,z=-96558..-63936 |
|||
off x=15322..27787,y=26350..47801,z=-67802..-46180 |
|||
off x=-84914..-54768,y=6968..34294,z=17631..34799 |
|||
on x=-7598..17160,y=37828..54405,z=-76895..-51602 |
|||
on x=11668..34456,y=40686..60885,z=-53707..-42575 |
|||
off x=-32256..-12704,y=-78957..-51139,z=-54900..-19346 |
|||
off x=19575..33292,y=-76785..-58856,z=-24794..-8650 |
|||
on x=-12555..10431,y=76180..91052,z=-7974..2379 |
|||
on x=-39693..-14106,y=7322..18221,z=-78159..-74632 |
|||
off x=-66375..-51676,y=-66860..-34841,z=-39129..-8655 |
|||
off x=-17258..-10828,y=12607..37266,z=61514..85164 |
|||
off x=-33610..-11456,y=-84257..-56108,z=-23442..-7294 |
|||
on x=14531..43763,y=53525..64606,z=-63336..-35807 |
|||
off x=-70597..-55320,y=-41967..-24265,z=25101..39095 |
|||
on x=-49603..-26677,y=-13219..1867,z=66460..87923 |
|||
off x=-60096..-23074,y=-70199..-42821,z=22480..37880 |
|||
off x=40348..69827,y=-51515..-33466,z=-52295..-34043 |
|||
off x=20389..44646,y=28477..41577,z=-72555..-44667 |
|||
on x=33741..54867,y=-36670..-7776,z=-72049..-55244 |
|||
on x=10950..46532,y=-54829..-45911,z=-73274..-40618 |
|||
on x=-67960..-44819,y=-45382..-24321,z=30618..47707 |
|||
on x=-58662..-48729,y=-65642..-29405,z=-56128..-29636 |
|||
on x=49272..79011,y=38939..52493,z=20586..30187 |
|||
off x=43410..60801,y=-61935..-34193,z=-32036..-22862 |
|||
on x=30969..60898,y=33040..50806,z=35073..57010 |
|||
off x=37114..59569,y=-71501..-44738,z=11340..32549 |
|||
off x=52829..76198,y=7688..34836,z=-67073..-40835 |
|||
off x=-92186..-63748,y=-11890..20416,z=-11446..1644 |
|||
on x=67652..84380,y=-40733..-18056,z=24324..41742 |
|||
on x=-62702..-39426,y=-43457..-16012,z=-69221..-51945 |
|||
on x=-73660..-53500,y=27383..37368,z=2421..23275 |
|||
on x=-77487..-46062,y=-50070..-24177,z=-47875..-27262 |
|||
on x=-945..14054,y=-49971..-42857,z=-76052..-46001 |
|||
on x=-43003..-22308,y=58137..82894,z=19469..47327 |
|||
off x=19774..38418,y=-33987..-16275,z=-69339..-64365 |
|||
on x=-21207..4193,y=-7234..-2286,z=-85723..-60361 |
|||
on x=72912..88857,y=2552..35986,z=20898..28896 |
|||
on x=54225..89222,y=15996..40989,z=-44532..-13768 |
|||
on x=-65712..-61563,y=-49387..-24770,z=-44808..-18999 |
|||
on x=-69404..-48271,y=-68838..-43356,z=-7999..13427 |
|||
on x=-14554..-6184,y=67577..76141,z=25618..45348 |
|||
off x=17080..39490,y=54822..76095,z=-33504..-20429 |
|||
off x=72126..88153,y=-25075..-2924,z=-35655..-21906 |
|||
off x=-9585..24318,y=-79462..-62167,z=36467..45387 |
|||
on x=50711..62365,y=8410..24520,z=44319..69714 |
|||
off x=26163..48176,y=49270..76862,z=25486..40214 |
|||
off x=-66006..-47007,y=26306..40268,z=-57257..-44008 |
|||
on x=-18103..978,y=-66402..-53423,z=-58187..-49950 |
|||
off x=-82231..-53929,y=-30302..-2792,z=-50350..-33862 |
|||
off x=-80773..-50142,y=26085..50767,z=-37036..-5317 |
|||
on x=-73412..-50645,y=-37254..-15738,z=27795..47197 |
|||
on x=53256..56693,y=-27500..-12752,z=39288..60009 |
|||
on x=9678..25000,y=9814..20035,z=-80762..-69083 |
|||
off x=75905..77562,y=-35226..-12588,z=-23403..2007 |
|||
on x=-74228..-51192,y=-60471..-47282,z=-18153..11152 |
|||
on x=-88144..-65383,y=27947..50190,z=-22007..7068 |
|||
on x=-57769..-30200,y=-74568..-46266,z=1997..7401 |
|||
on x=-53231..-25606,y=-1090..21355,z=57688..84914 |
|||
off x=3894..23908,y=-12364..22961,z=-89732..-71854 |
|||
on x=-29012..-9560,y=-78082..-62997,z=-29218..-8539 |
|||
off x=-35760..-28704,y=-69703..-59299,z=26665..59052 |
|||
on x=-9820..-311,y=-50467..-30267,z=45150..77323 |
|||
off x=-34746..-29058,y=53504..84718,z=15584..24656 |
|||
off x=-80685..-48403,y=-19777..4826,z=33281..66712 |
|||
on x=67395..77602,y=-46450..-19661,z=-31973..-18038 |
|||
on x=-70033..-64759,y=19552..51911,z=11121..35381 |
|||
off x=-73590..-42942,y=-46390..-22759,z=40874..56566 |
|||
off x=-36575..-18344,y=61042..86630,z=6307..26426 |
|||
off x=-46370..-27813,y=23975..41903,z=54255..72840 |
@ -0,0 +1,4 @@ |
|||
on x=10..12,y=10..12,z=10..12 |
|||
on x=11..13,y=11..13,z=11..13 |
|||
off x=9..11,y=9..11,z=9..11 |
|||
on x=10..10,y=10..10,z=10..10 |
@ -0,0 +1,22 @@ |
|||
on x=-20..26,y=-36..17,z=-47..7 |
|||
on x=-20..33,y=-21..23,z=-26..28 |
|||
on x=-22..28,y=-29..23,z=-38..16 |
|||
on x=-46..7,y=-6..46,z=-50..-1 |
|||
on x=-49..1,y=-3..46,z=-24..28 |
|||
on x=2..47,y=-22..22,z=-23..27 |
|||
on x=-27..23,y=-28..26,z=-21..29 |
|||
on x=-39..5,y=-6..47,z=-3..44 |
|||
on x=-30..21,y=-8..43,z=-13..34 |
|||
on x=-22..26,y=-27..20,z=-29..19 |
|||
off x=-48..-32,y=26..41,z=-47..-37 |
|||
on x=-12..35,y=6..50,z=-50..-2 |
|||
off x=-48..-32,y=-32..-16,z=-15..-5 |
|||
on x=-18..26,y=-33..15,z=-7..46 |
|||
off x=-40..-22,y=-38..-28,z=23..41 |
|||
on x=-16..35,y=-41..10,z=-47..6 |
|||
off x=-32..-23,y=11..30,z=-14..3 |
|||
on x=-49..-5,y=-3..45,z=-29..18 |
|||
off x=18..30,y=-20..-8,z=-3..13 |
|||
on x=-41..9,y=-7..43,z=-33..15 |
|||
on x=-54112..-39298,y=-85059..-49293,z=-27449..7877 |
|||
on x=967..23432,y=45373..81175,z=27513..53682 |
@ -0,0 +1,60 @@ |
|||
on x=-5..47,y=-31..22,z=-19..33 |
|||
on x=-44..5,y=-27..21,z=-14..35 |
|||
on x=-49..-1,y=-11..42,z=-10..38 |
|||
on x=-20..34,y=-40..6,z=-44..1 |
|||
off x=26..39,y=40..50,z=-2..11 |
|||
on x=-41..5,y=-41..6,z=-36..8 |
|||
off x=-43..-33,y=-45..-28,z=7..25 |
|||
on x=-33..15,y=-32..19,z=-34..11 |
|||
off x=35..47,y=-46..-34,z=-11..5 |
|||
on x=-14..36,y=-6..44,z=-16..29 |
|||
on x=-57795..-6158,y=29564..72030,z=20435..90618 |
|||
on x=36731..105352,y=-21140..28532,z=16094..90401 |
|||
on x=30999..107136,y=-53464..15513,z=8553..71215 |
|||
on x=13528..83982,y=-99403..-27377,z=-24141..23996 |
|||
on x=-72682..-12347,y=18159..111354,z=7391..80950 |
|||
on x=-1060..80757,y=-65301..-20884,z=-103788..-16709 |
|||
on x=-83015..-9461,y=-72160..-8347,z=-81239..-26856 |
|||
on x=-52752..22273,y=-49450..9096,z=54442..119054 |
|||
on x=-29982..40483,y=-108474..-28371,z=-24328..38471 |
|||
on x=-4958..62750,y=40422..118853,z=-7672..65583 |
|||
on x=55694..108686,y=-43367..46958,z=-26781..48729 |
|||
on x=-98497..-18186,y=-63569..3412,z=1232..88485 |
|||
on x=-726..56291,y=-62629..13224,z=18033..85226 |
|||
on x=-110886..-34664,y=-81338..-8658,z=8914..63723 |
|||
on x=-55829..24974,y=-16897..54165,z=-121762..-28058 |
|||
on x=-65152..-11147,y=22489..91432,z=-58782..1780 |
|||
on x=-120100..-32970,y=-46592..27473,z=-11695..61039 |
|||
on x=-18631..37533,y=-124565..-50804,z=-35667..28308 |
|||
on x=-57817..18248,y=49321..117703,z=5745..55881 |
|||
on x=14781..98692,y=-1341..70827,z=15753..70151 |
|||
on x=-34419..55919,y=-19626..40991,z=39015..114138 |
|||
on x=-60785..11593,y=-56135..2999,z=-95368..-26915 |
|||
on x=-32178..58085,y=17647..101866,z=-91405..-8878 |
|||
on x=-53655..12091,y=50097..105568,z=-75335..-4862 |
|||
on x=-111166..-40997,y=-71714..2688,z=5609..50954 |
|||
on x=-16602..70118,y=-98693..-44401,z=5197..76897 |
|||
on x=16383..101554,y=4615..83635,z=-44907..18747 |
|||
off x=-95822..-15171,y=-19987..48940,z=10804..104439 |
|||
on x=-89813..-14614,y=16069..88491,z=-3297..45228 |
|||
on x=41075..99376,y=-20427..49978,z=-52012..13762 |
|||
on x=-21330..50085,y=-17944..62733,z=-112280..-30197 |
|||
on x=-16478..35915,y=36008..118594,z=-7885..47086 |
|||
off x=-98156..-27851,y=-49952..43171,z=-99005..-8456 |
|||
off x=2032..69770,y=-71013..4824,z=7471..94418 |
|||
on x=43670..120875,y=-42068..12382,z=-24787..38892 |
|||
off x=37514..111226,y=-45862..25743,z=-16714..54663 |
|||
off x=25699..97951,y=-30668..59918,z=-15349..69697 |
|||
off x=-44271..17935,y=-9516..60759,z=49131..112598 |
|||
on x=-61695..-5813,y=40978..94975,z=8655..80240 |
|||
off x=-101086..-9439,y=-7088..67543,z=33935..83858 |
|||
off x=18020..114017,y=-48931..32606,z=21474..89843 |
|||
off x=-77139..10506,y=-89994..-18797,z=-80..59318 |
|||
off x=8476..79288,y=-75520..11602,z=-96624..-24783 |
|||
on x=-47488..-1262,y=24338..100707,z=16292..72967 |
|||
off x=-84341..13987,y=2429..92914,z=-90671..-1318 |
|||
off x=-37810..49457,y=-71013..-7894,z=-105357..-13188 |
|||
off x=-27365..46395,y=31009..98017,z=15428..76570 |
|||
off x=-70369..-16548,y=22648..78696,z=-1892..86821 |
|||
on x=-53470..21291,y=-120233..-33476,z=-44150..38147 |
|||
off x=-93533..-4276,y=-16170..68771,z=-104985..-24507 |
@ -0,0 +1,109 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys |
|||
from functools import cache |
|||
|
|||
@cache |
|||
def path(f1,f2): |
|||
path = [] |
|||
y, x = f1 |
|||
while y != 0: |
|||
y -= 1 |
|||
path.append((y,x)) |
|||
while x != f2[1]: |
|||
x += 1 if f2[1] > x else -1 |
|||
path.append((y,x)) |
|||
while y != f2[0]: |
|||
y += 1 |
|||
path.append((y,x)) |
|||
assert path[-1] == f2 |
|||
return path |
|||
|
|||
def pathvalid(path,board): |
|||
for p in path: |
|||
if p in board: return False |
|||
return True |
|||
|
|||
def cost(a,w): |
|||
if a == 'A': return len(w) * 1 |
|||
if a == 'B': return len(w) * 10 |
|||
if a == 'C': return len(w) * 100 |
|||
if a == 'D': return len(w) * 1000 |
|||
|
|||
def endstate(board): |
|||
for f,a in board.items(): |
|||
if f[1] != target[a]: return False |
|||
return True |
|||
|
|||
def target_position(f,b,lowest): |
|||
a = b[f] |
|||
if f[1] != target[a]: return False |
|||
for y in range(f[0],lowest+1): |
|||
if (y,target[a]) not in b: return False |
|||
if b[(y,target[a])] != a: return False |
|||
return True |
|||
|
|||
def totarget(board,lowest): |
|||
change = False |
|||
costs = 0 |
|||
nb = {k: v for k,v in board.items()} |
|||
for f,a in board.items(): |
|||
if target_position(f,nb,lowest): continue |
|||
t = (lowest,target[a]) |
|||
while t in nb and nb[t] == a: |
|||
t = (t[0]-1,target[a]) |
|||
if t == (0,target[a]): continue |
|||
p = path(f,t) |
|||
if pathvalid(p,nb): |
|||
change = True |
|||
nb.pop(f) |
|||
nb[t] = a |
|||
costs += cost(a,p) |
|||
return nb,costs,change |
|||
|
|||
def dfs(board,lowest,costs=0,curmin=sys.maxsize): |
|||
ch = True |
|||
nb = {k: v for k,v in board.items()} |
|||
while ch: |
|||
nb,co,ch = totarget(nb,lowest) |
|||
costs += co |
|||
if endstate(nb): |
|||
return costs |
|||
if costs > curmin: return None |
|||
board = {k: v for k,v in nb.items()} |
|||
for f,a in board.items(): |
|||
if f[0] != 0 and not(target_position(f,board,lowest)): |
|||
for f2 in hallway: |
|||
p = path(f,f2) |
|||
if pathvalid(p, board): |
|||
cb = {k: v for k,v in board.items()} |
|||
cb.pop(f) |
|||
cb[f2] = a |
|||
nc = dfs(cb,lowest,costs+cost(a,p),curmin) |
|||
if nc is not None and nc < curmin: curmin = nc |
|||
if curmin < sys.maxsize: return curmin |
|||
|
|||
if __name__ == '__main__': |
|||
# challenge 1 |
|||
lines = open(sys.argv[1]).readlines() |
|||
start = {} |
|||
for y,l in enumerate(lines[1:]): |
|||
for x,f in enumerate(l[1:]): |
|||
if f in 'ABCD': start[(y,x)] = f |
|||
|
|||
hallway = [(0,0), (0,1), (0,3), (0,5), (0,7), (0,9), (0,10)] |
|||
target = {'A': 2, 'B': 4, 'C': 6, 'D': 8} |
|||
|
|||
res1 = str(dfs(start,2)) |
|||
print("challenge 1:" + "\n" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
lines = open(sys.argv[2]).readlines() |
|||
start = {} |
|||
for y,l in enumerate(lines[1:]): |
|||
for x,f in enumerate(l[1:]): |
|||
if f in 'ABCD': start[(y,x)] = f |
|||
|
|||
res2 = str(dfs(start,4)) |
|||
print("challenge 2:" + "\n" + res2 + "\n") |
|||
|
@ -0,0 +1,329 @@ |
|||
--- Day 23: Amphipod --- |
|||
|
|||
A group of amphipods notice your fancy submarine and flag you down. "With such an impressive shell," one amphipod says, "surely you can help us with a question that has stumped our best scientists." |
|||
|
|||
They go on to explain that a group of timid, stubborn amphipods live in a nearby burrow. Four types of amphipods live there: Amber (A), Bronze (B), Copper (C), and Desert (D). They live in a burrow that consists of a hallway and four side rooms. The side rooms are initially full of amphipods, and the hallway is initially empty. |
|||
|
|||
They give you a diagram of the situation (your puzzle input), including locations of each amphipod (A, B, C, or D, each of which is occupying an otherwise open space), walls (#), and open space (.). |
|||
|
|||
For example: |
|||
|
|||
############# |
|||
#...........# |
|||
###B#C#B#D### |
|||
#A#D#C#A# |
|||
######### |
|||
|
|||
The amphipods would like a method to organize every amphipod into side rooms so that each side room contains one type of amphipod and the types are sorted A-D going left to right, like this: |
|||
|
|||
############# |
|||
#...........# |
|||
###A#B#C#D### |
|||
#A#B#C#D# |
|||
######### |
|||
|
|||
Amphipods can move up, down, left, or right so long as they are moving into an unoccupied open space. Each type of amphipod requires a different amount of energy to move one step: Amber amphipods require 1 energy per step, Bronze amphipods require 10 energy, Copper amphipods require 100, and Desert ones require 1000. The amphipods would like you to find a way to organize the amphipods that requires the least total energy. |
|||
|
|||
However, because they are timid and stubborn, the amphipods have some extra rules: |
|||
|
|||
Amphipods will never stop on the space immediately outside any room. They can move into that space so long as they immediately continue moving. (Specifically, this refers to the four open spaces in the hallway that are directly above an amphipod starting position.) |
|||
Amphipods will never move from the hallway into a room unless that room is their destination room and that room contains no amphipods which do not also have that room as their own destination. If an amphipod's starting room is not its destination room, it can stay in that room until it leaves the room. (For example, an Amber amphipod will not move from the hallway into the right three rooms, and will only move into the leftmost room if that room is empty or if it only contains other Amber amphipods.) |
|||
Once an amphipod stops moving in the hallway, it will stay in that spot until it can move into a room. (That is, once any amphipod starts moving, any other amphipods currently in the hallway are locked in place and will not move again until they can move fully into a room.) |
|||
|
|||
In the above example, the amphipods can be organized using a minimum of 12521 energy. One way to do this is shown below. |
|||
|
|||
Starting configuration: |
|||
|
|||
############# |
|||
#...........# |
|||
###B#C#B#D### |
|||
#A#D#C#A# |
|||
######### |
|||
|
|||
One Bronze amphipod moves into the hallway, taking 4 steps and using 40 energy: |
|||
|
|||
############# |
|||
#...B.......# |
|||
###B#C#.#D### |
|||
#A#D#C#A# |
|||
######### |
|||
|
|||
The only Copper amphipod not in its side room moves there, taking 4 steps and using 400 energy: |
|||
|
|||
############# |
|||
#...B.......# |
|||
###B#.#C#D### |
|||
#A#D#C#A# |
|||
######### |
|||
|
|||
A Desert amphipod moves out of the way, taking 3 steps and using 3000 energy, and then the Bronze amphipod takes its place, taking 3 steps and using 30 energy: |
|||
|
|||
############# |
|||
#.....D.....# |
|||
###B#.#C#D### |
|||
#A#B#C#A# |
|||
######### |
|||
|
|||
The leftmost Bronze amphipod moves to its room using 40 energy: |
|||
|
|||
############# |
|||
#.....D.....# |
|||
###.#B#C#D### |
|||
#A#B#C#A# |
|||
######### |
|||
|
|||
Both amphipods in the rightmost room move into the hallway, using 2003 energy in total: |
|||
|
|||
############# |
|||
#.....D.D.A.# |
|||
###.#B#C#.### |
|||
#A#B#C#.# |
|||
######### |
|||
|
|||
Both Desert amphipods move into the rightmost room using 7000 energy: |
|||
|
|||
############# |
|||
#.........A.# |
|||
###.#B#C#D### |
|||
#A#B#C#D# |
|||
######### |
|||
|
|||
Finally, the last Amber amphipod moves into its room, using 8 energy: |
|||
|
|||
############# |
|||
#...........# |
|||
###A#B#C#D### |
|||
#A#B#C#D# |
|||
######### |
|||
|
|||
What is the least energy required to organize the amphipods? |
|||
|
|||
Your puzzle answer was 18195. |
|||
--- Part Two --- |
|||
|
|||
As you prepare to give the amphipods your solution, you notice that the diagram they handed you was actually folded up. As you unfold it, you discover an extra part of the diagram. |
|||
|
|||
Between the first and second lines of text that contain amphipod starting positions, insert the following lines: |
|||
|
|||
#D#C#B#A# |
|||
#D#B#A#C# |
|||
|
|||
So, the above example now becomes: |
|||
|
|||
############# |
|||
#...........# |
|||
###B#C#B#D### |
|||
#D#C#B#A# |
|||
#D#B#A#C# |
|||
#A#D#C#A# |
|||
######### |
|||
|
|||
The amphipods still want to be organized into rooms similar to before: |
|||
|
|||
############# |
|||
#...........# |
|||
###A#B#C#D### |
|||
#A#B#C#D# |
|||
#A#B#C#D# |
|||
#A#B#C#D# |
|||
######### |
|||
|
|||
In this updated example, the least energy required to organize these amphipods is 44169: |
|||
|
|||
############# |
|||
#...........# |
|||
###B#C#B#D### |
|||
#D#C#B#A# |
|||
#D#B#A#C# |
|||
#A#D#C#A# |
|||
######### |
|||
|
|||
############# |
|||
#..........D# |
|||
###B#C#B#.### |
|||
#D#C#B#A# |
|||
#D#B#A#C# |
|||
#A#D#C#A# |
|||
######### |
|||
|
|||
############# |
|||
#A.........D# |
|||
###B#C#B#.### |
|||
#D#C#B#.# |
|||
#D#B#A#C# |
|||
#A#D#C#A# |
|||
######### |
|||
|
|||
############# |
|||
#A........BD# |
|||
###B#C#.#.### |
|||
#D#C#B#.# |
|||
#D#B#A#C# |
|||
#A#D#C#A# |
|||
######### |
|||
|
|||
############# |
|||
#A......B.BD# |
|||
###B#C#.#.### |
|||
#D#C#.#.# |
|||
#D#B#A#C# |
|||
#A#D#C#A# |
|||
######### |
|||
|
|||
############# |
|||
#AA.....B.BD# |
|||
###B#C#.#.### |
|||
#D#C#.#.# |
|||
#D#B#.#C# |
|||
#A#D#C#A# |
|||
######### |
|||
|
|||
############# |
|||
#AA.....B.BD# |
|||
###B#.#.#.### |
|||
#D#C#.#.# |
|||
#D#B#C#C# |
|||
#A#D#C#A# |
|||
######### |
|||
|
|||
############# |
|||
#AA.....B.BD# |
|||
###B#.#.#.### |
|||
#D#.#C#.# |
|||
#D#B#C#C# |
|||
#A#D#C#A# |
|||
######### |
|||
|
|||
############# |
|||
#AA...B.B.BD# |
|||
###B#.#.#.### |
|||
#D#.#C#.# |
|||
#D#.#C#C# |
|||
#A#D#C#A# |
|||
######### |
|||
|
|||
############# |
|||
#AA.D.B.B.BD# |
|||
###B#.#.#.### |
|||
#D#.#C#.# |
|||
#D#.#C#C# |
|||
#A#.#C#A# |
|||
######### |
|||
|
|||
############# |
|||
#AA.D...B.BD# |
|||
###B#.#.#.### |
|||
#D#.#C#.# |
|||
#D#.#C#C# |
|||
#A#B#C#A# |
|||
######### |
|||
|
|||
############# |
|||
#AA.D.....BD# |
|||
###B#.#.#.### |
|||
#D#.#C#.# |
|||
#D#B#C#C# |
|||
#A#B#C#A# |
|||
######### |
|||
|
|||
############# |
|||
#AA.D......D# |
|||
###B#.#.#.### |
|||
#D#B#C#.# |
|||
#D#B#C#C# |
|||
#A#B#C#A# |
|||
######### |
|||
|
|||
############# |
|||
#AA.D......D# |
|||
###B#.#C#.### |
|||
#D#B#C#.# |
|||
#D#B#C#.# |
|||
#A#B#C#A# |
|||
######### |
|||
|
|||
############# |
|||
#AA.D.....AD# |
|||
###B#.#C#.### |
|||
#D#B#C#.# |
|||
#D#B#C#.# |
|||
#A#B#C#.# |
|||
######### |
|||
|
|||
############# |
|||
#AA.......AD# |
|||
###B#.#C#.### |
|||
#D#B#C#.# |
|||
#D#B#C#.# |
|||
#A#B#C#D# |
|||
######### |
|||
|
|||
############# |
|||
#AA.......AD# |
|||
###.#B#C#.### |
|||
#D#B#C#.# |
|||
#D#B#C#.# |
|||
#A#B#C#D# |
|||
######### |
|||
|
|||
############# |
|||
#AA.......AD# |
|||
###.#B#C#.### |
|||
#.#B#C#.# |
|||
#D#B#C#D# |
|||
#A#B#C#D# |
|||
######### |
|||
|
|||
############# |
|||
#AA.D.....AD# |
|||
###.#B#C#.### |
|||
#.#B#C#.# |
|||
#.#B#C#D# |
|||
#A#B#C#D# |
|||
######### |
|||
|
|||
############# |
|||
#A..D.....AD# |
|||
###.#B#C#.### |
|||
#.#B#C#.# |
|||
#A#B#C#D# |
|||
#A#B#C#D# |
|||
######### |
|||
|
|||
############# |
|||
#...D.....AD# |
|||
###.#B#C#.### |
|||
#A#B#C#.# |
|||
#A#B#C#D# |
|||
#A#B#C#D# |
|||
######### |
|||
|
|||
############# |
|||
#.........AD# |
|||
###.#B#C#.### |
|||
#A#B#C#D# |
|||
#A#B#C#D# |
|||
#A#B#C#D# |
|||
######### |
|||
|
|||
############# |
|||
#..........D# |
|||
###A#B#C#.### |
|||
#A#B#C#D# |
|||
#A#B#C#D# |
|||
#A#B#C#D# |
|||
######### |
|||
|
|||
############# |
|||
#...........# |
|||
###A#B#C#D### |
|||
#A#B#C#D# |
|||
#A#B#C#D# |
|||
#A#B#C#D# |
|||
######### |
|||
|
|||
Using the initial configuration from the full diagram, what is the least energy required to organize the amphipods? |
|||
|
|||
Your puzzle answer was 50265. |
|||
|
|||
Both parts of this puzzle are complete! They provide two gold stars: ** |
@ -0,0 +1,5 @@ |
|||
############# |
|||
#...........# |
|||
###A#C#B#A### |
|||
#D#D#B#C# |
|||
######### |
@ -0,0 +1,7 @@ |
|||
############# |
|||
#...........# |
|||
###A#C#B#A### |
|||
#D#C#B#A# |
|||
#D#B#A#C# |
|||
#D#D#B#C# |
|||
######### |
@ -0,0 +1,5 @@ |
|||
############# |
|||
#...........# |
|||
###B#C#B#D### |
|||
#A#D#C#A# |
|||
######### |
@ -0,0 +1,7 @@ |
|||
############# |
|||
#...........# |
|||
###B#C#B#D### |
|||
#D#C#B#A# |
|||
#D#B#A#C# |
|||
#A#D#C#A# |
|||
######### |
@ -0,0 +1,5 @@ |
|||
############# |
|||
#.....D.D.A.# |
|||
###.#B#C#.### |
|||
#A#B#C#.# |
|||
######### |
@ -0,0 +1,7 @@ |
|||
############# |
|||
#AA.D......D# |
|||
###B#.#C#.### |
|||
#D#B#C#.# |
|||
#D#B#C#.# |
|||
#A#B#C#A# |
|||
######### |
@ -0,0 +1,60 @@ |
|||
#!/usr/bin/env python3 |
|||
|
|||
import sys, re, math |
|||
from operator import add, mul, truediv, mod |
|||
from functools import reduce |
|||
|
|||
def parse(line): |
|||
l = line.split(' ') |
|||
if l[0] == 'inp': i,o = l |
|||
else: i,o = l[0], [l[1],l[2]] |
|||
return (i,o) |
|||
|
|||
def replist(l,v,r): |
|||
return [r if i == v else i for i in l] |
|||
|
|||
def eql(a,b): |
|||
return int(a == b) |
|||
|
|||
def div(a,b): |
|||
return math.trunc(reduce(truediv,[a,b])) |
|||
|
|||
def alu(instruction, inp): |
|||
reg = {'w': 0, 'x': 0, 'y': 0, 'z': 0} |
|||
inp = list(str(inp)) |
|||
index = 0 |
|||
for i,ops in instruction: |
|||
if i == 'inp': |
|||
reg[ops] = inp[index] |
|||
index += 1 |
|||
else: |
|||
reg[ops[0]] = reduce(eval(i),[int(reg[o]) if o in 'wxyz' else int(o) for o in ops]) |
|||
|
|||
return reg |
|||
|
|||
if __name__ == '__main__': |
|||
instr = [parse(line.strip('\n')) for line in open(sys.argv[1])] |
|||
|
|||
for i in range(1,9): |
|||
for k in range(11111111111,99999999999): |
|||
for j in ['18','27']: |
|||
r = alu(instr,str(i)+j+str(k)) |
|||
print(str(i)+j+str(k),r) |
|||
if r['z'] == 0: print(i,j,k) |
|||
|
|||
for i in range(99999999999999,9999999999999,-1): |
|||
if i % 10000 == 0: print(i) |
|||
if '0' in str(i): continue |
|||
r = alu(instr,str(i)) |
|||
if r['z'] == 0: |
|||
print(i) |
|||
break |
|||
|
|||
# challenge 1 |
|||
res1 = "" |
|||
print("challenge 1:" + "\n" + res1 + "\n") |
|||
|
|||
# challenge 2 |
|||
res2 = "" |
|||
print("challenge 2:" + "\n" + res2 + "\n") |
|||
|
@ -0,0 +1,109 @@ |
|||
:- use_module(library(clpfd)). |
|||
|
|||
% den state kannst du mit nem dictoniary modellieren: |
|||
initState(state{ x: 0, y: 0, z:0, w: 0 , in: I}, I). |
|||
% Dictonary lookup: initstate(State), R = State.x |
|||
% Dictonary update: initstate(State), NewState = State.put(x, 1) |
|||
|
|||
% Convert List of input digits into single number |
|||
%input_number(+Inputs, -Number) |
|||
input_number(Inputs, Number) :- atomic_list_concat(Inputs, Number). |
|||
|
|||
|
|||
% read program helper functions |
|||
noteof(L) :- \+ L = [end_of_file]. |
|||
string_term(String,Term) :- term_string(Term, String). |
|||
parse_instr(String, Inst) :- |
|||
split_string(String, " ", "", Words), |
|||
maplist(string_term, Words, Inst). |
|||
|
|||
% Read a list of Instructions from Filename |
|||
% read_program(+Filename, -Prog) |
|||
read_program(Filename, Prog) :- |
|||
open(Filename, read, Str), |
|||
read_string(Str, _, S), |
|||
split_string(S, "\n", "", Lines), |
|||
maplist(parse_instr, Lines, Instrs), |
|||
include(noteof, Instrs, Prog), |
|||
close(Str). |
|||
|
|||
% Takes input and state and binds O to a number |
|||
num(N,S,O) :- |
|||
atom(N), |
|||
O = S.N. |
|||
|
|||
num(N,S,O) :- |
|||
number(N), |
|||
O = N. |
|||
|
|||
eq(A,B,R) :- |
|||
A = B, |
|||
R = 1. |
|||
|
|||
eq(A,B,R) :- |
|||
A #\= B, |
|||
R = 0. |
|||
|
|||
read_input(In,F,NIn) :- |
|||
[F | NIn] = In. |
|||
|
|||
% interprets an instruction |
|||
% interpret(+list,+state,R) |
|||
interpret([inp, A],InState,OutState) :- |
|||
read_input(InState.in,C,NInput), |
|||
BS = InState.put(A,C), |
|||
OutState = BS.put(in,NInput). |
|||
|
|||
interpret([add, A, B],InState,OutState) :- |
|||
num(B,InState,C), |
|||
R #= InState.A + C, |
|||
OutState = InState.put(A,R). |
|||
|
|||
interpret([mul, A, B],InState,OutState) :- |
|||
num(B,InState,C), |
|||
R #= InState.A*C, |
|||
OutState = InState.put(A,R). |
|||
|
|||
interpret([div, A, B],InState,OutState) :- |
|||
num(B,InState,C), |
|||
R #= InState.A div C, |
|||
OutState = InState.put(A,R). |
|||
|
|||
interpret([mod, A, B],InState,OutState) :- |
|||
num(B,InState,C), |
|||
R #= InState.A mod C, |
|||
OutState = InState.put(A,R). |
|||
|
|||
interpret([eql, A, B],InState,OutState) :- |
|||
num(B,InState,C), |
|||
eq(InState.A, C, R), |
|||
OutState = InState.put(A,R). |
|||
|
|||
rprogram(State,[],O) :- |
|||
O = State.z. |
|||
|
|||
rprogram(State,[I|Instr], O) :- |
|||
interpret(I,State,Out), |
|||
rprogram(Out,Instr,O). |
|||
|
|||
program(Instr,Input) :- |
|||
length(Input, 14), |
|||
Input ins 1..9, |
|||
initState(S,Input), |
|||
rprogram(S,Instr, O), |
|||
O = 0. |
|||
|
|||
max_monad(M) :- |
|||
read_program(input24,Instr), |
|||
program(Instr,R), |
|||
labeling([max,down],R), |
|||
input_number(R,M), |
|||
write(M). |
|||
|
|||
min_monad(M) :- |
|||
read_program(input24,Instr), |
|||
program(Instr,R), |
|||
labeling([min],R), |
|||
input_number(R,M), |
|||
write(M). |
|||
|
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue