diff --git a/2025/day08/input b/2025/day08/input new file mode 100644 index 0000000..bf694d2 --- /dev/null +++ b/2025/day08/input @@ -0,0 +1,1000 @@ +5370,32684,47416 +50576,36657,47067 +81216,77932,88744 +26014,71483,56637 +93100,35760,25348 +53636,26550,49908 +8762,79604,84002 +54152,48622,83231 +42843,85172,85591 +78311,51264,32667 +8978,47449,86125 +13542,55797,94088 +52467,55171,82851 +83138,91898,64572 +66649,6522,43593 +78010,65055,84448 +55462,73210,95831 +5939,77777,27955 +80037,77215,23522 +44670,37343,77063 +43361,52692,50672 +71204,15252,96837 +79631,59459,74410 +22649,56384,80097 +26124,52033,50180 +74708,67310,86116 +13688,87510,51113 +79789,97363,87714 +28199,60995,29098 +28803,87812,50176 +42604,85,57721 +5976,6902,53103 +44552,43275,63677 +57221,51946,51549 +42425,27699,83789 +74532,63477,87598 +61289,86959,95188 +47844,76826,38030 +37643,82620,2892 +93084,15746,19013 +32346,40104,79137 +68519,66135,83166 +95032,85781,88322 +94296,48225,17970 +85856,63450,15661 +91773,24505,75271 +92224,98382,83288 +53978,10917,68450 +61002,84108,21018 +56295,90888,16153 +79048,67081,57416 +60313,31493,92848 +83948,18160,58025 +67823,16508,86907 +26929,94029,39232 +31918,39023,22591 +26573,74122,95796 +41147,28882,95960 +85707,14306,47501 +74503,98519,42008 +36470,97513,30767 +44095,56911,77658 +60461,91262,51255 +23967,41157,90137 +24811,56386,84712 +89628,56642,9086 +79177,17117,77904 +87628,79246,25993 +79251,52486,37763 +53630,47975,51414 +39554,53840,6189 +22277,95274,96376 +72695,18936,40095 +74026,9791,60221 +17577,44603,31750 +76890,65751,69594 +41526,96394,33352 +16041,56373,99391 +57875,25172,69681 +46000,22365,46413 +46158,71048,58674 +3391,39108,4898 +85784,28643,63451 +85217,12320,43885 +25532,82329,12681 +4983,52676,89949 +21536,96568,41775 +9458,17482,85559 +49636,30852,64370 +239,28759,40535 +99422,30203,4106 +44822,47438,69988 +30241,19871,66917 +96932,37970,91573 +9114,62465,6999 +22258,77325,30100 +741,70851,89012 +46724,93525,87077 +65692,33941,64401 +62458,48534,20220 +38281,57068,74842 +53174,20386,43434 +61329,74432,97186 +1562,53594,61290 +2897,82189,92268 +32704,69258,50965 +59863,39279,64814 +82916,48801,54015 +73147,94392,91097 +12839,75143,55229 +19579,20791,63854 +95524,65731,4449 +90234,13835,11771 +6237,79979,63175 +96255,48220,74929 +70873,60732,47287 +93629,72469,27007 +10054,14361,69662 +13493,32926,7445 +70174,57944,53383 +62286,22702,81009 +54480,6210,13415 +39425,91684,17646 +59094,13208,54398 +24136,84876,2409 +72910,7465,56947 +75524,53107,33100 +99562,83520,48143 +81265,34866,96020 +29751,92049,68261 +15066,87033,89824 +3279,8078,81882 +23213,11116,76343 +15940,29432,31149 +35271,91671,96902 +21039,44509,71214 +81710,66541,52231 +81734,13436,61160 +40747,79689,68612 +60505,8118,52379 +68032,43130,40680 +1195,72407,82952 +17817,53883,72576 +73798,6679,93786 +41229,86447,10021 +62372,86711,76642 +4157,91402,12234 +69267,71079,95903 +79996,91293,83948 +15763,36421,12600 +38844,28596,6696 +29615,48502,79602 +81870,18439,81656 +34911,25283,19984 +70905,76704,25453 +54482,44264,23683 +35838,2805,2639 +95682,16981,20287 +54593,2019,40262 +49743,88491,39132 +14329,84938,63198 +42907,52594,66758 +5196,77472,43225 +10682,30612,17193 +99706,6748,54123 +17729,31216,69213 +86954,90484,56259 +61462,67782,21476 +1731,77773,62817 +78668,52049,24313 +34848,63302,91232 +30701,30803,1872 +74738,15811,9144 +81415,70096,78764 +3055,76034,66434 +41569,44230,35378 +6192,13383,1671 +33695,78716,9183 +87148,52471,9021 +45760,56127,71165 +7442,64744,72429 +13815,31879,31964 +84670,77952,76012 +22367,80558,4118 +89617,84197,85058 +16109,73797,50809 +63912,24829,70432 +25724,94162,82131 +84985,50125,97547 +49434,81509,92378 +75620,2092,62418 +98267,82251,81816 +70413,57105,60047 +81882,10792,72642 +12904,63790,6773 +55612,93323,58768 +44100,54838,26477 +66372,92142,21049 +44996,77883,73339 +8135,60884,90789 +89804,93494,91072 +47867,62187,76805 +88419,99889,30876 +56092,13333,13547 +60761,93889,35663 +98374,58204,63831 +50685,20363,90554 +99802,65504,81129 +15404,73244,97250 +35199,7229,67984 +76333,72962,74736 +51724,66488,31327 +12220,5798,68450 +90156,24652,43665 +31082,41381,18946 +48964,38418,64527 +5457,97336,4189 +31584,4920,96030 +88326,84030,89854 +11143,49317,52898 +97149,35749,78836 +20494,54084,40850 +93216,80325,44989 +4689,12415,34638 +74882,20410,69081 +60284,31931,75014 +6276,71358,17687 +88131,35755,47816 +65840,13077,3342 +84063,52317,77291 +2763,30286,65727 +68332,73938,55910 +43767,25624,40651 +2339,32415,49039 +80917,17886,17816 +81718,71506,78046 +50295,16328,16600 +98944,93823,37981 +15415,507,17890 +81415,71152,81788 +10388,99609,15272 +36592,45998,22120 +58938,79372,43469 +6955,74508,25102 +94005,44283,11892 +91879,31123,64645 +20154,80294,37245 +1310,47091,51600 +74176,95056,47126 +39556,71317,50761 +29527,14111,77972 +25943,8676,83924 +62891,70785,80382 +8079,36735,42502 +92678,53246,50709 +81130,26235,13185 +39158,82652,63755 +23953,85448,13605 +45186,95916,91502 +30964,57168,16714 +72500,55046,42201 +96333,12776,71493 +82047,53734,47918 +42229,77870,25436 +55509,92642,28668 +90964,74462,22604 +82269,2383,45182 +98237,77364,9216 +92078,7359,8781 +33572,11525,68163 +75113,59997,95092 +34022,21495,11460 +5746,29160,79883 +26804,37066,24660 +64205,90003,59130 +41839,72597,80678 +83446,72716,29022 +75762,40526,83470 +1832,80044,42054 +16620,28292,58901 +12904,7779,57379 +89128,1886,61514 +74766,96769,72473 +92751,65364,66741 +1889,91820,91857 +54194,77778,45396 +59804,7737,33044 +76797,8344,99277 +40720,18399,13342 +3168,49483,8883 +40041,51231,56660 +7801,3354,21976 +27363,30313,24692 +77665,96540,43102 +48686,6997,63808 +97349,55767,42744 +70378,51608,77001 +21116,52500,3449 +55854,14770,98566 +77361,73048,75608 +7317,32774,40962 +51984,95054,61678 +14107,22023,30965 +43702,53367,98770 +74822,47073,20474 +91394,41611,88284 +82471,40948,46953 +49293,36028,20144 +77287,58148,50707 +88461,44173,53183 +6768,10721,95199 +9874,14649,76548 +69916,27300,43670 +36847,71057,63633 +20250,2312,14748 +19443,40276,18176 +82154,87707,55553 +42662,5430,90722 +65168,57238,27170 +78492,64196,31706 +1935,69263,64767 +52745,95520,20682 +18718,10908,50429 +56368,92902,77612 +49592,65537,3919 +3747,33505,97694 +30136,37563,24273 +96530,27432,8071 +32899,39939,68059 +6660,79978,61080 +57177,44012,34467 +29553,11618,69874 +67680,34722,83509 +43046,60365,74164 +95932,89585,77485 +49777,17664,14673 +9205,79686,23232 +52839,45888,64422 +67469,81214,21334 +96468,169,49277 +91078,70032,76325 +28330,63499,56427 +96135,75842,30545 +34791,72109,79108 +44780,59700,49172 +63655,10692,59745 +48911,62997,33999 +74217,17614,74932 +44320,79872,96407 +17295,47749,44417 +12851,23357,8549 +77161,99219,28598 +17717,66442,51395 +30025,3113,85343 +51707,94334,26151 +76265,32922,38882 +6979,56593,72465 +60369,19147,14483 +85000,80533,99807 +29400,57144,69731 +68827,76958,14985 +91357,34061,83772 +78254,39570,57553 +33990,74824,66050 +53385,95019,26270 +68751,99974,2362 +75539,46048,53412 +608,87587,66880 +2039,84420,84663 +23717,72224,75901 +71816,86997,79987 +46221,2190,72752 +79463,74108,33377 +38887,26942,92830 +38374,98939,5432 +23313,80558,57642 +19818,13030,10197 +42238,14537,89230 +28900,3032,5169 +7947,32388,51078 +81002,6140,35233 +69207,88913,88558 +3617,92850,69064 +50439,43661,91435 +82015,25536,78767 +60749,54671,81379 +85460,46767,21820 +61567,74209,86424 +51265,1711,1116 +58965,97067,51083 +74514,70392,18258 +97369,94622,34485 +53531,75207,96319 +97655,37622,99786 +87694,75956,46764 +90801,17833,14733 +41344,76988,14659 +42359,38647,11634 +950,6070,60469 +403,87601,50960 +5181,86974,17050 +22783,45117,53114 +65715,45082,34442 +38343,37204,84717 +74038,42291,82812 +83926,45641,38665 +62900,98024,32192 +53607,22624,45884 +52901,69750,54331 +4753,85272,38703 +82764,75195,30702 +73795,59867,8411 +21254,58067,35146 +43277,11811,22525 +62552,18,60751 +11221,73143,40704 +63123,63611,37295 +42831,60345,73640 +33938,63564,39984 +68190,55877,60798 +46045,25631,98269 +8782,15365,95554 +85975,15675,17621 +2150,99196,47027 +16698,11526,5131 +50859,58833,14618 +16493,98941,80227 +45560,90895,26142 +73407,95793,93939 +667,50410,48255 +54363,66933,42108 +97045,93082,8050 +10180,15778,55874 +3931,62387,23700 +88855,55394,26856 +80563,78874,84777 +88796,28592,20048 +54260,37978,28757 +40771,97954,39742 +96586,30707,90562 +81574,93946,88040 +60952,74131,43506 +77344,54114,96131 +94091,56979,89721 +70080,21803,31211 +13732,76973,23909 +81145,84463,57092 +72246,74922,33192 +77823,88548,91904 +38016,62972,86009 +78364,8548,88977 +66027,89434,97398 +95699,6824,15696 +58132,86531,3934 +87769,97171,88640 +33373,7897,62572 +28707,78321,14248 +39512,3393,9016 +36044,87987,91081 +54670,67312,11713 +20425,86895,86471 +82726,10265,34844 +60940,50684,39226 +3080,83719,19188 +48048,21428,5742 +85517,2688,83160 +99319,14470,69352 +43145,61042,21694 +56109,52933,10676 +42294,30685,15258 +90940,42194,15865 +88508,23306,23708 +16706,63101,30234 +84363,36172,49496 +24478,5671,64942 +53046,72453,93269 +78890,87831,19217 +23834,74266,81898 +76701,9844,10923 +14361,10648,98634 +1429,73112,52606 +25184,76516,35484 +25845,32316,11770 +16185,23418,21237 +17692,42949,55614 +58527,65167,64227 +86121,22404,44973 +51327,72051,45915 +86330,73906,84418 +2688,92753,29725 +11268,72386,89784 +31866,85508,28607 +28896,67008,60313 +67745,4141,62177 +4864,69393,26508 +43055,67131,68937 +67764,50521,54482 +72877,47374,52543 +280,44369,48442 +52505,99637,87980 +31131,42278,21183 +21600,73416,75919 +96684,12886,32035 +78274,95855,96140 +42901,39694,50253 +61720,96059,54581 +65317,8215,40196 +15951,71967,71990 +25039,92297,14310 +48992,44533,55765 +44832,20007,31729 +54238,26495,98191 +99015,84151,97507 +72216,49894,18421 +90948,868,85309 +25211,70922,76579 +26925,11813,29559 +62786,9188,84570 +16020,90076,92960 +4743,47850,81021 +6603,72918,95915 +45919,70169,5882 +72771,29205,38648 +1833,78324,87169 +58547,77925,30188 +85354,55589,21090 +94843,32296,10505 +14874,32048,24243 +75083,95240,12551 +92522,85495,83239 +88650,96027,37771 +36485,10297,30896 +58089,31589,34944 +78155,74623,20744 +77228,38624,38124 +44740,14313,54255 +5495,49974,67993 +70375,84472,79721 +29589,20539,78106 +9445,70675,34634 +94378,1341,10109 +86575,32135,31472 +42843,25105,36450 +62877,17498,92986 +33024,99523,74158 +83612,72789,1358 +55913,29921,23245 +28495,69739,63018 +85870,77827,23186 +85768,53679,56894 +64243,25419,49278 +25881,22092,5879 +71669,11250,88180 +88182,94889,24866 +62,92088,88967 +95893,37423,34229 +4646,63477,11116 +2045,79048,74700 +5189,57720,76631 +61913,9923,13706 +95160,27831,84671 +99229,2391,76323 +94634,4839,58013 +86164,40096,35516 +45244,17984,12488 +59952,35123,68870 +74081,28181,27821 +81424,30174,57809 +22644,75444,90062 +2754,21110,90702 +49586,11522,44872 +12515,59904,25198 +77038,41074,18776 +30206,6638,67898 +58904,66321,61912 +34489,47838,46261 +96274,29019,81685 +89917,5569,73653 +85807,16814,31082 +15273,71068,88643 +49253,95190,83622 +73237,61061,58979 +85140,25039,25114 +9273,68471,83546 +19323,54446,29881 +74468,67527,74415 +76234,21796,55995 +45675,9041,86382 +52656,7406,57215 +43481,4224,90098 +8542,48151,25905 +86242,94759,19280 +99779,96970,2035 +49902,99354,58587 +55389,74195,39634 +25305,26003,35724 +48391,93132,69644 +86238,15827,47949 +74410,37812,39567 +88106,22768,20979 +81312,39864,23705 +57652,35151,97239 +17002,82389,96132 +32775,81483,50121 +45814,58487,64765 +82502,66705,67384 +17501,85085,73365 +32256,85784,69129 +82604,46218,44071 +96171,31653,73133 +65545,98463,86894 +20597,56924,31161 +56497,97296,1430 +24938,57223,23030 +68884,70868,35121 +8363,65789,43614 +61947,29500,87452 +60098,23325,67906 +76906,55278,44206 +21885,96418,5838 +14643,94753,33048 +38571,50608,20435 +22932,60117,56329 +58928,24296,46027 +15808,20749,57491 +32734,90676,8453 +74413,89028,12014 +74925,8476,72561 +37013,30239,80753 +40429,73340,2289 +15106,15183,19654 +99871,14052,63048 +8919,1583,13173 +19342,90139,19365 +11916,67200,25822 +88306,76808,49931 +11100,93101,50421 +42709,61897,36039 +87316,2517,84252 +91618,17403,30436 +18540,59986,90822 +12019,55814,10850 +99667,50440,49894 +95115,88961,68989 +27460,73489,78526 +33612,53436,29642 +694,69222,3394 +91405,70145,50422 +42851,13701,4271 +53806,78954,82408 +69082,11784,57329 +53638,6270,47299 +60918,12896,5385 +91760,86335,94373 +10575,61820,40989 +62374,69170,15142 +25214,10547,12253 +15945,31891,61863 +26984,50465,19965 +53538,78974,3405 +33186,50259,10587 +75176,21577,20423 +16159,37835,35008 +10931,33263,1761 +80278,23997,9911 +84965,76364,87275 +19807,39711,69487 +89471,24004,27088 +19661,46001,79570 +27372,84024,51897 +99878,3072,66910 +56201,91925,71278 +988,57814,62643 +3595,63529,27026 +66523,24893,13673 +19633,93177,78325 +84100,87060,86978 +23447,49024,31880 +86718,29454,71197 +94484,45867,67143 +57296,34731,81653 +31397,11039,18987 +2143,8792,58526 +99327,31212,31682 +76696,48565,39412 +80959,41427,33304 +86646,81227,48048 +87093,98132,15583 +54180,11938,62782 +86044,51895,66606 +97542,63103,28781 +52092,97912,57690 +58177,55321,94258 +4656,73300,5699 +80498,2706,15060 +30250,93984,19543 +59323,39233,58277 +12422,29110,95754 +78722,89282,2097 +3680,48171,58987 +40653,60013,5946 +7843,89465,57978 +49855,16284,64210 +6994,61571,31377 +99294,12496,4461 +45365,3086,71485 +51090,521,43896 +36312,7642,69284 +32100,59565,13621 +14554,84916,95175 +98113,56723,36521 +15546,85902,95823 +52081,40563,36650 +13221,99231,22904 +13680,7542,42271 +14539,62469,73792 +35294,53728,6441 +78363,71587,69959 +64045,1435,83365 +48907,58151,43169 +22202,76745,19572 +11408,31001,69662 +35669,49008,69517 +33370,9236,25327 +18330,86873,6625 +22794,67832,23710 +45636,18551,18692 +19710,98191,97584 +58932,98231,41432 +97886,98123,78458 +50172,86733,62943 +82029,73745,50394 +89983,94312,61897 +54781,70494,73175 +83932,72133,32389 +13144,67088,40832 +30342,66874,61426 +50551,71188,49676 +35786,5063,7453 +17816,13327,98156 +64796,15186,29641 +59429,55143,18737 +15398,12665,66376 +30678,10003,56079 +94544,63855,5899 +59693,51608,98528 +16637,31001,34749 +41009,99445,30482 +36347,91224,20910 +3350,45916,45616 +94509,21112,87526 +12602,66933,66982 +15582,84350,1241 +31438,77301,95040 +28175,19740,37165 +51963,80127,81235 +43929,71757,17776 +2825,28210,4983 +28232,25923,22983 +23949,51066,40291 +52566,62012,49032 +29714,90733,78839 +22146,26995,25475 +31891,94347,20169 +17866,26563,22902 +12257,13478,8228 +72397,4842,66170 +31333,2465,66033 +2054,71617,74731 +78095,73462,35507 +37855,94596,93081 +9330,86580,84135 +62682,93899,62459 +93490,11503,96330 +10133,30939,80001 +30127,77973,86984 +45967,81205,48281 +68975,13704,76751 +57572,5281,21774 +85883,67611,58495 +70749,46652,33335 +93413,6095,59034 +83691,49651,91092 +84330,49323,29068 +75235,19557,89175 +90801,61243,62736 +53208,50495,31621 +88831,75796,62141 +47973,23719,93994 +60230,44199,38198 +85020,4090,10697 +8368,91112,75497 +140,71606,58947 +72944,66775,87264 +41046,42004,97988 +22454,52980,9832 +77841,80063,31679 +14230,82824,68341 +14862,53300,97200 +48848,41636,32377 +22542,57799,30858 +60715,68481,60330 +12190,93838,50998 +99002,89188,29124 +93920,38268,92653 +25305,58581,82071 +13257,22372,97012 +69327,76694,10596 +93653,93765,72769 +17982,88740,83175 +66641,18834,49355 +36201,89563,84681 +7749,49427,79687 +16749,89437,57015 +33030,3006,47713 +13977,63862,84719 +11492,38337,18498 +48551,23531,81548 +11001,75670,10100 +63071,4516,60904 +23059,87364,30721 +9422,52574,92477 +17226,53728,14388 +59691,94405,12877 +59193,46668,92812 +59005,51396,66643 +94293,71830,31051 +83511,54383,40465 +6081,29475,19428 +78633,53840,92543 +38196,98090,64380 +29268,21533,29726 +12582,69756,66043 +5587,41086,39366 +28503,24111,28182 +73218,51830,76801 +36457,24516,19933 +21722,17783,77015 +52924,97325,56398 +35054,43077,99254 +96418,33453,99001 +8143,44385,44132 +85966,93829,96586 +49133,75697,11681 +89262,51453,2627 +1180,45738,38887 +45184,42151,25556 +43107,41699,86907 +8172,20437,18682 +79308,48438,53840 +64229,76894,67465 +52218,56961,87577 +24232,25448,49000 +16092,98325,96965 +64051,30943,89122 +92970,74486,23676 +52610,14492,56652 +48106,93691,58983 +35382,26969,63289 +48461,37149,72084 +68981,35523,98595 +26523,52232,74078 +43030,28736,30430 +139,4437,56201 +16311,97163,27981 +30915,44727,13506 +43188,71437,66883 +6434,22234,71338 +2808,19581,4054 +43230,88586,95524 +18860,69598,9040 +23572,85876,77514 +47191,17663,56892 +19173,70626,71610 +7830,70179,31832 +50605,95686,99536 +47732,40128,15715 +73489,19885,81276 +27788,92937,47451 +12123,41661,13324 +72052,81708,23419 +27831,87016,31765 +95667,94707,85724 +52726,82766,81835 +15561,18585,966 +74669,28387,19062 +8269,24902,66830 +19093,27071,98002 +21765,42470,96350 +38914,22004,58164 +31927,11103,36954 +30463,862,58643 +59099,15122,97661 +91844,90953,57429 +38925,40813,53492 +90171,33281,59290 +5823,82221,94023 +82942,72623,45679 +21980,56093,3119 +41655,20799,81726 +77250,3776,10816 +28506,58294,22947 +71430,41887,1462 +56849,76081,64246 +32443,69746,44369 +20758,34132,732 +49039,86773,32072 +56215,2820,21294 +65631,31696,53524 +46078,21479,71517 +22556,26782,95352 +57909,89474,90718 +26908,93117,6470 +4193,17943,63528 +94582,53548,26806 +91439,46752,89965 +19151,29376,30025 +34517,18287,728 +24648,11918,15813 +57993,65631,17885 +86395,11371,12450 +94083,68703,72799 +84868,18334,79734 +87468,82733,37435 +81881,61235,90661 +10730,13764,90086 +35779,68779,77639 +9941,69338,61636 +81336,91438,27717 +2564,2247,36409 +61886,47221,48987 +98132,19144,65889 +74469,56001,99231 +11783,57027,62666 +66775,95705,36163 +35806,81374,93928 +21670,51504,49170 +29006,2255,77588 +19016,23267,58245 +55353,51636,71755 +36024,40849,10679 +69513,5929,72687 +64068,98361,8020 +36526,71078,79420 +20804,1455,67240 +30402,51008,72479 +32555,21219,34348 +96076,22065,61485 +82143,22597,19022 +5676,37291,16344 +57508,36666,23614 +67902,51647,30421 +11365,33051,27880 +38729,59487,94583 +84185,90307,46246 +42653,8238,26425 +36895,76169,64351 +23918,71856,80169 +97587,54842,67440 +52875,19653,22096 +68254,69811,4234 +48579,55269,42497 +74492,83507,13968 +85337,44242,3891 +92517,29787,43539 +56889,22847,15682 +64622,55847,50665 +24387,71844,39376 +1956,30876,2778 +29113,14566,50548 +22934,69032,53344 +30355,81563,76111 +80317,36364,46275 +91247,26920,44919 +258,11717,7275 +64458,39622,73498 +88825,97496,14954 +47817,92548,34085 +83622,36823,93404 +50090,23465,40820 +91652,55938,57832 +17713,6539,7877 +43022,34730,30432 +97515,16106,95015 +59199,91542,21647 +60135,12299,67235 +13311,74243,29275 +87771,69529,75393 +64619,1141,20672 +49174,22740,17123 +45229,51006,50917 +95191,35073,35609 +470,77838,76337 +38802,51534,22615 +72786,70420,5462 +2043,32034,80285 +84590,47083,66371 +14004,74940,91284 +96119,48818,80808 +28276,67157,67851 diff --git a/2025/day08/main.go b/2025/day08/main.go new file mode 100644 index 0000000..1e45a9d --- /dev/null +++ b/2025/day08/main.go @@ -0,0 +1,83 @@ +package main + +import ( + "cmp" + "fmt" + "maps" + "slices" + "strings" + + h "git.bullercodeworks.com/brian/adventofcode/helpers" +) + +func main() { + inp := h.StdinToStringSlice() + solve(inp) +} + +func solve(inp []string) { + var part1, part2 int + pts := inputToMap(inp) + circuits := []map[h.Coordinate3d]struct{}{} + for _, b := range pts { + circuits = append(circuits, map[h.Coordinate3d]struct{}{b: {}}) + } + + pairs := [][2]h.Coordinate3d{} + for i, b1 := range pts { + for _, b2 := range pts[i+1:] { + pairs = append(pairs, [2]h.Coordinate3d{b1, b2}) + } + } + slices.SortFunc(pairs, func(a, b [2]h.Coordinate3d) int { + return cmp.Compare(a[0].Distance(a[1]), b[0].Distance(b[1])) + }) + + for i, p := range pairs { + var c1, c2 int + for i, c := range circuits { + if _, ok := c[p[0]]; ok { + c1 = i + } + if _, ok := c[p[1]]; ok { + c2 = i + } + } + + if c1 != c2 { + maps.Copy(circuits[c1], circuits[c2]) + circuits = slices.Delete(circuits, c2, c2+1) + } + + if i+1 == 1000 { + slices.SortFunc(circuits, func(a, b map[h.Coordinate3d]struct{}) int { + return -cmp.Compare(len(a), len(b)) + }) + part1 = len(circuits[0]) * len(circuits[1]) * len(circuits[2]) + } + if len(circuits) == 1 { + part2 = (p[0].X * p[1].X) + break + } + } + fmt.Println("# Part 1") + fmt.Println(part1) + fmt.Println() + fmt.Println("# Part 2") + fmt.Println(part2) +} + +func inputToMap(inp []string) []h.Coordinate3d { + var ret []h.Coordinate3d + for i := range inp { + pts := strings.Split(inp[i], ",") + ret = append(ret, + h.Coordinate3d{ + X: h.Atoi(pts[0]), + Y: h.Atoi(pts[1]), + Z: h.Atoi(pts[2]), + }, + ) + } + return ret +} diff --git a/2025/day08/problem b/2025/day08/problem new file mode 100644 index 0000000..e03bcbf --- /dev/null +++ b/2025/day08/problem @@ -0,0 +1,140 @@ + [1]Advent of Code + + • [2][About] + • [3][Events] + • [4][Shop] + • [5][Settings] + • [6][Log Out] + + br0xen [7](AoC++) 14* + +    [8]2025 + + • [9][Calendar] + • [10][AoC++] + • [11][Sponsors] + • [12][Leaderboards] + • [13][Stats] + + Our [14]sponsors help make Advent of Code possible: + [15]Kilo Code - The fastest growing coding agent because it is open. #1 on + OpenRouter. 500k+ Kilo Coders. 6.1T tokens per month. Try it today! + +--- Day 8: Playground --- + + Equipped with a new understanding of teleporter maintenance, you + confidently step onto the repaired teleporter pad. + + You rematerialize on an unfamiliar teleporter pad and find yourself in a + vast underground space which contains a giant playground! + + Across the playground, a group of Elves are working on setting up an + ambitious Christmas decoration project. Through careful rigging, they have + suspended a large number of small electrical [16]junction boxes. + + Their plan is to connect the junction boxes with long strings of lights. + Most of the junction boxes don't provide electricity; however, when two + junction boxes are connected by a string of lights, electricity can pass + between those two junction boxes. + + The Elves are trying to figure out which junction boxes to connect so that + electricity can reach every junction box. They even have a list of all of + the junction boxes' positions in 3D space (your puzzle input). + + For example: + + 162,817,812 + 57,618,57 + 906,360,560 + 592,479,940 + 352,342,300 + 466,668,158 + 542,29,236 + 431,825,988 + 739,650,466 + 52,470,668 + 216,146,977 + 819,987,18 + 117,168,530 + 805,96,715 + 346,949,466 + 970,615,88 + 941,993,340 + 862,61,35 + 984,92,344 + 425,690,689 + + This list describes the position of 20 junction boxes, one per line. Each + position is given as X,Y,Z coordinates. So, the first junction box in the + list is at X=162, Y=817, Z=812. + + To save on string lights, the Elves would like to focus on connecting + pairs of junction boxes that are as close together as possible according + to [17]straight-line distance. In this example, the two junction boxes + which are closest together are 162,817,812 and 425,690,689. + + By connecting these two junction boxes together, because electricity can + flow between them, they become part of the same circuit. After connecting + them, there is a single circuit which contains two junction boxes, and the + remaining 18 junction boxes remain in their own individual circuits. + + Now, the two junction boxes which are closest together but aren't already + directly connected are 162,817,812 and 431,825,988. After connecting them, + since 162,817,812 is already connected to another junction box, there is + now a single circuit which contains three junction boxes and an additional + 17 circuits which contain one junction box each. + + The next two junction boxes to connect are 906,360,560 and 805,96,715. + After connecting them, there is a circuit containing 3 junction boxes, a + circuit containing 2 junction boxes, and 15 circuits which contain one + junction box each. + + The next two junction boxes are 431,825,988 and 425,690,689. Because these + two junction boxes were already in the same circuit, nothing happens! + + This process continues for a while, and the Elves are concerned that they + don't have enough extension cables for all these circuits. They would like + to know how big the circuits will be. + + After making the ten shortest connections, there are 11 circuits: one + circuit which contains 5 junction boxes, one circuit which contains 4 + junction boxes, two circuits which contain 2 junction boxes each, and + seven circuits which each contain a single junction box. Multiplying + together the sizes of the three largest circuits (5, 4, and one of the + circuits of size 2) produces 40. + + Your list contains many junction boxes; connect together the 1000 pairs of + junction boxes which are closest together. Afterward, what do you get if + you multiply together the sizes of the three largest circuits? + + To begin, [18]get your puzzle input. + + Answer: [19]_____________________ [20][ [Submit] ] + + You can also [Shareon [21]Bluesky [22]Twitter [23]Mastodon] this puzzle. + +References + + Visible links + 1. https://adventofcode.com/ + 2. https://adventofcode.com/2025/about + 3. https://adventofcode.com/2025/events + 4. https://adventofcode.com/2025/shop + 5. https://adventofcode.com/2025/settings + 6. https://adventofcode.com/2025/auth/logout + 7. Advent of Code Supporter + https://adventofcode.com/2025/support + 8. https://adventofcode.com/2025 + 9. https://adventofcode.com/2025 + 10. https://adventofcode.com/2025/support + 11. https://adventofcode.com/2025/sponsors + 12. https://adventofcode.com/2025/leaderboard/private + 13. https://adventofcode.com/2025/stats + 14. https://adventofcode.com/2025/sponsors + 15. https://adventofcode.com/2025/sponsors/redirect?url=https%3A%2F%2Fkilo%2Eai%2F + 16. https://en.wikipedia.org/wiki/Junction_box + 17. https://en.wikipedia.org/wiki/Euclidean_distance + 18. https://adventofcode.com/2025/day/8/input + 21. https://bsky.app/intent/compose?text=%22Playground%22+%2D+Day+8+%2D+Advent+of+Code+2025+%23AdventOfCode+https%3A%2F%2Fadventofcode%2Ecom%2F2025%2Fday%2F8 + 22. https://twitter.com/intent/tweet?text=%22Playground%22+%2D+Day+8+%2D+Advent+of+Code+2025&url=https%3A%2F%2Fadventofcode%2Ecom%2F2025%2Fday%2F8&related=ericwastl&hashtags=AdventOfCode + 23. javascript:void(0); diff --git a/2025/day08/testinput b/2025/day08/testinput new file mode 100644 index 0000000..e98a3b6 --- /dev/null +++ b/2025/day08/testinput @@ -0,0 +1,20 @@ +162,817,812 +57,618,57 +906,360,560 +592,479,940 +352,342,300 +466,668,158 +542,29,236 +431,825,988 +739,650,466 +52,470,668 +216,146,977 +819,987,18 +117,168,530 +805,96,715 +346,949,466 +970,615,88 +941,993,340 +862,61,35 +984,92,344 +425,690,689 diff --git a/helpers/coordinate3d.go b/helpers/coordinate3d.go index 7cd50ce..4080a64 100644 --- a/helpers/coordinate3d.go +++ b/helpers/coordinate3d.go @@ -1,6 +1,9 @@ package aoc -import "fmt" +import ( + "fmt" + "math" +) type Coordinate3d struct { X, Y, Z int @@ -71,6 +74,13 @@ func (c *Coordinate3d) GetDownCoord() *Coordinate3d { Z: c.Z - 1, } } + +func (c *Coordinate3d) Distance(c2 Coordinate3d) float64 { + return math.Sqrt(math.Pow(float64(c2.X-c.X), 2) + + math.Pow(float64(c2.Y-c.Y), 2) + + math.Pow(float64(c2.Z-c.Z), 2)) +} + func (c Coordinate3d) String() string { return fmt.Sprintf("[X:%d, Y:%d, Z:%d]", c.X, c.Y, c.Z) }