Update days

This commit is contained in:
Blizzard Finnegan 2021-12-20 10:10:08 -05:00
parent 9573fe6391
commit 96b02986a8
9 changed files with 2103 additions and 0 deletions

100
day18/data/input.txt Normal file
View file

@ -0,0 +1,100 @@
[6,[[5,[7,7]],[[8,2],2]]]
[[8,[0,0]],[[[1,4],[2,0]],[[2,3],[8,2]]]]
[[[7,[6,1]],[9,[7,9]]],[[6,6],2]]
[[5,[2,0]],[[[9,4],[6,8]],[3,9]]]
[[[3,[0,3]],[5,[9,8]]],[[5,[8,1]],[1,2]]]
[[[5,[8,5]],[[6,3],3]],[[1,[0,9]],[[3,0],[7,3]]]]
[[[[1,2],0],[8,[6,6]]],[6,[7,5]]]
[[[[0,9],[5,3]],[[9,7],8]],[9,[[1,9],1]]]
[[4,[6,[0,8]]],[[2,9],1]]
[[[5,1],[6,[9,5]]],8]
[[[4,[7,0]],1],[3,3]]
[2,[[3,4],6]]
[[[[0,5],[7,1]],[[7,0],[1,7]]],2]
[[3,[7,8]],[[1,0],[[1,7],6]]]
[[[7,[6,3]],1],[4,[1,[6,8]]]]
[[[[5,5],[3,5]],[5,[2,6]]],[3,[1,[3,2]]]]
[[8,2],9]
[[8,[[1,9],2]],[[8,[8,4]],3]]
[[[[8,7],9],5],[[[0,6],5],[6,5]]]
[[2,6],[0,[[9,8],6]]]
[[[[7,9],0],[[1,5],9]],[[[2,2],1],[3,1]]]
[[8,[1,[9,1]]],[0,[0,[2,4]]]]
[[[[0,2],3],[[9,4],9]],[[3,2],[[5,7],[4,8]]]]
[[[[8,0],3],[9,[5,9]]],[4,3]]
[2,[7,[[3,3],[7,9]]]]
[3,[[[6,4],0],5]]
[[1,[[9,9],9]],[[[0,3],[0,6]],0]]
[[7,[[2,3],4]],[6,[9,9]]]
[3,5]
[[[[2,3],2],[1,[9,9]]],[[8,2],[1,[2,0]]]]
[[[[7,2],[3,6]],[[9,7],[8,9]]],[[[5,3],[5,1]],6]]
[8,[[7,0],[[8,2],5]]]
[[[1,[1,0]],[[3,7],[4,5]]],[[[6,5],2],1]]
[8,[[5,0],3]]
[[[4,1],9],[1,5]]
[[9,[5,[3,7]]],[[0,4],4]]
[[[[9,6],4],[8,[7,5]]],[[6,9],5]]
[[[7,[2,5]],0],[8,[0,7]]]
[8,[[4,[1,8]],[[8,9],3]]]
[[[[3,7],[7,3]],[[5,3],1]],[[[6,7],[2,7]],[[2,6],[9,0]]]]
[[[9,[5,4]],[[1,7],2]],[[1,0],[[2,6],0]]]
[[[[3,2],[5,3]],[9,[2,0]]],[[7,6],[[8,2],[0,7]]]]
[[[4,0],0],[9,0]]
[[[[9,4],[0,9]],[2,3]],8]
[[2,[8,[6,7]]],[[[6,1],[5,1]],[3,[1,1]]]]
[[6,[[8,2],7]],5]
[[[[7,3],[9,7]],5],[[[0,9],4],[3,[0,3]]]]
[[2,[6,7]],[[[9,0],[6,7]],4]]
[[[[3,1],5],[7,[5,1]]],[[[8,4],9],[[2,7],[4,6]]]]
[[8,8],[[[1,4],[7,3]],[[9,6],5]]]
[[[[3,0],8],[[5,1],[7,8]]],[[[5,0],[2,2]],[[9,0],[0,7]]]]
[[1,1],7]
[[4,3],[[9,[7,3]],[2,3]]]
[[[5,[3,5]],3],7]
[[[5,[3,2]],1],[[[3,2],8],[8,5]]]
[[7,[6,5]],[[[9,8],7],6]]
[[[7,9],0],[3,4]]
[[[[5,6],[7,4]],[4,[1,7]]],[[[8,2],7],[6,[4,5]]]]
[[[[8,5],1],[[7,0],[9,7]]],[[[5,2],3],2]]
[[[[7,3],9],7],[[[8,1],9],3]]
[[[6,5],[4,[6,1]]],7]
[[[[4,0],1],[4,4]],[[1,7],[3,0]]]
[9,[[2,[9,0]],6]]
[[[[0,0],9],2],[9,3]]
[5,[5,[[6,6],[2,6]]]]
[[[[8,2],[8,9]],[[8,4],[8,0]]],[[[9,5],6],4]]
[[[3,[6,1]],[3,[6,9]]],[3,4]]
[[[7,[6,3]],[[6,7],1]],[[1,1],2]]
[[[[1,2],[7,1]],[[7,7],4]],3]
[[[[7,2],4],[[4,7],[2,4]]],[1,[[6,2],4]]]
[4,[[0,4],5]]
[[[4,6],[0,[8,2]]],[[4,[8,7]],[[7,9],0]]]
[[[9,2],[5,2]],7]
[[9,[2,2]],4]
[[[6,2],[[4,3],[3,9]]],[[4,1],[[9,4],4]]]
[[[7,[4,2]],4],[[8,[9,3]],[[9,0],[5,4]]]]
[[[[4,1],[4,6]],[2,[4,5]]],[[1,[1,5]],9]]
[[[[5,2],8],6],[1,[[8,9],4]]]
[[[6,[4,2]],[6,[5,5]]],[0,3]]
[[7,[5,[7,0]]],[[[7,2],0],[[7,3],8]]]
[[3,[[2,3],[2,8]]],[5,7]]
[[[[8,0],[6,4]],[[3,7],3]],[[[7,3],[9,8]],[[8,0],8]]]
[[2,[5,2]],[[[0,9],[4,1]],[[8,8],4]]]
[[[[4,1],[6,5]],[[2,7],[5,8]]],[[[7,1],[2,3]],2]]
[[3,5],2]
[[9,2],[[6,[1,9]],[9,5]]]
[[4,[3,8]],[[4,[0,3]],[1,1]]]
[[[6,[0,7]],[[0,4],[6,1]]],[[8,5],[[5,2],[7,2]]]]
[[[[8,8],[6,3]],[[0,2],[6,5]]],[[[7,6],[5,4]],[4,[7,1]]]]
[[[[7,6],[5,8]],[6,1]],[0,[[0,8],9]]]
[[[6,[2,2]],[5,2]],6]
[[[7,9],[[1,5],8]],2]
[[[3,3],[5,6]],[[3,[3,6]],[2,[5,9]]]]
[[[[0,8],[0,1]],[[8,6],4]],[[0,[1,3]],4]]
[[6,[4,4]],[4,[0,4]]]
[[[3,4],[4,1]],8]
[[0,[[4,6],[5,1]]],[[0,[4,3]],[6,9]]]
[[[0,7],2],[[4,9],[1,6]]]
[[1,0],[[[4,9],9],[[5,4],9]]]
[8,[[[1,4],[5,5]],[1,[0,9]]]]

