From c62c12a21b11413ee66eee359152d34075daa0e3 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Sun, 19 Dec 2021 00:11:35 -0800 Subject: 19 --- 19/Cargo.toml | 11 + 19/input | 1105 +++++++++++++++++++++++++++++++++++++++++++++++++ 19/small | 136 ++++++ 19/src/main.rs | 344 +++++++++++++++ 19/tests/.main.rs.swm | Bin 0 -> 12288 bytes 19/tests/.main.rs.swn | Bin 0 -> 12288 bytes 19/tests/main.rs | 19 + 7 files changed, 1615 insertions(+) create mode 100644 19/Cargo.toml create mode 100644 19/input create mode 100644 19/small create mode 100644 19/src/main.rs create mode 100644 19/tests/.main.rs.swm create mode 100644 19/tests/.main.rs.swn create mode 100644 19/tests/main.rs (limited to '19') diff --git a/19/Cargo.toml b/19/Cargo.toml new file mode 100644 index 0000000..0c97bfc --- /dev/null +++ b/19/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "advent_19" +version = "0.1.0" +authors = ["Irene Knapp "] +edition = "2018" + +[dependencies] +advent_lib = { path = "../lib" } + +[dev-dependencies] +assert_cmd = "0.10" diff --git a/19/input b/19/input new file mode 100644 index 0000000..9f5fd22 --- /dev/null +++ b/19/input @@ -0,0 +1,1105 @@ +--- scanner 0 --- +645,-448,-766 +529,751,-867 +596,-483,472 +584,-612,-728 +474,-460,434 +519,-382,388 +-348,803,-533 +-537,553,429 +-294,-812,-542 +479,-471,-692 +-371,642,-453 +-318,612,-477 +-395,-304,520 +-584,541,384 +144,72,-32 +-395,-670,-544 +558,671,-929 +512,677,703 +-428,-427,552 +405,711,772 +423,630,722 +-390,-536,556 +642,620,-881 +-674,550,365 +-389,-736,-572 + +--- scanner 1 --- +-393,403,722 +643,282,-608 +351,315,563 +721,-673,-816 +355,306,639 +621,-719,700 +825,382,-598 +685,-475,-791 +-368,-959,-481 +-486,-753,361 +-486,696,-868 +-384,-661,271 +448,336,736 +-529,335,716 +542,-668,644 +87,-105,-137 +-435,-988,-672 +-36,-10,-38 +-441,-742,293 +667,-668,-722 +-650,402,705 +692,312,-657 +-526,656,-877 +-402,-874,-553 +-606,595,-896 +658,-738,740 + +--- scanner 2 --- +-502,386,-714 +-447,481,-660 +-710,431,691 +-420,-743,260 +655,418,584 +-487,447,-683 +489,-827,-821 +438,653,-769 +431,791,-690 +839,-489,706 +639,-925,-819 +868,-558,767 +-662,481,702 +548,360,670 +-529,457,646 +61,23,-129 +410,742,-710 +-417,-905,386 +-452,-834,262 +452,438,629 +608,-869,-690 +-745,-799,-676 +-690,-606,-679 +893,-495,695 +-662,-751,-591 + +--- scanner 3 --- +562,772,919 +-673,-779,-320 +799,-477,579 +769,-466,766 +-778,-788,594 +-696,-684,666 +12,-164,174 +-561,652,599 +-623,462,-553 +-619,628,532 +-786,360,-579 +779,-879,-761 +709,591,-439 +-745,515,-617 +-708,632,577 +797,-892,-635 +575,680,849 +660,617,893 +789,-461,644 +-635,-869,-324 +-631,-770,654 +146,-103,-7 +845,-834,-745 +723,540,-411 +-695,-740,-223 +675,437,-497 + +--- scanner 4 --- +568,-402,-528 +731,747,-759 +582,-463,-371 +-6,14,139 +636,-380,-382 +767,528,479 +637,447,439 +678,763,-629 +-800,-324,-524 +676,505,415 +-669,389,463 +893,-564,777 +753,-440,773 +-673,-393,-510 +667,-628,779 +-773,-776,730 +-433,585,-672 +-424,339,-644 +-444,479,-632 +-525,-343,-523 +-571,544,489 +-856,-796,879 +-783,-742,862 +620,701,-794 +-656,481,533 + +--- scanner 5 --- +56,90,-41 +-341,751,-661 +363,-837,546 +-98,7,42 +396,695,826 +-659,-454,-504 +-851,-375,-528 +-822,-315,559 +383,775,632 +394,828,684 +775,706,-750 +372,-654,549 +405,-579,-739 +-354,779,-558 +813,687,-742 +520,-748,559 +-831,-477,595 +-748,-455,-545 +507,-477,-669 +865,736,-846 +-665,690,600 +-891,-375,463 +-434,670,-568 +410,-424,-714 +-625,724,577 +-610,785,546 + +--- scanner 6 --- +743,442,600 +671,-584,-384 +-368,-399,-275 +721,359,-540 +-775,675,541 +-368,-352,-512 +674,-743,848 +-433,-415,560 +510,-623,-396 +-786,552,646 +-380,-493,699 +647,-653,-391 +-415,-389,709 +687,-827,756 +-766,613,-425 +-753,671,-345 +744,531,559 +-797,461,551 +883,368,-504 +-811,715,-419 +823,299,-408 +-386,-334,-442 +823,339,583 +-58,12,59 +588,-797,884 + +--- scanner 7 --- +-476,-516,410 +-869,-855,-731 +394,398,-696 +371,389,735 +370,478,776 +253,408,-685 +497,-917,-638 +-754,703,712 +440,-796,487 +291,286,752 +326,-941,-597 +332,-909,-547 +-492,-471,488 +427,-880,579 +-835,796,619 +526,-850,451 +-101,-42,131 +-843,264,-774 +-863,783,722 +-825,315,-711 +291,528,-715 +-729,-962,-773 +-828,424,-691 +-741,-875,-595 +-581,-595,463 + +--- scanner 8 --- +339,-571,-769 +-785,492,873 +-651,828,-325 +809,-419,513 +-565,792,-379 +-729,-452,-499 +-552,700,-295 +351,869,-659 +-702,-787,589 +477,-492,-762 +-515,-776,559 +-12,9,46 +706,590,553 +367,791,-704 +825,-374,579 +388,-551,-790 +628,593,527 +-592,-447,-469 +-580,-792,569 +-787,573,905 +699,-361,561 +-573,509,904 +635,653,597 +456,816,-580 +-568,-440,-538 + +--- scanner 9 --- +-387,413,750 +491,-575,-842 +-512,-475,-986 +-518,-567,-869 +538,-523,-955 +-380,473,742 +-667,366,-540 +-568,317,-630 +501,-500,-799 +498,690,698 +-752,-868,583 +-583,250,-491 +377,766,763 +-695,-907,651 +84,-52,-107 +-791,-929,749 +512,351,-589 +566,413,-622 +-395,307,683 +5,-184,6 +750,-738,777 +864,-841,704 +690,-831,766 +-566,-425,-860 +528,383,-825 +463,615,714 + +--- scanner 10 --- +600,-778,-693 +623,699,654 +-508,771,-532 +-563,-403,-774 +378,-950,575 +681,686,734 +-619,806,-578 +369,-788,539 +309,-890,671 +-342,301,567 +-602,-427,-832 +725,744,660 +650,-643,-732 +-574,-738,695 +527,301,-619 +614,456,-632 +648,-657,-710 +-561,641,-516 +-88,-167,1 +-324,319,637 +-472,-467,-751 +-613,-577,683 +540,497,-624 +-643,-714,688 +-389,301,804 +95,-68,-43 + +--- scanner 11 --- +646,-816,-431 +750,-791,-282 +-613,793,766 +-605,-294,-694 +-401,-736,690 +-629,761,-271 +-104,110,60 +609,505,-706 +699,-392,544 +685,442,622 +670,472,-598 +756,-340,530 +-772,842,698 +735,-405,356 +39,-43,43 +-485,-810,652 +-538,785,-333 +-736,863,842 +645,551,699 +-744,-318,-646 +-570,-283,-724 +-582,740,-441 +-615,-780,722 +589,358,725 +535,555,-559 +778,-794,-465 + +--- scanner 12 --- +-799,849,-884 +-783,743,394 +-71,-27,-106 +585,559,-634 +472,-715,-783 +-575,-520,514 +-829,921,439 +564,473,-660 +-803,686,-911 +611,572,-644 +246,-299,558 +779,438,534 +651,-805,-802 +258,-316,442 +-834,905,-938 +554,-733,-719 +-703,-640,-403 +670,428,450 +-576,-501,501 +-746,-432,-391 +15,140,-3 +-538,-599,633 +-878,872,465 +-756,-408,-415 +287,-451,543 +674,383,617 + +--- scanner 13 --- +517,-522,-501 +526,706,-530 +-627,-731,-913 +450,-643,-490 +-361,-437,668 +730,-796,434 +84,-27,-149 +-653,755,-545 +-504,426,388 +542,470,-562 +580,673,-592 +-552,435,246 +694,-736,234 +-569,804,-429 +515,496,321 +-343,-459,683 +-546,-788,-935 +552,340,344 +-521,-510,662 +722,-787,309 +518,-779,-484 +-554,665,-496 +505,453,396 +-638,-686,-845 +-498,309,296 + +--- scanner 14 --- +387,-558,836 +316,-654,-556 +692,442,-808 +406,-688,733 +-886,853,610 +-777,863,526 +-718,719,-568 +-704,-385,-698 +-548,-648,469 +722,370,515 +727,386,-862 +676,548,470 +771,419,541 +696,605,-835 +33,-46,96 +-717,-393,-596 +-130,98,-31 +-498,-565,360 +-781,908,693 +-692,732,-558 +327,-690,-333 +404,-648,-445 +417,-678,874 +-619,-500,-619 +-458,-577,384 +-671,818,-584 + +--- scanner 15 --- +-563,-421,-670 +-534,469,-754 +-453,-507,-587 +513,669,-464 +-74,132,-102 +-657,-719,740 +573,817,784 +646,584,-444 +679,828,654 +708,-431,-618 +-523,517,-704 +655,-628,716 +721,-600,722 +713,945,786 +-641,619,594 +-658,667,473 +-627,-695,793 +-619,617,608 +651,601,-556 +667,-603,-642 +-494,-513,-653 +-818,-639,763 +797,-630,817 +-579,650,-728 +594,-423,-666 +-197,24,-20 + +--- scanner 16 --- +-680,491,-653 +778,-514,459 +-446,-350,-698 +-569,589,785 +-652,539,894 +-555,-370,-701 +267,714,793 +468,916,-429 +-529,-365,521 +-633,386,-595 +810,-464,453 +744,-466,-614 +-640,499,870 +724,-330,-742 +-659,-346,418 +360,966,-457 +243,807,784 +-395,-287,-716 +-145,-8,-40 +-624,386,-694 +831,-288,-602 +786,-423,624 +281,853,744 +1,109,103 +-539,-376,380 +455,869,-511 + +--- scanner 17 --- +-638,601,-617 +-816,-827,539 +-616,587,-619 +371,705,517 +-716,-512,-583 +576,411,-419 +-597,411,503 +-655,722,-569 +559,711,603 +740,-595,-671 +647,-462,-717 +495,709,377 +682,541,-408 +-724,-553,-509 +-574,347,594 +-516,371,633 +617,-693,-735 +394,-439,688 +-99,-47,93 +311,-450,634 +716,409,-291 +-49,111,-11 +333,-596,702 +-729,-357,-496 +-832,-697,592 +-770,-862,650 + +--- scanner 18 --- +-496,390,677 +374,-516,-664 +-531,-602,489 +711,424,408 +921,-537,506 +800,469,-708 +-634,347,-327 +16,44,98 +827,-527,507 +796,-502,488 +-334,-443,-538 +-776,480,-329 +-336,-570,-509 +-527,451,692 +163,-93,141 +618,505,501 +462,-425,-726 +-550,485,732 +-619,-747,517 +478,-401,-716 +-352,-394,-586 +896,439,-798 +792,488,-746 +608,396,421 +-582,400,-316 +-534,-795,434 + +--- scanner 19 --- +654,610,588 +60,-95,-45 +412,-785,681 +631,512,481 +-349,771,665 +593,537,-644 +705,-447,-466 +-658,448,-820 +-755,-742,564 +-325,731,653 +637,-450,-339 +-723,-755,542 +-666,-454,-453 +-575,343,-765 +-491,452,-775 +-887,-838,522 +378,-727,536 +406,-675,504 +603,511,-631 +-574,-462,-447 +-434,681,736 +-565,-321,-403 +733,525,473 +-37,91,66 +619,558,-730 +763,-542,-346 + +--- scanner 20 --- +-429,655,652 +645,-496,618 +-473,-528,538 +-417,-477,617 +808,-593,596 +-847,515,-756 +849,536,-744 +757,-720,-739 +-846,-535,-388 +499,591,823 +767,658,-834 +755,-489,589 +-8,70,-74 +-399,581,462 +751,-560,-666 +-377,-458,654 +772,-738,-717 +97,139,79 +-824,-454,-445 +600,537,839 +542,594,670 +-413,654,385 +811,659,-716 +-756,-443,-490 +-727,613,-805 +-720,513,-694 + +--- scanner 21 --- +-868,-833,-776 +-782,883,-500 +-855,860,-447 +706,752,766 +-888,890,-517 +365,-710,683 +-674,565,618 +812,389,-709 +724,489,-614 +764,711,653 +-40,-36,-14 +-729,-713,-763 +-775,499,683 +-763,527,477 +419,-727,-565 +405,-699,789 +707,443,-822 +-509,-583,660 +-398,-667,595 +776,654,676 +-461,-558,683 +393,-719,929 +416,-540,-623 +-731,-722,-786 +425,-695,-746 + +--- scanner 22 --- +-561,-541,612 +684,714,402 +310,386,-663 +435,377,-671 +235,437,-635 +456,-518,-635 +-181,42,-36 +-72,-40,88 +-465,-657,682 +-469,-447,-392 +-934,385,605 +529,-695,-642 +-912,442,686 +-505,-620,663 +663,663,580 +-642,-350,-371 +-566,-354,-362 +-500,651,-458 +720,-599,547 +557,-621,644 +669,736,420 +619,-508,-645 +667,-592,651 +-489,530,-391 +-483,394,-459 +-844,487,697 + +--- scanner 23 --- +-573,-369,-818 +-777,575,718 +-543,-832,714 +-565,-856,744 +262,-592,-740 +-534,-535,-788 +-384,431,-398 +579,786,692 +557,563,-793 +-472,526,-498 +23,-77,-107 +644,770,702 +372,-579,356 +-459,-897,751 +374,-498,388 +-771,394,686 +-780,517,531 +629,459,-875 +586,-515,357 +314,-572,-606 +457,781,672 +-67,74,4 +-511,-582,-807 +-489,318,-452 +273,-572,-495 +569,477,-728 + +--- scanner 24 --- +613,574,260 +-324,-739,-476 +-549,281,-811 +843,-622,-519 +-427,495,492 +653,345,-940 +728,480,277 +-675,288,-719 +975,-580,-423 +-617,408,-814 +-318,-562,-586 +-603,514,390 +-290,-594,-534 +-484,-875,486 +-309,-909,540 +645,-799,717 +787,-832,719 +53,-102,12 +662,389,-799 +601,-809,790 +811,-600,-506 +-361,-854,418 +671,487,306 +754,395,-807 +-485,491,522 + +--- scanner 25 --- +-720,312,-561 +-788,595,661 +447,-525,-917 +-776,389,633 +-765,313,-501 +-739,-945,-618 +751,565,449 +-175,-133,-57 +523,389,-687 +-795,-588,277 +469,-506,-884 +763,588,506 +-750,-888,-568 +799,-797,771 +-823,408,-570 +416,442,-755 +-901,-605,270 +-687,530,595 +-868,-535,300 +497,-692,-923 +711,-702,671 +484,442,-641 +-770,-779,-525 +694,-910,717 +-70,45,-92 +693,678,408 + +--- scanner 26 --- +-513,827,529 +-380,-632,440 +293,843,-662 +-466,-515,-481 +-14,61,-4 +280,815,-559 +598,-390,-716 +790,-311,-692 +-471,-360,-506 +-429,-606,391 +-568,-413,-551 +678,-414,756 +548,-311,775 +-874,751,-478 +687,-391,-675 +-621,860,468 +761,805,771 +668,-273,745 +-926,800,-374 +-660,777,603 +652,808,751 +373,734,-652 +-558,-677,486 +-836,770,-470 +812,823,834 + +--- scanner 27 --- +450,687,243 +812,677,-421 +494,678,384 +715,-453,718 +-22,-26,22 +500,586,376 +-48,123,-107 +-618,903,-849 +822,761,-530 +-809,-697,418 +727,-452,-749 +-689,818,-759 +-625,-562,-962 +897,-431,-702 +-495,529,677 +-606,927,-809 +867,594,-526 +-517,497,664 +695,-529,725 +-475,365,760 +-752,-657,365 +786,-499,557 +-634,-661,-962 +835,-407,-793 +-578,-620,-857 +-727,-718,419 + +--- scanner 28 --- +694,-572,709 +454,780,-442 +-682,752,-692 +-752,-670,-637 +-422,-716,316 +-476,-829,421 +-522,-621,404 +-744,646,364 +539,717,-398 +666,782,723 +-131,6,-43 +-785,759,422 +686,922,735 +662,-753,703 +678,-377,-712 +16,91,70 +441,872,-372 +-740,728,-759 +668,-361,-647 +-899,-688,-697 +-687,669,352 +648,-366,-525 +677,676,763 +507,-630,712 +-829,732,-714 +-817,-584,-625 + +--- scanner 29 --- +-433,-640,645 +489,731,-728 +579,704,511 +-620,-643,587 +843,-358,-589 +-763,511,-428 +435,645,-764 +-437,-406,-762 +-479,594,851 +-400,-322,-827 +880,-311,632 +405,744,-636 +898,-329,562 +609,567,516 +-69,46,125 +-449,781,840 +17,158,-28 +833,-311,395 +-794,723,-445 +-407,-428,-786 +817,-376,-440 +-465,-634,464 +-795,509,-509 +-459,716,856 +739,-323,-579 +648,728,504 + +--- scanner 30 --- +667,415,-670 +668,782,587 +-404,-700,-822 +-164,177,-119 +322,-651,569 +283,-616,-456 +-517,-805,-876 +-369,733,513 +-141,7,14 +-779,862,-405 +9,101,-64 +449,-655,-486 +-726,789,-382 +260,-569,574 +-535,764,420 +-622,-503,818 +619,932,672 +294,-620,399 +-709,895,-375 +-612,-717,-776 +-808,-475,779 +-426,744,463 +589,708,657 +496,-678,-467 +735,489,-667 +-789,-453,812 +746,548,-654 + +--- scanner 31 --- +-643,659,471 +-738,713,526 +-471,768,-414 +845,-626,-536 +-667,-647,553 +-382,709,-386 +-764,-671,-524 +422,796,245 +-643,-703,686 +655,-585,584 +-677,682,511 +-686,-630,-428 +-693,-692,734 +909,-649,-627 +669,-607,586 +885,-707,-666 +-333,689,-407 +362,700,314 +25,136,-60 +-706,-585,-631 +524,664,305 +598,813,-707 +574,820,-638 +534,-568,536 +735,808,-677 + +--- scanner 32 --- +-957,-446,-753 +-440,-436,807 +304,-444,395 +613,752,-504 +676,-518,-378 +349,666,501 +632,-527,-519 +-707,782,-908 +-735,906,-915 +-948,-466,-747 +-943,-591,-707 +-423,-552,819 +626,-619,-511 +-575,-537,778 +740,684,-507 +-123,101,32 +-839,789,593 +314,-528,286 +-689,855,-831 +259,-611,391 +-929,808,414 +-857,725,511 +733,810,-599 +448,650,454 +435,640,480 + +--- scanner 33 --- +733,-484,725 +705,-475,971 +-126,42,153 +855,569,609 +-402,-720,921 +690,627,547 +-472,-707,829 +-418,716,782 +368,864,-606 +-378,586,863 +820,680,563 +-689,614,-664 +679,-467,-523 +-677,-493,-312 +-555,-513,-317 +350,799,-773 +693,-495,831 +-428,-622,766 +350,846,-536 +-742,-483,-328 +-528,575,-652 +673,-499,-704 +-2,-86,49 +682,-654,-581 +-665,545,-657 +-354,625,805 + +--- scanner 34 --- +443,448,691 +857,329,-541 +822,-700,558 +-738,348,435 +493,427,769 +-466,257,-511 +507,446,714 +811,-577,663 +911,273,-506 +605,-767,-917 +-684,-801,-827 +884,492,-537 +382,-803,-906 +-685,445,480 +-787,-913,621 +-787,-671,-846 +-707,-810,604 +494,-761,-829 +-421,435,-557 +833,-791,653 +-583,343,410 +111,-22,-114 +-492,306,-462 +26,-130,22 +-708,-721,645 +-825,-791,-816 + +--- scanner 35 --- +492,310,751 +-487,-770,770 +670,-896,629 +616,577,-692 +-504,-691,-431 +490,452,884 +-795,673,-319 +-306,-815,796 +162,-48,97 +-514,590,841 +676,-855,695 +858,-722,-751 +-569,536,746 +-454,-730,-566 +479,504,831 +-529,559,780 +802,-531,-721 +-726,577,-259 +-735,541,-421 +-456,-708,-552 +882,-692,-698 +468,587,-598 +459,590,-781 +584,-786,712 +-354,-826,746 + +--- scanner 36 --- +85,-89,-10 +637,-789,-745 +-699,285,462 +650,-641,-795 +607,534,479 +-422,-752,911 +-752,-972,-342 +-652,551,-510 +523,-762,527 +655,452,-736 +-646,637,-698 +-362,-788,711 +-603,-889,-362 +710,-759,617 +636,527,589 +509,520,-758 +533,-752,690 +-371,-780,836 +498,466,-675 +-721,303,477 +651,-916,-814 +-650,777,-574 +614,430,426 +-735,-899,-396 +-648,463,483 + +--- scanner 37 --- +-478,-931,649 +650,421,-299 +739,-924,-754 +630,555,-351 +-419,433,-606 +860,-917,-808 +130,-80,-41 +630,666,-310 +-531,-722,-523 +-673,-734,-613 +12,28,48 +-505,368,-594 +-489,-666,-603 +-401,286,-666 +971,-960,-740 +-260,709,452 +438,-512,532 +-664,-892,677 +404,-687,583 +466,-682,501 +-373,763,347 +593,373,497 +640,354,474 +427,343,536 +-645,-925,699 +-468,663,435 + +--- scanner 38 --- +-767,437,-422 +-603,498,-384 +-825,-542,-606 +-907,532,587 +465,495,-269 +-967,-441,-608 +488,-785,689 +-849,-604,850 +-626,332,-458 +549,449,675 +-743,-474,839 +-119,-92,157 +457,-465,-673 +648,-495,-617 +449,-650,639 +487,-518,-697 +562,294,762 +-814,399,541 +516,411,-221 +-891,-536,-578 +-883,-472,967 +-784,630,523 +471,-664,641 +596,382,-283 +557,490,749 + +--- scanner 39 --- +70,136,-4 +-670,751,-781 +-669,460,636 +-554,-600,-581 +735,797,-745 +868,-662,-834 +690,-707,-788 +470,562,446 +588,747,-671 +-352,-543,241 +385,-567,774 +-696,944,-725 +627,830,-806 +-504,-558,282 +-813,439,600 +-737,509,477 +362,517,402 +300,541,493 +-573,-587,-580 +-593,860,-821 +-652,-468,-543 +375,-651,665 +330,-484,669 +-369,-659,253 +819,-636,-883 +-90,92,-126 diff --git a/19/small b/19/small new file mode 100644 index 0000000..4e496e9 --- /dev/null +++ b/19/small @@ -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 diff --git a/19/src/main.rs b/19/src/main.rs new file mode 100644 index 0000000..8b13d80 --- /dev/null +++ b/19/src/main.rs @@ -0,0 +1,344 @@ +use advent_lib::prelude::*; + +use std::collections::BTreeSet; + + +#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq)] +struct Point { + x: i64, + y: i64, + z: i64, +} + +#[derive(Debug, Clone)] +struct Rotation { + top: RotationAngle, + front: RotationAngle, + right: RotationAngle, +} + +#[derive(Debug, Clone, Copy)] +enum RotationAngle { + None, + Ninety, + OneEighty, + TwoSeventy, +} + + +fn main() -> Result<()> { + let mut args = std::env::args(); + if args.len() != 2 { + eprintln!("Usage: advent input"); + } + let _ = args.next(); + let filename = args.next().unwrap(); + + let input = advent_lib::group_lines_by_blanks( + advent_lib::read_lines_file(&filename)?); + + let mut scanners = Vec::new(); + for group in &input { + let mut scanner = Vec::new(); + for line in group.iter().skip(1) { + let values: Vec<&str> = line.split(",").collect(); + let x = values[0].parse::().unwrap(); + let y = values[1].parse::().unwrap(); + let z = values[2].parse::().unwrap(); + scanner.push(Point { x, y, z }); + } + scanners.push(scanner); + } + + let (merged_points, largest_distance) = + compare_all_scanners(&scanners, false); + println!("{}", merged_points.len()); + println!("{}", largest_distance); + + Ok(()) +} + + +fn compare_all_scanners(all_scanners: &Vec>, perform_sort: bool) + -> (Vec, i64) +{ + let mut unvisited_scanners = all_scanners.clone(); + let mut visited_scanner_offsets = Vec::new(); + + visited_scanner_offsets.push(Point { x: 0, y: 0, z: 0 }); + + loop { + let mut found_match = false; + + //println!("{} scanners remain", unvisited_scanners.len()); + + for i in 0 .. unvisited_scanners.len() - 1 { + for j in i + 1 .. unvisited_scanners.len() { + //println!("comparing {} vs {}", i, j); + let scanner_a = &unvisited_scanners[i]; + let scanner_b = &unvisited_scanners[j]; + + match compare_scanners(scanner_a, scanner_b) { + None => { }, + Some((a_b_unioned_points, offset)) => { + //println!("matched {} vs {} for {} beacons", i, j, + // a_b_unioned_points.len()); + + unvisited_scanners.remove(j); + unvisited_scanners[i] = a_b_unioned_points; + if perform_sort { + unvisited_scanners.sort_by(|a, b| + a.len().partial_cmp(&b.len()).unwrap()); + } + + visited_scanner_offsets.push(offset); + + found_match = true; + }, + } + + if found_match { + break; + } + } + + if found_match { + break; + } + } + + if !found_match { + break; + } + } + + let mut largest_distance = None; + for i in 0 .. visited_scanner_offsets.len() - 1 { + for j in i + 1 .. visited_scanner_offsets.len() { + let a = &visited_scanner_offsets[i]; + let b = &visited_scanner_offsets[j]; + let new_distance = compute_distance(a, b); + + match largest_distance { + None => { + largest_distance = Some(new_distance); + } + Some(old_distance) => { + if new_distance > old_distance { + largest_distance = Some(new_distance); + } + } + } + } + } + + (unvisited_scanners[0].clone(), largest_distance.unwrap()) +} + + +fn compare_scanners(scanner_a: &Vec, scanner_b: &Vec) + -> Option<(Vec,Point)> +{ + let all_rotations = compute_all_rotations(); + + for rotation in &all_rotations { + let mut sorted_scanner_a = scanner_a.clone(); + sorted_scanner_a.sort(); + + let mut sorted_scanner_b = Vec::new(); + for point in scanner_b { + let rotated_point = apply_rotation(point, rotation); + sorted_scanner_b.push(rotated_point); + } + sorted_scanner_b.sort(); + + for a_i in 0 .. sorted_scanner_a.len() { + for b_i in 0 .. sorted_scanner_b.len() { + let a_origin_point = sorted_scanner_a[a_i].clone(); + let b_origin_point = sorted_scanner_b[b_i].clone(); + + let mut n_matches = 0; + let mut a_j = 0; + let mut b_j = 0; + loop { + if a_j >= sorted_scanner_a.len() { + break; + } + if b_j >= sorted_scanner_b.len() { + break; + } + + let a_point = point_difference( + &sorted_scanner_a[a_j], &a_origin_point); + let b_point = point_difference( + &sorted_scanner_b[b_j], &b_origin_point); + + if a_point == b_point { + n_matches += 1; + a_j += 1; + b_j += 1; + } else if a_point < b_point { + a_j += 1; + } else { + b_j += 1; + } + } + + if n_matches >= 12 { + let b_offset = point_difference(&a_origin_point, &b_origin_point); + + let mut unioned_points = BTreeSet::new(); + for point in sorted_scanner_a { + unioned_points.insert(point.clone()); + } + + for point in sorted_scanner_b { + let adjusted_point = point_sum(&point, &b_offset); + unioned_points.insert(adjusted_point); + } + + let mut result = Vec::new(); + for point in unioned_points { + result.push(point); + } + result.sort(); + + return Some((result, b_offset)); + } + } + } + } + + None +} + + +fn point_difference(left: &Point, right: &Point) -> Point { + Point { + x: left.x - right.x, + y: left.y - right.y, + z: left.z - right.z, + } +} + + +fn point_sum(left: &Point, right: &Point) -> Point { + Point { + x: left.x + right.x, + y: left.y + right.y, + z: left.z + right.z, + } +} + + +/* top 0, top 1, top 2, top 3 (front, right 0) + * top 0, top 1, top 2, top 3 (front 1, right 0) + * top 0, top 1, top 2, top 3 (front 2, right 0) + * top 0, top 1, top 2, top 3 (front 3, right 0) + * top 0, top 1, top 2, top 3 (front 0, right 1) + * top 0, top 1, top 2, top 3 (front 0, right 3) + */ +fn compute_all_rotations() -> Vec { + let mut result = Vec::new(); + + let all_angles = vec![ + RotationAngle::None, + RotationAngle::Ninety, + RotationAngle::OneEighty, + RotationAngle::TwoSeventy, + ]; + + for front in 0 .. 4 { + for top in 0 .. 4 { + result.push(Rotation { + top: all_angles[top], + front: all_angles[front], + right: RotationAngle::None, + }); + } + } + + for right in [1, 3].iter() { + for top in 0 .. 4 { + result.push(Rotation { + top: all_angles[top], + front: RotationAngle::None, + right: all_angles[*right], + }); + } + } + + result +} + + +/* + * x is left-right, y is top-bottom, z is front-back. + * top, front, right have their standard Rubik's cube meanings. + */ +fn apply_rotation(point: &Point, rotation: &Rotation) -> Point { + let mut result = point.clone(); + + match rotation.top { + RotationAngle::None => { } + RotationAngle::Ninety => { + let temp_x = result.x; + result.x = result.z; + result.z = -temp_x; + } + RotationAngle::OneEighty => { + result.x = -result.x; + result.z = -result.z; + } + RotationAngle::TwoSeventy => { + let temp_x = result.x; + result.x = -result.z; + result.z = temp_x; + } + } + + match rotation.front { + RotationAngle::None => { } + RotationAngle::Ninety => { + let temp_x = result.x; + result.x = result.y; + result.y = -temp_x; + } + RotationAngle::OneEighty => { + result.x = -result.x; + result.y = -result.y; + } + RotationAngle::TwoSeventy => { + let temp_x = result.x; + result.x = -result.y; + result.y = temp_x; + } + } + + match rotation.right { + RotationAngle::None => { } + RotationAngle::Ninety => { + let temp_z = result.z; + result.z = result.y; + result.y = -temp_z; + } + RotationAngle::OneEighty => { + result.z = -result.z; + result.y = -result.y; + } + RotationAngle::TwoSeventy => { + let temp_z = result.z; + result.z = -result.y; + result.y = temp_z; + } + } + + result +} + + +fn compute_distance(point_a: &Point, point_b: &Point) -> i64 { + (point_a.x - point_b.x).abs() + + (point_a.y - point_b.y).abs() + + (point_a.z - point_b.z).abs() +} diff --git a/19/tests/.main.rs.swm b/19/tests/.main.rs.swm new file mode 100644 index 0000000..5054379 Binary files /dev/null and b/19/tests/.main.rs.swm differ diff --git a/19/tests/.main.rs.swn b/19/tests/.main.rs.swn new file mode 100644 index 0000000..6017cf8 Binary files /dev/null and b/19/tests/.main.rs.swn differ diff --git a/19/tests/main.rs b/19/tests/main.rs new file mode 100644 index 0000000..ae2797e --- /dev/null +++ b/19/tests/main.rs @@ -0,0 +1,19 @@ +use assert_cmd::prelude::*; +//use predicates::prelude::*; +use std::process::Command; + + +#[test] +fn personal_input() -> Result<(), Box> { + let mut command = Command::cargo_bin("advent_19")?; + + command.arg("small"); + command.assert().success().stdout( + "79\n\ + 3621\n"); + + + + Ok(()) +} + -- cgit 1.4.1