2021 Day 19

This commit is contained in:
Akumatic 2021-12-19 20:56:53 +01:00
parent ddceb28761
commit deffbfcde9
8 changed files with 1431 additions and 1 deletions

396
2021/19/README.md Normal file
View File

@ -0,0 +1,396 @@
# 2021 Day 19: Beacon Scanner
Copyright (c) Eric Wastl
#### [Direct Link](https://adventofcode.com/2021/day/19)
## Part 1
As your [probe](https://adventofcode.com/2021/day/17) 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?**
## Part 2
Sometimes, it's a good idea to appreciate just how big the ocean is. Using the [Manhattan distance](https://en.wikipedia.org/wiki/Taxicab_geometry), 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?**

166
2021/19/code.py Normal file
View File

@ -0,0 +1,166 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2021 Akumatic
#
# https://adventofcode.com/2021/day/19
class Scanner:
def __init__(self, id: int) -> "Scanner":
self.id = id
self.x, self.y, self.z, self.orientation = None, None, None, None
self._beacons = 0
self.transformations = {x:list() for x in range(24)}
self.distances = {x:dict() for x in range(24)}
self.positions = None
def get_position(self) -> tuple:
return (self.x, self.y, self.z)
def add_beacon(self, beacon: list) -> None:
self._beacons += 1
# beacons and their transformations
for i in range(24):
self.transformations[i].append(self._transform(beacon, i))
# distances between different beacons for each orientation
for t in range(24):
self.distances[t] = list()
for i in range(self._beacons):
for j in range(i, self._beacons):
if i == j:
continue
a = self.transformations[t][i]
b = self.transformations[t][j]
dist = (b[0] - a[0], b[1] - a[1], b[2] - a[2])
self.distances[t].append(dist)
def set_position_and_orientation(self, pos: tuple, orientation: int) -> None:
self.x = pos[0]
self.y = pos[1]
self.z = pos[2]
self.orientation = orientation
self.positions = [[self.x + beacon[0], self.y + beacon[1], self.z + beacon[2]]
for beacon in self.transformations[orientation]]
self.distances = self.distances[orientation]
def _transform(self, beacon: list, t: int) -> list:
x, y, z = beacon[0], beacon[1], beacon[2]
if t == 0: return [x, y, z]
elif t == 1: return [x, -y, -z]
elif t == 2: return [x, z, -y]
elif t == 3: return [x, -z, y]
elif t == 4: return [y, x, -z]
elif t == 5: return [y, -x, z]
elif t == 6: return [y, z, x]
elif t == 7: return [y, -z, -x]
elif t == 8: return [z, x, y]
elif t == 9: return [z, -x, -y]
elif t == 10: return [z, y, -x]
elif t == 11: return [z, -y, x]
elif t == 12: return [-x, y, -z]
elif t == 13: return [-x, -y, z]
elif t == 14: return [-x, z, y]
elif t == 15: return [-x, -z, -y]
elif t == 16: return [-y, x, z]
elif t == 17: return [-y, -x, -z]
elif t == 18: return [-y, z, -x]
elif t == 19: return [-y, -z, x]
elif t == 20: return [-z, x, -y]
elif t == 21: return [-z, -x, y]
elif t == 22: return [-z, y, x]
else: return [-z, -y, -x] # t == 23
def shared_points(scn_a: Scanner, scn_b: Scanner) -> tuple:
result, orientation = 0, 0
for t in range(24): # transformations
tmp = [distance for distance in scn_a.distances[t] if distance in scn_b.distances]
if len(tmp) > result:
result = len(tmp)
orientation = t
return result, orientation
def get_points_to_distance(scanner: Scanner, distance: list, orientation: int) -> list:
result = list()
for i in range(scanner._beacons):
for j in range(scanner._beacons):
if i == j:
continue
a, b = scanner.transformations[orientation][i], scanner.transformations[orientation][j]
dist = (b[0] - a[0], b[1] - a[1], b[2] - a[2])
if dist == distance:
result.append([a, b])
return result
def calculate_position_orientation(scn_a: Scanner, scn_b: Scanner, orientation: int) -> tuple:
mapping = {dist: get_points_to_distance(scn_a, dist, orientation)
for dist in scn_a.distances[orientation] if dist in scn_b.distances}
a, b = None, None
for key in mapping:
if len(mapping[key]) > 1:
continue
tmp = get_points_to_distance(scn_b, key, scn_b.orientation)
if len(tmp) > 1:
continue
a, b = mapping[key][0][0], tmp[0][0]
return [scn_b.x + b[0] - a[0], scn_b.y + b[1] - a[1], scn_b.z + b[2] - a[2]], orientation
def find_scanner_positions(scanners: list, shared_beacons: int = 12) -> None:
done = [s for s in scanners if s.get_position() != (None, None, None)]
queue = [s for s in scanners if s not in done]
while queue:
a = queue.pop(0)
add = True
for b in done:
shared = shared_points(a, b)
if shared[0] < shared_beacons:
continue
add = False
a.set_position_and_orientation(*calculate_position_orientation(a, b, shared[1]))
done.append(a)
break
if add:
queue.append(a)
def manhattan_distance(a: tuple, b: tuple) -> int:
return sum(abs(b[i] - a[i]) for i in range(3))
def read_file(filename: str = "input.txt") -> list:
with open(f"{__file__.rstrip('code.py')}{filename}", "r") as f:
lines= [line for line in f.read().strip().split("\n")]
scanners = list()
cur = None
for line in lines:
if line.startswith("--- scanner"):
scanners.append(Scanner(int(line.split(" ")[2])))
elif line == "":
continue
else:
tmp = [int(x) for x in line.split(",")]
scanners[-1].add_beacon(tmp)
scanners[0].set_position_and_orientation((0, 0, 0), 0)
return scanners
def part1(scanners: list) -> int:
unique_positions = list()
find_scanner_positions(scanners)
for scanner in scanners:
for pos in scanner.positions:
if pos not in unique_positions:
unique_positions.append(pos)
return len(unique_positions)
def part2(scanners: list) -> int:
max_dist = 0
for i in range(len(scanners)):
for j in range(len(scanners)):
if i == j:
continue
dist = manhattan_distance(scanners[i].get_position(), scanners[j].get_position())
if max_dist < dist:
max_dist = dist
return max_dist
if __name__ == "__main__":
vals = read_file()
print(f"Part 1: {part1(vals)}")
print(f"Part 2: {part2(vals)}")

690
2021/19/input.txt Normal file
View File

@ -0,0 +1,690 @@
--- scanner 0 ---
-862,834,-491
-704,853,778
-577,-475,-324
707,862,-788
-830,-538,785
-72,-45,-21
-923,797,-524
579,-736,817
764,896,-611
-897,-542,748
567,595,938
-772,762,903
-583,-519,-525
-569,-609,-339
358,610,931
477,-769,705
-44,89,156
483,691,867
556,-378,-311
-810,-589,711
599,-282,-259
-895,949,-416
-743,681,734
768,844,-655
696,-431,-275
569,-720,811
--- scanner 1 ---
530,-693,-485
-712,901,-567
-268,579,650
-218,531,682
-683,911,-609
-360,-633,332
-326,-529,-536
-279,-539,367
117,123,88
398,-801,850
-781,919,-589
510,486,-477
-6,45,-32
847,411,391
426,-765,-500
451,-809,804
462,-519,-507
541,632,-504
708,383,465
884,393,572
-324,-537,-748
-329,625,623
-362,-607,-689
466,-815,705
558,559,-632
-386,-503,449
--- scanner 2 ---
322,-539,862
380,688,-603
-829,-746,-383
-541,600,425
464,832,615
-895,-621,384
-844,-603,542
322,-332,919
-587,414,395
266,802,-621
-831,-681,-349
393,654,660
-556,493,-382
473,781,-677
-33,86,47
-448,468,-333
-148,-38,129
527,-494,-495
-871,-598,519
425,-482,-526
-574,580,461
444,723,508
-863,-637,-485
-609,501,-257
235,-363,859
566,-392,-533
--- scanner 3 ---
-597,741,515
617,684,797
757,719,-558
173,-16,29
635,570,683
743,-612,536
846,601,-516
540,-647,-464
-490,-635,-690
-716,-638,289
476,-516,-447
896,767,-543
-2,-113,-75
-409,-597,-644
-495,708,403
-505,692,409
595,-467,-478
705,-510,497
-507,-623,282
-752,619,-401
-694,604,-605
712,-600,638
-591,-719,353
-747,670,-642
561,663,590
-395,-540,-582
--- scanner 4 ---
-643,-764,-348
600,-923,-760
448,-446,651
764,701,687
-676,455,-371
-658,498,-276
-492,-738,-306
-589,831,677
327,635,-705
760,713,904
365,768,-663
-615,-357,709
479,-860,-771
-489,775,542
-10,-38,179
-585,-907,-317
-540,819,643
-658,377,-302
525,-401,682
-592,-564,672
97,-66,-3
502,699,-669
540,-566,721
717,780,742
560,-782,-702
-566,-368,734
--- scanner 5 ---
-723,394,952
-717,-670,-784
-732,-564,-812
493,456,796
23,49,150
700,-789,-355
602,558,830
907,-846,-355
618,-311,862
-370,-535,609
641,-446,838
876,-786,-268
847,606,-599
-738,616,924
-460,643,-463
558,422,798
-780,491,844
757,599,-458
158,59,-7
-518,-421,583
-528,658,-598
745,568,-560
-333,-418,588
-737,-749,-755
-414,557,-546
636,-469,811
--- scanner 6 ---
249,-387,489
679,295,-603
9,-95,-124
658,502,-547
-804,-802,-875
-895,-916,381
-617,556,-729
-515,595,-691
378,-580,-967
-182,-49,-34
370,-527,-842
-929,-739,324
-724,739,605
-643,803,730
703,689,509
-760,-834,-739
-877,-783,320
687,683,519
-605,454,-698
-869,-800,-841
398,-403,392
-628,810,521
345,-419,-891
345,-439,532
565,409,-621
736,577,611
--- scanner 7 ---
564,668,522
-612,-659,596
-443,-688,677
-641,561,-854
275,406,-732
-598,-813,-627
-35,26,-128
625,-552,-501
479,464,-717
-561,-746,-623
516,411,-783
-96,104,45
-479,567,606
-535,653,-805
648,-785,538
653,-736,574
-529,663,-821
-568,-620,768
789,-676,523
656,-614,-531
-635,-726,-674
-408,651,510
-415,442,525
494,-605,-576
456,763,427
518,749,484
--- scanner 8 ---
-738,512,-716
521,848,482
-723,440,-820
777,-815,-403
-813,-642,488
533,-616,643
577,492,-266
-685,-618,566
644,-853,-361
-773,-620,-364
-778,-705,453
-625,786,365
571,522,-440
-914,-580,-306
-620,683,485
606,-486,686
708,-678,-397
298,906,488
-103,104,12
663,-570,542
370,925,499
35,-40,106
556,519,-420
-716,686,-784
-851,-701,-295
-656,809,383
--- scanner 9 ---
-604,756,-583
15,-28,100
777,-397,-447
-415,665,665
776,666,-448
803,-417,-429
669,784,487
-484,-464,847
-370,642,729
-508,821,-480
-577,842,-587
681,558,-543
719,604,-462
-342,748,706
800,801,423
-704,-507,877
487,-456,452
-608,-570,-550
733,-545,-487
-644,-554,-304
616,-481,435
-689,-624,-471
849,770,542
-565,-412,858
518,-530,383
--- scanner 10 ---
-406,-554,-430
306,696,586
-915,611,-441
-572,-704,533
-378,-546,-543
-794,503,-494
820,-386,-669
-88,56,114
-684,519,442
-424,-744,489
-815,548,368
-825,481,449
447,805,601
577,-729,547
579,-391,-720
-922,493,-524
439,634,-468
601,625,-513
-407,-552,-540
616,-444,-654
531,-648,585
470,572,-438
639,-743,490
-444,-762,463
442,756,637
45,-54,-48
--- scanner 11 ---
855,649,-662
21,-57,35
-539,596,-687
578,-603,546
-685,623,-718
-727,-675,-327
515,-531,646
464,770,630
595,696,601
835,675,-680
-724,-575,-469
-612,468,-670
628,-817,-638
-734,-759,-529
682,-736,-559
579,-555,677
-461,-666,467
454,689,563
698,-772,-805
-351,730,898
-630,715,894
707,605,-622
-478,683,926
-411,-741,610
-399,-672,654
--- scanner 12 ---
-641,-637,-724
715,-482,283
638,805,-673
443,702,324
-540,-553,319
-736,-732,-616
500,720,-626
-722,-675,-678
647,-391,408
686,-563,452
763,-585,-813
-624,-649,248
-601,648,-526
380,786,329
-116,84,12
-704,552,-461
703,-636,-949
-17,-63,-113
-427,387,270
641,798,-620
-334,446,313
306,700,304
-415,-634,255
812,-621,-808
-597,621,-440
-421,325,232
--- scanner 13 ---
544,-575,-383
403,-507,592
443,-524,-427
559,869,572
-394,424,790
-466,-598,517
588,729,-501
-804,292,-567
-420,-701,610
-470,-711,-747
434,-336,606
-762,330,-434
-418,509,730
-365,688,792
327,-364,623
482,820,724
-41,-1,-136
-375,-693,-704
-401,-693,-825
578,-624,-371
805,725,-489
643,682,-422
-496,-742,494
526,785,718
37,-111,18
-768,467,-503
--- scanner 14 ---
-663,806,-387
-932,598,870
-810,-693,-584
642,543,-574
-699,855,-392
14,103,171
441,514,756
-851,531,880
655,-670,706
574,-591,652
543,-554,-760
610,-837,636
474,-661,-739
570,-558,-674
-811,-694,479
-64,47,-8
-753,-679,-522
-837,-712,499
393,645,755
369,614,819
-715,-598,-476
-767,-654,627
720,684,-580
-714,746,-251
-858,569,739
727,681,-527
--- scanner 15 ---
762,678,-549
-394,887,725
660,-759,-447
-332,-718,-360
-457,-376,452
774,634,-480
509,-729,495
-417,905,694
744,-713,-295
88,-42,127
695,362,875
-402,-680,-249
-348,-822,-320
-297,782,-229
543,394,907
471,-835,595
383,-819,434
712,821,-474
822,390,922
-355,788,-452
-437,-420,666
-278,771,-301
-520,785,689
648,-694,-471
-541,-463,520
--- scanner 16 ---
778,567,812
-564,-801,-832
489,-850,372
-294,634,492
-406,-696,599
-498,-770,-842
0,-30,-52
-281,731,-641
841,389,-654
-309,500,484
735,340,-562
-495,590,498
-550,-701,492
-245,678,-781
590,-751,372
-551,-655,492
510,-418,-851
815,571,745
433,-574,-870
409,-474,-805
-424,-822,-726
741,520,725
-229,827,-684
476,-876,341
847,373,-664
--- scanner 17 ---
485,-608,-825
682,-272,597
-69,108,0
-578,467,670
669,-548,-835
585,-750,-828
646,-518,581
512,590,-554
-695,-455,606
-623,863,-371
-601,932,-353
603,890,739
-713,-359,-786
522,879,687
-480,415,621
-449,484,695
742,909,644
-739,-415,754
-765,-397,734
-581,834,-361
727,-439,527
516,508,-603
-686,-390,-640
84,130,-132
-558,-407,-713
560,663,-530
--- scanner 18 ---
-368,-707,-755
-612,-646,745
-366,-699,-543
764,-553,503
-513,701,-505
-583,609,-625
784,-550,488
-549,385,642
-766,389,654
-544,624,-460
420,-717,-784
384,-471,-791
48,-106,-24
909,670,-919
843,822,576
-604,432,721
938,-523,509
807,647,640
-480,-672,772
-499,-730,754
488,-543,-806
-404,-629,-602
801,784,709
840,589,-841
898,549,-982
--- scanner 19 ---
-579,-564,-538
464,-452,-739
-622,-924,801
-734,-491,-490
-602,-916,703
564,-449,-881
825,585,590
852,559,458
-704,514,-442
-522,602,382
-707,-637,-521
-463,532,344
589,708,-960
-675,524,346
-726,688,-510
539,-747,532
491,-723,459
-711,760,-406
583,678,-786
834,501,477
-22,-107,-79
495,-674,377
-644,-906,732
648,-442,-679
568,681,-806
--- scanner 20 ---
39,-9,129
794,-308,667
-731,698,375
-343,-740,-740
914,622,864
799,-357,631
935,-417,682
89,155,-30
659,653,-723
612,-620,-674
-318,-814,-654
-297,-405,528
659,-482,-759
773,688,794
-782,468,-367
950,698,900
741,698,-593
-587,809,411
-730,399,-297
606,-479,-752
-466,-434,609
542,735,-642
-741,845,364
-338,-677,-656
-773,416,-446
-422,-473,437
--- scanner 21 ---
-649,721,598
-797,830,-374
727,628,356
595,602,329
820,-850,-470
669,-704,642
-744,-406,617
-602,-409,717
-373,-348,-647
498,572,-741
880,-650,-436
514,-631,686
-542,-399,533
725,-750,-400
625,640,-769
596,-680,690
-502,-478,-672
-651,856,-478
-726,757,-430
621,611,-729
-490,-299,-681
-823,751,592
614,544,347
79,103,33
-669,724,613
--- scanner 22 ---
-378,838,603
460,-548,-742
449,763,-452
-328,-577,-732
707,286,584
-364,-730,-654
-388,408,-758
-469,710,573
-543,-707,584
-281,326,-722
396,809,-460
-473,-827,676
67,-1,-160
949,-413,645
-504,-872,599
424,-541,-496
938,-350,524
-326,-789,-724
807,267,645
-362,291,-628
880,-491,564
464,664,-446
796,326,698
528,-526,-568
-457,809,454
--- scanner 23 ---
725,755,-476
414,-294,-594
-713,-710,-436
-526,679,-460
449,-322,-418
440,-365,-529
759,458,470
271,-751,909
-712,746,530
744,462,749
-669,-789,-394
-610,-691,632
-502,710,-396
-634,-626,644
-643,702,518
799,726,-345
-637,889,580
718,793,-335
432,-767,821
712,430,597
332,-661,783
-458,-645,548
20,9,-30
-574,810,-459
-729,-742,-410
-141,47,79
--- scanner 24 ---
461,-491,-507
-333,-606,522
-340,-522,320
-528,749,680
817,-547,241
787,-541,415
623,746,759
-716,883,-905
-382,776,711
500,686,-408
797,768,691
-656,-588,-617
-437,868,-901
-606,-513,-474
523,655,-390
-589,836,-933
384,-340,-524
790,-526,395
869,753,795
403,-268,-513
626,650,-510
-455,621,663
-343,-422,462
121,75,-77
-668,-519,-661

2
2021/19/solution.txt Normal file
View File

@ -0,0 +1,2 @@
Part 1: 308
Part 2: 12124

33
2021/19/test_code.py Normal file
View File

@ -0,0 +1,33 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2021 Akumatic
from code import *
def test():
scanner = read_file("test_input_1.txt")[0]
tranformations = [
[[-1, -1, 1], [-2, -2, 2], [-3, -3, 3], [-2, -3, 1], [5, 6, -4], [8, 0, 7]],
[[1, -1, 1], [2, -2, 2], [3, -3, 3], [2, -1, 3], [-5, 4, -6], [-8, -7, 0]],
[[-1, -1, -1], [-2, -2, -2], [-3, -3, -3], [-1, -3, -2], [4, 6, 5], [-7, 0, 8]],
[[1, 1, -1], [2, 2, -2], [3, 3, -3], [1, 3, -2], [-4, -6, 5], [7, 0, 8]],
[[1, 1, 1], [2, 2, 2], [3, 3, 3], [3, 1, 2], [-6, -4, -5], [0, 7, -8]]
]
for transformation in tranformations:
assert transformation in scanner.transformations.values()
print("Transformation passed")
scanners = read_file("test_input_2.txt")
find_scanner_positions(scanners)
assert scanners[0].get_position() == (0, 0, 0)
assert scanners[1].get_position() == (68,-1246,-43)
assert scanners[2].get_position() == (1105,-1205,1229)
assert scanners[3].get_position() == (-92,-2380,-20)
print("Passed position finding")
assert part1(scanners) == 79
print("Passed Part 1")
assert part2(scanners) == 3621
print("Passed Part 2")
if __name__ == "__main__":
test()

7
2021/19/test_input_1.txt Normal file
View File

@ -0,0 +1,7 @@
--- scanner 0 ---
-1,-1,1
-2,-2,2
-3,-3,3
-2,-3,1
5,6,-4
8,0,7

136
2021/19/test_input_2.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

View File

@ -33,7 +33,7 @@ Collect stars by solving puzzles. Two puzzles will be made available on each day
| 16 | :white_check_mark: | :white_check_mark: | [Solution](16/code.py) | [Day 16](https://adventofcode.com/2021/day/16) |
| 17 | :white_check_mark: | :white_check_mark: | [Solution](17/code.py) | [Day 17](https://adventofcode.com/2021/day/17) |
| 18 | :white_check_mark: | :white_check_mark: | [Solution](18/code.py) | [Day 18](https://adventofcode.com/2021/day/18) |
| 19 | | | | |
| 19 | :white_check_mark: | :white_check_mark: | [Solution](19/code.py) | [Day 19](https://adventofcode.com/2021/day/19) |
| 20 | | | | |
| 21 | | | | |
| 22 | | | | |