10
day18/data/testInput.txt Normal file
View file

@ -0,0 +1,10 @@
[[[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]]]

162
day18/part1Instructions.txt Normal file
View file

@ -0,0 +1,162 @@
--- 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?

1115
day19/data/input.txt Normal file

File diff suppressed because it is too large Load diff

136
day19/data/testInput.txt Normal file
View file

@ -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

366
day19/part1Instructions.txt Normal file
View file

@ -0,0 +1,366 @@
--- 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?

102
day20/data/input.txt Normal file
View file

@ -0,0 +1,102 @@
##.....##.#.#####.#...###...#.##..#....##..#.##.#.#....##.....#.##.##.#.#.#...#.#.#.###.##..#.#.#.#..#.##.#...#..#.#.#..#####.##.#..#..##.#..#.#...#.....#.###..#..#####.##...#..##..##...#.#...##.##..##...##.##.#......#...##.##.#####.#....####....######.#.#.......#.############.###..#..#......####......#..##.####.##....#..#.#.###..#.####.####.#.##.##.##..###.#..#.......#....#..########....##..##.#...#.#.###.###.###..#..#.###..#....#.###..#.##.##..###.#.#####....###.##.###.....#######........#.#.##...##.#....
..##.#.#..#..##.###....######.####.....#.#..##..####......####...##...#.##..##.##.#.####.##.#.##.#.#
#.#####.#.#..#.#...##.......#.#...##.#..#.######....#.#####....####...##..##..#.#####..#.##......##.
....#..#...#...######...#.#.##.##.####..####....####.##.......#..##.#.##..#.#..##..#.##...##...#.#..
.#..#####..#..#..#.#.....#..###.###.##.#..#....#..#...#....#####...###.....#.##.####.#######.##..##.
###.###...###..##.##.######..####.#.###..#....####....#...#.##.#.#....#..#....#.#.#.#.#.......#..###
.#.##.#.#####.....#...##.##..##.##...#####....#.##.###.....##.#..#.######.....###...#.###....#...#.#
##..##.##...#######..#..#.###.##.#.###..##.#.#.#..#..#....##.#..###....#..##.#..#.#....##.##........
#..#......#.###.#####.##..#....#...#.#.#.#.###.##.##..#.#.##.#...#.##..##....#######.######..##.#.#.
.###.....#....###..#.#...##...#.#.####.##.###.#.##..##..###.#.##.####..##.....##....##.......#.#.###
..#.....#####.#.#..##..##..#.###..#.##.#..#.####....##..####.###....##.##.#.#...#..###.##......#####
#..#..####.#.#...#..#...#######.#......#.#.#..#.##.#......#......#.##.####.######....#####..##...###
.###.#...#..####.##...#.#####.##.#...#.#...#...#.#.##.###..#.##.###..#.##...######.#.#.##..#.##..###
####.#.##....#.#..#########.###.#.###.#..#.####.#..##.##..#.#.#....###...#..#..###..##...#..#.....#.
....#####.#..##.....###..#..#.##...#####..##...#...#.##.###....#..####.##.#####.##.#..##..##.#..#.#.
####...#..#####.#..#######.##.#.####...#####.#.#.##....#.###...#.###.##...#...##.##.##.#.#.....##.##
##..##.##.#.#..##..##.#..#.#..#.##.###.#..#..##.#..##..##.##.#......#.##..##.##.##.....##..#.#...###
#..#.#.#.#####..#.##..##....#.##.#.###.#.#...##.###.#..##.##...##..###.##...##.####...##.#..##..##..
####....##.#.#........###..#..####.###..#.#.#....#####.#.#...#.##.####.#..#...#..#.#...#.#...#.##.##
#..#..##.##..#....#...#.#.....#...#...##.....####.#.###.#.#.####.#..#.#.#...#.##.###...##.#.##..##.#
##..##..#.###.####.#####.###..#..#.....####.#..#.##.#####.##.#...##...###.######.#.#...#####.#..#...
#...##.#......#####..##..#.....#..###.#.....##.....#####....#.##.###...##.####.#.#...#.##.######.#..
##.#.###.##.......#.##.####..######...######...####.#..######....##.#.......####...###..##.##...#...
#.....##.#####.####..#.##.#.#.....##.#..#....#.....#.....#.#...#.###.#.....#####.#.###..##..##..###.
#.###..######..#....#...#.#.##..#.....#.###.....#..#.##..#..#.##....#.#..#..#..####.#.##.....#.#.###
#..##..#...##..##........#...#....###.###.#.########.#..#.............#....####..#..##.#.##.#......#
.###..#####........##..##.###.##..#.#.#.####.#..##.##.#...#..####..####..##.##..#.#.#.#......#.##.#.
#.##..##..######....#....##.....#...##..#.#.......#.##.#####.###..##...##.##.#..##.###...##########.
.##.########.##..###....#####.###.###.#.#.##.#.#.#..##.#.#..#.##..#....#.####..###.##..###.....##.#.
..##...#.###.#.#.#...#.##..#.#...#..##..##.##..#.#..##..#.##..##.###.##..##...#.###..##...#..#.#..##
.#.#.####.###.#.##.##.#.###.#.#....##.#........#..##..##..#...##..#.#.###.#.###..#...#.#.##.##..##.#
#.#.####.#.##...###.###.#...#.###.#.#.....#..#.##.#...#.#..#.#.##...###..###.#..#.###.#.####.###.#..
##..####...#.#.####..#..#...###.##.###.##...##.#.#..##..#.###.#.##.##.#..#.###.#..#######.#....#.#..
.#.#.######..##.#..###.##.#....##....#.#..###.....#.##...#..#...#.#.#.#.##....##....####....#......#
.#.#.#.##.###...##.#...###.#....#.#.#....##...#.######.#.#.#####..#..######.#.##.#.##.....##.####.##
..######...##..##..#.#.#.##.......##.#.#...#.#####...######..#######...####..##...#.##.##.#..#...#.#
##..#.#.#..##....#.##....#.....#.#####..#.#.#.#.#.#####....#..###..###.###...#...######...##..#.#..#
####.....##...##....##.##.#...#..##.#..###.#....#...###...#..######...####.###..##......##..###.##..
##.####...#.#.#.#..#..#.#.###..##.#....##.##..#..##........##.##.####.##.#.###.#.#....#####.#.....#.
#...#.....###..#..###..##..#.#..#.###.#..#####.#.###..###..#...##.#..##..#...##...#.#.###.#.#.##.###
##.#...#....##.########..##....##..###.#....###.#.#....#...###.....###.#.##.#..#####......###.#.#.#.
###.###.#...###..#.##....#.#.#.........#.#####.#.#...#######.###.#.#.#..#.#...#..##.#...###.#...##..
.####.###.#..#.###.#.#.######..#####.#...###..#...###..#.########.#.#.#..####..##.###..#..##..##....
#..##.#.#...####.#..#..#..###.##...#####..#.###......#..####.####.##..###.....###..#....#.#######...
###..##.#.#.#..##..##...#..#.#......#..####....#.##..#.##.###...####..##..####...#...###...##..#.#.#
##.##..#....###.##......#.#.##.#.###..##...##.##.#....#.#.#.###....##..#....#.########...#.....##.#.
#.#..###.....#######..#.###....####...##......####..#...##....#..####.#....##.#...#....##.###.##....
#....######..##.##..##.###.....##..#.....#....##...#....###.....##.##...##.#..##.####.#..####.##.#.#
.#.#....#..####..#..#.#...#..#..###..#........###.##...##.##....#.#..#.##..#.##...#####...#..#####..
.##..####..##...##.###.#..####...#....#..#..##.#...##...#.###.....#.#..######.#.#####..#####..######
.#...#.#..##.#.##..#.#.#...###..#..#....###.########..######.#.####...##..#..#...##.####...#.#######
.#####.##.#####.#.#.##.#.#....#..###.#..##......#####..#.##.#########...##..###.######.....#.#.####.
##.#.#.#.##..##.##...#.....#########.##.#.......#..#####.#..#.#.#######...#..##.#..###.#####...##.##
##.##...###.###...#..##.#..#.##.##.....##.#.#.###...##.#.##..#.#.#...####..#..###.####..#...##.##.#.
#...#.#.#..#.##..#..####.#..###.#####...#..#.#..#####.#..#.......#..#.....#.#.#.#.#.##.##.###....#.#
....##..#..####.##..#.#...#####...#...###.##.#.#...##.##.##..######......####.##.#..#.##..##...####.
##...###..#.##..##..#.##...#.#.####.####..#.#.###..#.#..##.#...#.#.####..#.#.##.##.#.###.#.###.#.#..
#.#.#.#..#######.#....#..#.#.####....##...##.###.####.####.#..#..##...##..#..##....#...#..##.####...
.#####.###.##.##..##.##.##.#.##...##..#..##...#.#.##.#...####..#####..#.............###..#..#..#.#..
.##..##..###.##.##.....#...#....#..#..#.#######....#...#......##.###..#....#.#.####.#....###..##..#.
.##.#.###......#.###..#.#..#.##.###.#.#..#.#.##......##.#..##.###..#.###.##...##.#.........###.#.###
.#.#.###......#..#####.###..#..#.##..........#..##.###.#.##.#..#.##.#.###.#.###..#.#...#.###..###...
.###.####.##.##.###..#.#..###..##..##....###.###..#...###...#.##.#...#.#.##..###.##.##..###.##....##
###.########.#.######..#.##.#.#####.###...###.###.#####.###..#...#.###..#...#..#.###.#......#......#
.##....###...##.####....#....#..##...#....###..#..#..#...#...#..##....#####.#..###...##.####....###.
.....#..##...##....####.#..#.#.##..####.#####..###...###.###..##..#...##.....#.#.##...#.....#.####..
.#.###.#.#..#.####....#.#.##..#.####..#...#.#.#.#..#..#.####.###....#####.#..##..#.#..##.#.####.#.#.
#.####.#.....###..###.#..#.####.#..#.#.##.##..##..#.#.#..##...#.####..#.###...#....#.#...#.#..##.#..
.#.####...#.#.#..###.##..#.#...##.##.#.....######...#....#.#.##.....###......##.#...#.###..#....###.
..##.###......#.##...###.#...######..##.#.#.#.#..#####.##...#......#....#.####..#..#..#.#.#.#..#..##
#.##.##.#.##.#.#..#.#.#..###....#####..#.#####.####.##.##.#.##.#..#.#.#.#.###..##.##.#####..##.#####
..#.#..##.#.##.#..###..##.#.#..#.#..#.##....#....##..#.#..#.#.##.##.#.#.#..##..###..##.##.#.###.####
####.####..#..#.#....##.#...##....#.######...#.##.....#.##..#####.#####..##..#.####.#.##......#.#...
.#####..##...#....#.#..#.#.##.#...#.#..#..###.#..#.#..#..##.#.....#.####.#.#...###..#..##.##......##
###.#.....###...###########.##.##..#....##.#.####.#.#.#.....#...###.#.##..#.#.#...###..........###.#
#.#.##.##..#..#.##.#..##.#.#.####..###.#.#..###.#.#.###..###..#.##...#..#..#.#...#...#..##..#..###..
..#.#####.###..#.......#..#.####.#.######....#.##.##.#..#..#####..#...#.##.##.##..#...#####.##..#..#
##..##...##...#.####...#.#....##..#.....##.###.####.##..###..#.##..#..##..####....##.#...#.####.#..#
#.#.##...####..#.##....##...#.###..##....##.#.#.....###...####..###.###..#...##.###.#.#.#.#....#.##.
..####.##..##.#.....##...#.#.##.#.....#.#.##..##.##..#.##...##....#.#...###..####.#.#######..##.#.##
#.....##...#...#...#.##.#.####.###..#.#..###.#.#..#######...#.##.###.#.###.#.##.#.##.....#.#...#.##.
#..#####.....#..#..###.#####..##.##....#.###.##.#.#..##...###...#######.##....#...###...#####..##..#
#..############.##.####..#..#..#..#.####........#.###.###..#.######...##..####..###......##.#.#..#..
##.............###.#.####....##.##....#.#.....#.#.###...##.##.#.#..###.##.##..#.#.#####..#.#.#....##
.####...###.#.###.#..#.#.#.####.#......#..#..#.#...#..#..#....#.##..##.#..##.#..#....#..##.#..##.#.#
###.#..#..###.#...#....###..########....##....#....#.###.#.##...###.#.#.#..##..#.##....#.######.#.#.
#.###....#.##.#.#...#.##.###.##..#..###.##...####..#..#..#.####.#..#..#..#.###....#..#.##...##...###
#..#.##.#.#.#...#.#####.##.#..###.#.#.###........####.#####..#.##..###....#..#.#.#...#.#.#..#.#####.
#..##.##.#####...##...##.##..##.#...#.#..#...#..#..#.....#..####.#...#..#######....########.....#.##
#.....####.#.#.#..#.##..#.#.#####..#.#..######.#.#..#...#..#....#.##.##..##.#.###..#.##...##.#...##.
.###.#..##.##....#.##.#..#.##..####.......##..##.##.#####.###.##.....#.....##.###.#.##.#.#.##..#..##
##....#.#.##.###.#.##.#####.#..#####.#..#####.##.#..#..#..#####.##.###.#..###...#.#...#....######..#
####..#..#..#..######...#####..#..#.#...#.##....###...#...##......#...#####.##.#..#.#.##.#...##.##.#
####...##...#..#..##..#.#....#####...#.#....######.#.#.....#...##..##.##..##...##.###.....##....##.#
.#.####.#..##..####...#.##.##.##..#####..##.#.#..##....#..#.#.####..##.##.#.###.##..####......##.#..
...#..####...##.##.#..#.#....#######.####.#...###....##.#...####.#.###.####.#.#.##.#.......###.####.
.......#..#..#.#..#..#...#.#####.#.#..####..#..#...##..#.#.####.#...#.#.#.#.#.#...#.#.##.#..#.#.####
...###.#...#..#.#.#.....##.##.#.#..##.#......#.#######.....#..###.#####.##..###.#..#.#######.#####.#
.####.#..#.#.###...#..#####...#....##..####..#..#######.###.##.##..######.###..##...#####...#.##.#.#
#..##..####.#.#.#..#.####.###...#..###.#.##.##..####..###.####.....#..#.#.####...#.#.#.##.##..#.#.##
..#.###.#...###..#...###.###.####..##..#.#...##.#...#..#....#####.#####..##.####..##.##.##..#...####

7
day20/data/testInput.txt Normal file
View file

@ -0,0 +1,7 @@
..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..###..######.###...####..#..#####..##..#.#####...##.#.#..#.##..#.#......#.###.######.###.####...#.##.##..#..#..#####.....#.#....###..#.##......#.....#..#..#..##..#...##.######.####.####.#.#...#.......#..#.#.#...####.##.#......#..#...##.#.##..#...##.#.##..###.#......#.#.......#.#.#.####.###.##...#.....####.#..#..#.##.#....##..#.####....##...##..#...#......#.#.......#.......##..####..#...#.#.#...##..#.#..###..#####........#..####......#..#
#..#.
#....
##..#
..#..
..###

105
day20/part1Instructions.txt Normal file
View file

@ -0,0 +1,105 @@
--- 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?