From ce2ccd21f351525a61b5568ed345de9a9a481dc9 Mon Sep 17 00:00:00 2001 From: Jonathan Chan Date: Sun, 19 Dec 2021 13:09:52 -0800 Subject: [PATCH] Day 19. idk how to make it faster --- input/19.txt | 1054 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/15.rkt | 3 +- src/19.rkt | 90 +++++ 3 files changed, 1146 insertions(+), 1 deletion(-) create mode 100644 input/19.txt create mode 100644 src/19.rkt diff --git a/input/19.txt b/input/19.txt new file mode 100644 index 0000000..e55cd09 --- /dev/null +++ b/input/19.txt @@ -0,0 +1,1054 @@ +--- scanner 0 --- +774,-455,852 +-529,-517,624 +-625,-711,-470 +767,-512,840 +-460,951,-692 +-818,472,520 +-773,679,511 +862,-464,744 +525,623,391 +743,-739,-442 +796,-625,-416 +-555,856,-666 +-530,-533,678 +804,770,-668 +855,755,-607 +-665,-695,-474 +-832,675,456 +625,642,504 +-625,857,-708 +-27,128,-6 +884,831,-613 +-640,-819,-499 +726,-734,-426 +-592,-507,506 +65,-30,-114 +576,640,521 + +--- scanner 1 --- +-864,-782,-362 +-684,452,-674 +603,-703,632 +-898,-886,739 +787,-751,623 +399,-826,-424 +515,643,-482 +-879,489,-701 +230,792,432 +285,667,497 +-880,-904,-466 +-109,-166,-16 +-545,652,661 +-829,-745,-380 +-773,-797,771 +234,-800,-373 +230,772,515 +-877,-785,797 +602,544,-446 +-502,800,703 +634,-853,661 +254,-783,-470 +-497,710,730 +-801,515,-567 +607,644,-482 + +--- scanner 2 --- +-698,597,831 +-456,-401,798 +85,-151,126 +711,-671,-521 +-784,-429,-370 +-315,-428,717 +298,226,815 +337,698,-468 +-892,354,-385 +-75,-8,34 +-862,458,-307 +364,-804,590 +-828,538,816 +357,-859,491 +490,708,-536 +345,645,-460 +774,-652,-513 +680,-624,-591 +-762,-457,-312 +314,-928,532 +-390,-471,710 +-820,-421,-374 +475,225,715 +553,252,826 +-871,520,-442 +-764,685,904 + +--- scanner 3 --- +574,-737,-603 +481,504,754 +744,-364,288 +-419,879,545 +-572,798,582 +-661,-760,-402 +617,467,-909 +-711,480,-772 +-569,-790,-543 +568,375,-939 +625,-401,422 +-668,-822,-549 +-62,46,-9 +645,-352,465 +-608,410,-700 +465,-737,-540 +-755,-308,291 +-530,462,-693 +2,-36,-178 +728,509,762 +-531,927,664 +502,-771,-627 +-847,-270,403 +519,429,767 +777,381,-928 +-820,-293,442 + +--- scanner 4 --- +538,-463,260 +577,702,635 +-375,-469,354 +-620,557,341 +592,-402,403 +777,841,-700 +704,-367,-763 +-761,488,-778 +640,585,528 +-672,613,-810 +-650,-685,-624 +667,-286,-916 +-779,506,427 +-333,-462,377 +614,507,662 +-657,522,323 +-418,-550,449 +-660,509,-836 +-578,-755,-727 +786,-238,-804 +-571,-703,-805 +835,889,-769 +-43,141,5 +59,71,-135 +925,884,-742 +673,-418,353 + +--- scanner 5 --- +885,830,613 +703,-349,-391 +-614,-641,-790 +31,41,62 +871,-496,784 +-542,-538,-860 +925,589,-841 +-781,638,-895 +920,798,-761 +813,-565,736 +-631,626,726 +-751,687,-803 +-725,-487,383 +-609,731,658 +740,-502,-472 +822,-461,-343 +-535,-460,-808 +961,-523,779 +-636,-455,508 +912,551,-766 +125,96,-96 +865,716,468 +-624,-429,404 +806,785,478 +-770,847,-889 +-620,568,759 + +--- scanner 6 --- +587,781,640 +884,-805,-825 +845,-839,495 +-528,401,-787 +903,-790,-832 +680,731,630 +-479,312,-861 +-520,-775,751 +650,713,502 +851,-870,440 +-420,-780,715 +615,560,-293 +581,586,-288 +-436,-887,-289 +-549,628,630 +819,-820,-845 +-592,284,-731 +467,426,-305 +849,-793,448 +-381,-978,-327 +-575,706,496 +-612,511,523 +-2,-38,-23 +-421,-688,715 +-293,-879,-301 + +--- scanner 7 --- +-651,-695,657 +515,-660,545 +636,483,803 +529,636,838 +-804,-776,620 +-54,-44,38 +-468,411,366 +-692,-824,739 +504,455,-518 +-555,925,-474 +-615,-307,-625 +-376,373,478 +-693,-359,-618 +623,414,-500 +561,-512,-465 +466,-593,-422 +-512,-377,-697 +577,429,-591 +-654,893,-468 +-562,863,-327 +596,704,794 +99,38,-28 +489,-600,-380 +465,-644,626 +372,-599,491 +-403,396,517 + +--- scanner 8 --- +807,837,699 +-809,516,696 +-867,427,560 +-576,-391,899 +-503,-394,944 +629,-715,-705 +808,957,764 +-508,-299,929 +820,598,-444 +377,-535,628 +12,107,165 +395,-663,658 +609,-705,-628 +860,950,631 +-36,24,-26 +603,-517,-708 +327,-525,721 +-546,-719,-345 +705,562,-338 +-794,949,-483 +-507,-655,-409 +-865,798,-505 +-517,-669,-425 +849,596,-331 +-812,829,-601 +-846,621,574 + +--- scanner 9 --- +-882,654,333 +76,147,-61 +415,692,-896 +627,749,307 +-405,-415,-906 +-546,-426,-869 +-595,773,-591 +-802,709,394 +834,-415,489 +720,-647,-757 +775,-470,485 +-82,20,-96 +-574,-480,524 +750,-748,-795 +798,-770,-703 +-462,-451,-830 +-623,-463,522 +311,707,-979 +557,707,308 +-619,766,-485 +-853,648,409 +-527,735,-488 +-523,-350,541 +462,733,213 +820,-479,692 +425,785,-937 + +--- scanner 10 --- +-35,-73,40 +365,794,713 +513,356,-592 +334,800,768 +-692,-514,695 +746,-448,-486 +-405,410,576 +-434,486,570 +-741,-792,-504 +-882,-829,-493 +429,-571,457 +-764,618,-428 +-485,471,631 +516,-472,493 +411,798,760 +-760,-411,657 +-825,-753,-529 +801,-343,-504 +-668,-408,688 +-664,599,-541 +-713,601,-558 +413,463,-652 +801,-323,-421 +534,378,-677 +-175,-15,-91 +424,-471,493 + +--- scanner 11 --- +-824,-356,769 +828,680,-615 +658,-444,898 +-393,-551,-556 +443,-408,936 +-487,595,-811 +699,861,874 +507,-641,-438 +716,845,879 +-342,-564,-661 +-834,-329,760 +777,619,-630 +-692,813,835 +-582,621,-716 +857,674,-691 +-490,-546,-620 +633,-678,-438 +769,871,765 +-652,579,-717 +-652,817,851 +-80,154,183 +-667,788,959 +-906,-373,648 +10,7,64 +548,-611,-394 +538,-457,887 + +--- scanner 12 --- +-74,-15,36 +668,712,729 +575,-362,-380 +439,-304,-291 +-800,563,-736 +-722,-359,-693 +384,424,-349 +280,385,-468 +284,471,-350 +778,-595,527 +-800,703,729 +626,716,845 +583,720,701 +-680,638,757 +-934,481,-655 +-466,-625,855 +-759,509,671 +-917,600,-686 +-604,-377,-813 +453,-325,-485 +808,-663,435 +823,-668,530 +-546,-654,805 +-626,-306,-662 +-530,-664,791 + +--- scanner 13 --- +512,-334,-648 +-424,679,-521 +-469,-831,-580 +75,-109,-50 +-299,-532,743 +739,690,-519 +502,-807,500 +-738,606,386 +325,-834,463 +-745,663,374 +558,601,602 +621,611,720 +446,-338,-729 +-611,-816,-664 +-439,-585,691 +-556,690,-628 +-332,-583,773 +-833,654,482 +559,585,548 +-569,784,-534 +483,-369,-630 +721,698,-515 +408,-804,411 +-66,14,75 +-517,-836,-558 +777,815,-583 + +--- scanner 14 --- +-738,-857,-957 +772,-447,782 +394,451,353 +661,-422,738 +517,354,294 +550,-372,-505 +-821,-877,-957 +-738,-408,585 +-453,696,323 +-592,768,-553 +763,-355,640 +-346,695,304 +-630,666,-400 +-621,618,-584 +-756,-752,-902 +605,-467,-560 +590,582,-823 +630,545,-769 +-33,28,-167 +62,97,-14 +-713,-447,669 +541,524,292 +516,-373,-564 +669,622,-684 +-749,-371,726 +-463,706,242 + +--- scanner 15 --- +-718,-598,624 +353,784,-404 +508,-721,-455 +-624,528,762 +657,447,564 +-599,649,847 +-688,882,-849 +434,-675,465 +-684,628,869 +579,631,577 +-655,932,-690 +-572,888,-731 +653,693,588 +-387,-400,-471 +-46,111,-7 +378,788,-445 +-495,-312,-480 +-399,-407,-528 +482,-637,549 +521,-576,-350 +464,-786,439 +421,691,-374 +-848,-649,607 +615,-589,-444 +-735,-549,626 + +--- scanner 16 --- +629,408,495 +-554,458,-592 +-829,-911,-578 +377,-927,-899 +412,-900,-941 +-832,-866,-651 +-508,738,554 +-104,53,-129 +-706,741,528 +235,-660,473 +-688,-595,302 +-924,-896,-583 +230,-694,447 +-698,-688,252 +447,580,-611 +-504,378,-621 +-568,442,-582 +583,437,323 +422,569,-668 +-518,661,534 +609,451,408 +-560,-625,320 +247,-808,607 +576,544,-681 +447,-889,-812 + +--- scanner 17 --- +-381,579,750 +345,540,-487 +-300,623,614 +794,-922,481 +-317,-726,816 +-710,-934,-470 +-661,419,-374 +863,-965,522 +391,474,-415 +606,-568,-531 +-763,-942,-478 +-648,224,-316 +484,305,513 +355,421,-518 +-290,-804,705 +-20,-47,43 +-328,537,622 +559,-599,-601 +-773,-789,-546 +739,-915,580 +587,-505,-523 +-291,-981,805 +400,254,643 +-743,237,-379 +463,270,470 + +--- scanner 18 --- +-376,792,-504 +667,-524,825 +677,-617,875 +-251,-623,680 +-630,522,719 +485,-355,-699 +-795,-301,-696 +487,809,573 +-314,744,-433 +-256,-589,654 +477,-353,-776 +539,-554,807 +435,396,-642 +-366,836,-425 +-650,479,632 +-31,48,105 +433,490,-522 +-604,508,804 +-268,-737,520 +-788,-320,-711 +685,812,599 +497,732,593 +532,-359,-745 +118,-35,5 +-808,-385,-726 +592,440,-570 + +--- scanner 19 --- +-596,737,-579 +627,709,-561 +478,-497,-574 +169,124,-24 +-404,-523,-849 +-223,-499,415 +475,-466,-666 +969,-525,264 +-317,-483,580 +39,-30,-136 +-373,660,270 +437,440,382 +436,379,484 +-343,-578,-929 +-419,-584,-900 +-596,774,-705 +585,809,-465 +927,-447,378 +-414,642,418 +-640,707,-620 +886,-540,368 +525,442,481 +-318,-525,510 +-478,647,321 +516,657,-513 +581,-459,-642 + +--- scanner 20 --- +-508,466,651 +741,-705,-602 +-359,655,-828 +449,-837,463 +-753,-433,749 +-484,462,405 +524,504,-631 +-822,-501,722 +-385,685,-717 +525,741,746 +-469,637,-679 +-767,-695,-617 +454,698,649 +653,-822,-678 +458,-699,386 +430,598,-618 +102,-22,92 +-497,540,589 +535,611,-763 +-683,-760,-746 +-684,-418,747 +484,766,742 +648,-793,-698 +-755,-877,-706 +429,-666,536 + +--- scanner 21 --- +581,-712,492 +-700,879,-544 +411,495,-545 +662,-617,535 +530,-713,-556 +762,613,633 +742,747,732 +-771,646,501 +-817,823,-480 +-473,-538,-523 +-394,-639,896 +350,422,-541 +-410,-743,774 +574,-689,450 +741,577,619 +368,595,-606 +-590,-431,-460 +64,154,75 +-395,-404,-497 +-789,953,-593 +575,-806,-421 +-700,683,528 +-445,-725,737 +514,-663,-475 +-867,756,575 +-72,-4,46 + +--- scanner 22 --- +-628,647,-653 +-570,453,-694 +-117,-158,48 +-707,-698,-698 +-641,-703,675 +624,-562,-441 +674,-570,-274 +401,647,746 +379,-913,709 +-598,436,689 +-542,518,-574 +489,615,-374 +-570,444,774 +376,699,771 +44,-58,-17 +422,-706,748 +719,-552,-482 +-557,-822,698 +-793,-614,-671 +679,607,-416 +548,494,-430 +445,-808,818 +-775,-729,-576 +-661,-859,696 +411,732,817 +-454,440,732 + +--- scanner 23 --- +-487,-849,593 +106,79,-154 +45,-24,-17 +-466,-743,604 +450,343,624 +332,349,508 +491,299,541 +-316,871,668 +-452,-621,-392 +-540,757,-583 +763,528,-892 +811,-491,439 +-342,879,609 +-329,-605,-514 +818,-347,473 +705,-376,475 +441,-593,-640 +857,648,-890 +521,-587,-828 +-510,-789,550 +813,576,-733 +-485,782,632 +-647,738,-560 +-503,743,-573 +444,-567,-838 +-520,-620,-430 + +--- scanner 24 --- +-462,-602,564 +-433,413,702 +131,-165,-19 +440,-571,-773 +703,353,406 +-357,473,-916 +-519,-577,575 +677,551,403 +649,799,-490 +557,-764,693 +8,-40,-99 +-664,-654,-637 +472,-738,707 +466,-577,-890 +-695,-671,-737 +-443,399,686 +-242,414,-884 +-472,349,766 +-532,-731,600 +644,-784,736 +428,-720,-843 +683,363,483 +665,677,-367 +-562,-720,-701 +650,761,-558 +-448,460,-878 + +--- scanner 25 --- +-566,-460,-730 +465,348,574 +-602,331,-403 +26,-23,-17 +523,-613,937 +638,660,-785 +-153,-90,118 +-524,-538,549 +-558,443,621 +-489,367,-459 +-570,-581,404 +-463,326,-292 +-502,463,691 +671,-567,-623 +708,599,-744 +599,307,512 +-473,-564,384 +561,-511,784 +504,329,376 +-480,-619,-679 +697,-579,-727 +639,-478,-748 +-462,-582,-714 +-552,431,745 +532,-661,753 +721,720,-776 + +--- scanner 26 --- +771,327,407 +-590,-848,-471 +809,488,-669 +362,-399,-421 +468,-890,405 +-658,-745,-433 +-34,-17,-37 +-481,-741,835 +-577,-699,735 +-952,679,680 +-682,-851,-440 +761,441,557 +697,426,-690 +-791,784,-252 +248,-357,-499 +-891,585,813 +366,-889,466 +-830,780,-326 +-529,-810,683 +-961,726,733 +352,-440,-514 +-706,761,-387 +811,447,537 +824,478,-757 +465,-801,468 +-143,47,150 + +--- scanner 27 --- +386,-844,-700 +563,-544,698 +-647,-988,-455 +516,665,-690 +429,-747,-771 +361,-840,-741 +659,478,805 +-379,344,-674 +623,533,-701 +31,-182,6 +-778,757,572 +553,572,825 +-748,790,521 +-579,-408,378 +-680,-938,-296 +575,620,820 +-696,650,574 +-391,351,-617 +524,-483,499 +-564,-944,-414 +560,-510,581 +-487,256,-665 +-556,-505,521 +-520,-416,352 +529,520,-795 +-61,-23,96 + +--- scanner 28 --- +532,-499,955 +-755,442,498 +-943,-589,422 +676,663,880 +670,-562,887 +649,700,685 +-30,44,152 +724,-761,-619 +457,508,-606 +-628,-319,-517 +542,-592,905 +542,637,802 +-830,-521,475 +-686,500,546 +-457,360,-229 +-713,-341,-496 +732,-763,-696 +-728,352,503 +-522,485,-284 +-540,380,-229 +-950,-456,474 +421,608,-601 +677,-757,-665 +-688,-426,-617 +457,509,-514 + +--- scanner 29 --- +144,112,-18 +-702,-369,-411 +-432,801,-275 +863,-556,-253 +-370,-792,740 +-642,641,969 +475,-740,563 +655,448,-612 +61,-29,112 +674,561,-512 +810,672,565 +672,578,-561 +479,-693,517 +-276,-790,620 +-423,909,-363 +787,-550,-282 +-707,-385,-394 +917,612,665 +-683,724,925 +-480,897,-370 +-320,-633,692 +473,-748,486 +-801,608,919 +895,697,686 +-593,-359,-341 +802,-611,-333 + +--- scanner 30 --- +-37,-100,-74 +-412,840,610 +326,-334,-645 +584,474,-750 +497,-368,-686 +450,-339,-614 +-87,76,18 +-426,-768,-381 +628,406,-802 +-645,-777,-449 +-490,870,714 +710,-320,842 +634,297,-807 +610,-497,843 +726,676,471 +-561,531,-443 +-611,492,-414 +-573,-359,370 +711,806,530 +-547,849,548 +-501,-801,-422 +-565,-367,423 +-713,459,-476 +721,-575,816 +-641,-512,360 +799,742,383 + +--- scanner 31 --- +445,606,687 +-603,470,-551 +538,-947,859 +489,-855,829 +-666,423,346 +391,426,-728 +378,-813,-842 +-594,389,-546 +-549,405,480 +-856,-911,-741 +550,674,709 +460,416,-787 +-671,399,498 +346,561,-807 +587,-893,-847 +-642,-702,732 +4,21,-57 +-892,-849,-799 +-884,-853,-763 +-661,-710,795 +-564,301,-523 +329,-941,848 +625,-818,-834 +-689,-632,701 +608,707,698 + +--- scanner 32 --- +6,-21,-26 +-395,-854,893 +466,287,463 +438,-459,-353 +-393,738,-480 +-307,757,-320 +-430,-925,-616 +811,432,-523 +-337,-832,865 +565,294,518 +845,456,-595 +426,-636,-452 +-546,641,651 +-435,-933,-369 +-355,-938,-578 +-616,610,698 +692,-385,894 +685,-460,851 +507,244,394 +475,-593,-472 +811,369,-632 +773,-526,921 +-399,-890,901 +-538,704,670 +-66,-168,60 +-301,768,-529 + +--- scanner 33 --- +320,354,547 +479,405,461 +-471,681,583 +-739,340,-727 +766,-614,497 +-578,-746,-381 +724,-621,474 +521,-907,-607 +-800,299,-657 +-8,-45,97 +-587,-885,-270 +449,-837,-504 +-507,625,470 +-793,-925,788 +427,461,-690 +681,-702,569 +439,357,-716 +-817,-807,756 +-779,-793,866 +442,370,443 +528,-855,-685 +-603,-915,-326 +338,336,-658 +-860,308,-740 +-466,792,444 +-139,-8,-40 + +--- scanner 34 --- +-734,649,-804 +897,754,-539 +-212,-948,780 +574,-560,549 +-622,-551,-646 +14,-146,49 +759,-663,-654 +489,-681,524 +467,-660,609 +-716,-555,-557 +729,617,773 +-642,791,-813 +787,605,-557 +-337,-893,715 +-681,594,697 +-232,-948,697 +871,643,-509 +-667,747,-702 +772,-479,-732 +-718,735,708 +712,566,643 +748,-725,-728 +-642,678,672 +710,517,660 +-717,-496,-591 +187,-127,-64 + +--- scanner 35 --- +-675,-421,848 +-519,566,-584 +728,-566,-806 +-413,587,-573 +-473,610,-530 +451,-624,812 +250,946,797 +-915,-718,-453 +480,-704,862 +365,978,738 +-669,-341,660 +-771,-711,-419 +-642,620,450 +-657,429,534 +19,32,161 +482,729,-519 +799,-544,-655 +-641,552,412 +441,-640,798 +-695,-344,858 +541,863,-568 +456,940,751 +-18,156,-16 +385,760,-528 +-886,-605,-455 +746,-448,-686 + +--- scanner 36 --- +-310,675,-866 +-311,610,-746 +-298,-533,-507 +421,-788,-656 +860,368,816 +829,374,761 +783,370,808 +-509,-717,796 +-489,-794,806 +427,-906,-540 +726,-381,858 +660,790,-629 +781,705,-604 +-14,55,82 +-258,542,-859 +606,-475,860 +-791,632,616 +-741,539,626 +-413,-427,-471 +-723,569,754 +-515,-797,608 +377,-747,-573 +654,-425,701 +-269,-420,-505 +681,812,-544 +95,-98,30 + +--- scanner 37 --- +473,-578,819 +-940,881,-381 +-912,776,-403 +-400,586,662 +482,-578,-649 +-830,-487,741 +-463,486,559 +-585,-355,-626 +-700,-373,-531 +547,-606,-529 +-793,-591,743 +704,806,-783 +676,-520,-608 +-674,-507,720 +761,500,535 +-111,-17,198 +800,619,431 +714,501,435 +469,-694,777 +465,-550,734 +585,837,-766 +-458,501,654 +-669,-441,-653 +-38,40,27 +-860,800,-384 +622,887,-649 diff --git a/src/15.rkt b/src/15.rkt index cbb677d..652204e 100644 --- a/src/15.rkt +++ b/src/15.rkt @@ -37,4 +37,5 @@ (let*-values ([(weights paths) (dijkstra (make-graph dim) (posn 0 0))]) (hash-ref weights (posn (sub1 dim) (sub1 dim))))) -(show-solution (shortest-path dim) (shortest-path (* dim 5))) \ No newline at end of file +(show-solution (time (shortest-path dim)) + (time (shortest-path (* dim 5)))) \ No newline at end of file diff --git a/src/19.rkt b/src/19.rkt new file mode 100644 index 0000000..937edb6 --- /dev/null +++ b/src/19.rkt @@ -0,0 +1,90 @@ +#lang curly-fn racket + +(require "../lib.rkt") + +(define input + (for/list ([group (problem-input-grouped-lines 19)]) + (for/set ([line (rest group)]) + (match-let ([(list _ x y z) (regexp-match #px"(.+),(.+),(.+)" line)]) + (map string->number (list x y z)))))) + +(define (set-map s f) + (for/set ([x s]) + (f x))) + +(define (delta beacon1 beacon2) + (match* (beacon1 beacon2) + [((list x1 y1 z1) (list x2 y2 z2)) + (list (- x1 x2) (- y1 y2) (- z1 z2))])) + +(define (shift beacon change) + (match* (beacon change) + [((list xb yb zb) (list xc yc zc)) + (list (+ xb xc) (+ yb yc) (+ zb zc))])) + +(define (magnitude change) + (match-let ([(list x y z) change]) + (+ (abs x) (abs y) (abs z)))) + +(define (deltas region) + (for*/set ([beacon1 region] + [beacon2 region]) + (abs (magnitude (delta beacon1 beacon2))))) + +(define rotations + (for*/fold ([rotations '()]) + ([dx '(1 -1)] + [dy '(1 -1)] + [dz '(1 -1)]) + (append + (if (= (* dx dy dz) 1) + (list (match-lambda [`(,x ,y ,z) `(,(* x dx) ,(* y dy) ,(* z dz))]) + (match-lambda [`(,x ,y ,z) `(,(* y dy) ,(* z dz) ,(* x dx))]) + (match-lambda [`(,x ,y ,z) `(,(* z dz) ,(* x dx) ,(* y dy))])) + (list (match-lambda [`(,x ,y ,z) `(,(* x dx) ,(* z dz) ,(* y dy))]) + (match-lambda [`(,x ,y ,z) `(,(* y dy) ,(* x dx) ,(* z dz))]) + (match-lambda [`(,x ,y ,z) `(,(* z dz) ,(* y dy) ,(* x dx))]))) + rotations))) + +(define rotated-regions + (for/hash ([region input]) + (values region (map #{set-map region %} rotations)))) + +(define (combine region1 region2) + (and (>= (set-count (set-intersect (deltas region1) (deltas region2))) 66) + (for*/or ([beacon1 region1] + [beacon2 region2]) + (define change (delta beacon1 beacon2)) + (define shifted-region2 + (set-map region2 #{shift % (delta beacon1 beacon2)})) + (and (>= (set-count (set-intersect region1 shifted-region2)) 12) + (cons (set-union region1 shifted-region2) + change))))) + +(define-values (part1 part2) + (time + (let loop ([full-map (first input)] + [scanners '()] + [regions (rest input)]) + (if (empty? regions) + (values (set-count full-map) + (for*/fold ([distance 0]) + ([scanner1 scanners] + [scanner2 scanners] + #:when (not (equal? scanner1 scanner2))) + (max distance (magnitude (delta scanner1 scanner2))))) + (for*/fold ([full-map full-map] + [scanners scanners] + [regions regions] + #:result (loop full-map scanners regions)) + ([region regions] + [rotation (hash-ref rotated-regions region)]) + (define combined/scanner + (combine full-map rotation)) + (if combined/scanner + (values (car combined/scanner) + (cons (cdr combined/scanner) scanners) + (remove region regions)) + (values full-map scanners regions))))))) + +(show-solution part1 part2) \ No newline at end of file