diff --git a/AdventOfCode2025/Inputs/Day8_0.txt b/AdventOfCode2025/Inputs/Day8_0.txt new file mode 100644 index 0000000..20c6fd2 --- /dev/null +++ b/AdventOfCode2025/Inputs/Day8_0.txt @@ -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 \ No newline at end of file diff --git a/AdventOfCode2025/Inputs/Day8_1.txt b/AdventOfCode2025/Inputs/Day8_1.txt new file mode 100644 index 0000000..ca6f30e --- /dev/null +++ b/AdventOfCode2025/Inputs/Day8_1.txt @@ -0,0 +1,1000 @@ +21756,55854,50471 +60634,55363,26856 +46581,80134,49514 +51249,76468,86188 +89032,41793,41203 +35126,2547,78373 +65082,82062,70157 +83307,3582,73699 +37992,91363,1629 +31342,15700,12220 +27280,86712,46195 +63128,56698,61008 +63550,77438,13007 +46218,49987,34593 +7585,43797,79468 +74838,11465,90231 +89197,49603,5720 +91772,55052,60049 +52576,55719,98983 +72155,68044,36079 +20013,88791,7243 +64428,92609,56133 +35612,58474,1909 +83547,13439,51474 +1999,39426,73642 +64606,66960,28522 +99720,14946,12652 +64038,83848,66411 +66702,76238,56105 +56311,53482,81771 +62060,71580,96958 +8557,34809,76038 +66661,91031,61998 +61757,47973,32534 +11486,86578,87713 +64530,19508,77898 +87556,7217,1350 +5764,11965,69898 +50657,21232,72681 +91364,3985,97656 +9792,55649,61780 +21246,29215,74029 +45656,35031,80252 +73475,99926,18397 +74354,32,98583 +67900,286,34505 +28083,58495,81783 +30601,82896,95911 +35021,51941,31148 +98195,5726,85786 +98902,58905,23625 +5418,45846,76564 +86768,99719,94804 +79587,44686,73428 +60582,16410,59716 +82404,48159,14995 +95313,19369,49708 +80863,71726,22453 +28133,99341,88912 +83982,90756,25639 +97565,83994,9997 +89803,88037,32453 +62890,55479,8099 +48003,33343,58966 +40771,27878,40167 +14470,7957,23342 +31130,12867,81751 +54560,74155,14235 +8830,6092,7945 +51997,92273,94302 +7043,31461,45954 +97025,12761,34088 +87815,66823,68558 +86763,77081,96629 +33978,42147,15885 +81439,87884,50596 +25589,84587,42719 +8991,2270,11329 +95189,8742,42392 +56453,24051,342 +79571,93945,96465 +59828,64908,34015 +65280,12637,68311 +81621,80115,10417 +45583,87871,15420 +98742,57985,14854 +54007,79374,7333 +10807,90611,95101 +53070,67510,17717 +22572,58766,58810 +76545,87150,7342 +17911,46235,41390 +68139,32883,70802 +16401,68737,32690 +98632,44072,51761 +9309,15584,2175 +96580,11366,68009 +87670,79898,38604 +94429,23754,93152 +28701,57506,40129 +41260,24131,5271 +84570,12388,29229 +1241,67012,35700 +60172,76617,59086 +69906,73736,48744 +65422,84070,56266 +63634,5118,80649 +11006,96790,38881 +53984,99671,46536 +9640,93040,49815 +83486,31223,747 +11080,55018,24449 +71925,35938,56059 +15028,13825,30018 +59291,39610,6437 +96837,85989,60659 +40970,25878,842 +37205,83513,2751 +32969,95685,34469 +68084,84174,65675 +72951,7037,52629 +1262,26969,4658 +14560,75919,15683 +70939,2040,82000 +97980,92261,46204 +64322,93396,48340 +21728,88930,36337 +92799,284,75006 +84664,4586,63260 +71321,38812,1732 +22928,23857,80424 +70163,87402,82469 +10556,1483,79501 +20263,39955,84754 +79467,67005,49116 +39703,23433,78988 +17411,70144,15640 +12814,573,16563 +35361,34262,78544 +81448,66924,59369 +73657,27894,1512 +90877,57404,25337 +45808,16115,85734 +51714,88969,73027 +73609,1167,84807 +59426,93115,84501 +79952,60542,42220 +16383,85794,44798 +27430,30564,47149 +34392,60280,51066 +94302,92059,19638 +22958,87888,88508 +46771,98167,33990 +75755,43752,7615 +86125,3416,46044 +85749,83020,80263 +53453,53702,38172 +18601,78687,95489 +86305,59793,16523 +62699,60574,85264 +38366,27688,75421 +77091,74380,36268 +96719,28754,88331 +27246,11433,81499 +66994,28751,52505 +940,7106,77300 +74965,26965,67058 +53919,20792,56750 +69264,87659,2560 +23646,61560,37637 +99417,46236,24307 +53702,8683,62966 +3724,8130,68139 +73761,54255,38052 +38723,55284,33813 +93839,66189,39341 +48947,32144,69873 +71769,33374,55149 +3996,43590,36906 +87696,14026,87672 +34263,10734,50152 +7446,49207,69144 +79629,82841,51128 +31938,57853,30505 +73969,67243,17902 +67164,44053,69234 +33802,87770,79855 +31346,12901,63561 +46627,43726,6969 +43549,48441,23255 +74642,99211,13999 +83586,24604,43390 +57319,69101,59786 +26892,55294,10462 +88576,30230,98504 +87347,75386,22620 +15282,84045,46336 +19247,17,806 +17766,83247,61291 +94424,67736,57462 +42399,98470,60777 +78188,13115,51231 +71439,88752,26540 +98999,35581,93197 +25985,56258,12788 +42668,54298,81832 +37479,40885,99725 +61909,8806,66361 +29246,94241,54453 +2647,40768,11695 +55347,22919,71277 +12983,36776,9696 +47970,30975,86484 +86503,65863,37788 +17350,67136,28050 +86232,36821,75011 +36438,20579,48441 +74281,71908,59393 +93729,74272,36662 +89070,42009,96895 +39255,90040,68367 +24370,8278,6345 +88079,2591,5678 +22876,71872,58263 +39787,19012,78408 +79300,23650,60338 +56277,5659,91377 +85734,81160,18572 +36985,61044,68442 +942,22322,45174 +96402,60367,66829 +43542,69713,63006 +68487,77828,71924 +64108,56545,51859 +94016,46935,69666 +39772,74210,91924 +22692,14415,52770 +2722,39089,97961 +90384,64338,9796 +81074,46229,14652 +804,76555,83475 +76110,87727,54513 +7807,36400,94511 +31616,35617,40488 +62220,41477,90411 +81595,62030,7583 +91582,63828,91456 +37170,1999,77302 +84678,93078,58538 +39359,14603,21691 +11298,38786,36744 +85893,26960,88801 +1830,91304,74067 +77910,56565,97387 +52391,73618,29540 +69302,75267,14662 +13842,75112,78035 +43878,69439,41302 +43146,21531,69447 +99087,84118,92016 +55546,38065,67566 +93869,82330,11976 +21585,31211,59349 +45245,46719,5858 +17011,76292,24844 +23695,60077,53972 +93962,81314,44716 +12821,1152,42965 +44389,78757,59608 +81370,11413,63594 +62663,65707,7795 +59938,61291,86880 +66746,40034,1252 +54188,58725,36721 +70936,32463,9358 +62313,5939,7899 +45404,23867,76338 +31192,6095,69485 +88061,34489,35550 +50139,21049,14194 +85281,81619,10307 +14286,79402,19877 +27518,97824,87561 +24962,12295,10159 +77711,40404,25314 +82551,81707,89028 +87603,5082,58042 +17431,38805,82346 +17363,70612,94979 +33376,35108,58244 +36787,81115,91867 +73801,79906,8500 +93866,38161,10355 +13578,54092,77426 +41814,40143,87681 +79607,24665,72020 +54653,51751,6895 +76477,88123,65130 +85291,47471,78932 +4750,56837,3591 +57839,55751,70506 +24094,66978,64983 +19745,83465,43393 +14315,7087,58989 +32696,62873,51089 +14283,1123,39799 +9148,96077,43638 +55072,19741,52420 +75761,3059,57014 +82385,12267,47682 +66982,44181,48964 +37043,66296,77804 +79736,13203,24824 +77139,62859,75279 +86104,75259,44033 +63415,64074,75888 +2345,51238,69720 +77241,95758,35784 +92270,35083,89107 +68178,81075,6796 +76869,74516,36958 +3830,199,24173 +36023,66269,70371 +39057,30718,9818 +74480,30228,28673 +95569,62273,52619 +60963,39000,11381 +90765,59924,23108 +91026,11203,59712 +67231,98130,25202 +67892,47307,14213 +9664,86368,73924 +24020,96967,58025 +34259,77450,5476 +21,54646,53189 +82012,44519,67994 +66263,33176,26843 +89467,31105,52725 +43994,43880,58084 +2874,2874,16991 +94085,75117,7451 +52721,68634,64708 +12807,10142,36118 +17276,37137,63454 +4574,97864,51364 +49147,62701,45265 +11252,75663,92634 +87471,5415,39541 +27540,39035,31297 +79670,54366,85673 +92201,28634,4690 +95349,14391,31576 +35175,14166,91877 +32550,96069,97354 +76043,23383,76512 +54661,81013,97758 +12298,21128,87613 +4202,40879,91033 +7803,85976,93374 +18394,47099,87562 +60725,12300,49417 +89375,55004,61571 +71916,61974,84377 +59135,57287,54223 +56201,62397,7962 +7111,34809,98263 +27043,15397,84309 +78628,50550,6425 +80370,38884,26433 +21668,44683,4625 +89665,38440,40501 +63152,76732,62193 +24015,1141,24536 +23657,14032,28838 +11016,88373,68660 +57201,40650,1706 +22827,16360,26093 +62026,82294,92697 +6119,14308,9336 +34772,3995,50778 +850,4167,23676 +73581,13045,71604 +3639,34654,46919 +28192,69633,2361 +77878,70051,13568 +84000,690,46973 +61745,43465,10248 +43642,12695,18248 +49929,88825,24220 +48218,15786,93304 +7483,57402,97689 +82705,59983,71019 +91705,74665,1282 +33765,13114,10362 +97857,16424,41265 +74433,4299,40053 +8107,62286,55427 +7911,7034,93917 +11187,51909,10599 +44357,47154,73409 +90400,4960,57308 +77731,83783,939 +71687,71671,36253 +39032,14410,56834 +9890,17158,32353 +15676,13753,93730 +1820,48108,16979 +38162,80415,84544 +16832,92604,70201 +25716,77690,96427 +22015,53786,41355 +13998,61498,25745 +50005,69490,96550 +15226,69771,12534 +60896,68347,61823 +99960,16810,2573 +8675,92884,34484 +13565,63514,97304 +59288,86375,79838 +59621,89727,95877 +85588,6549,6902 +52932,61115,59258 +4967,22411,42257 +72957,75724,35802 +9992,50968,48850 +12864,15876,53680 +2344,25617,79655 +91025,50948,5357 +42140,27474,29133 +44208,55112,92667 +90756,51749,91376 +31819,968,32404 +95175,27854,43867 +78400,7410,13107 +78821,67375,65087 +70321,61297,93924 +22198,10041,83203 +95029,84077,40358 +60813,84173,11799 +2994,3528,35702 +92345,890,77507 +46506,97239,52787 +48288,97290,62752 +71744,55019,80327 +22445,21202,65303 +8961,43916,74386 +58442,68977,60629 +12509,31312,70692 +23496,92936,55340 +59208,10437,406 +95842,99186,43081 +38947,42224,68824 +43570,7953,65565 +39039,79430,37211 +90420,30494,56792 +89478,32203,99570 +30719,7771,47505 +10318,62910,22869 +79625,72359,11021 +5331,58251,23407 +27704,58261,53877 +82255,61391,91461 +62551,5576,22777 +84904,43654,25547 +31766,57221,86826 +90156,17887,71760 +98169,52934,74274 +84286,70142,82044 +80590,9432,4333 +62127,15637,31182 +56597,17249,85849 +31060,55822,75115 +44001,57856,41500 +45547,63797,18104 +72921,88516,53839 +56671,80420,76304 +29914,3207,73851 +1982,41495,40747 +57442,83032,48642 +66882,55869,49179 +33488,51651,61720 +71026,78824,87318 +17550,78701,59873 +87591,39972,74166 +37313,43307,42432 +58077,55758,20539 +76550,61956,95760 +89211,68595,3098 +85493,66135,2496 +5917,94781,17781 +88771,66783,36107 +93757,50274,75658 +19589,1786,61234 +57568,19238,15788 +51880,9250,31670 +58626,62958,94673 +54122,74911,24551 +29976,92179,13441 +83481,50135,78086 +56179,553,62102 +44481,45687,40356 +71568,45603,86605 +35342,32001,45620 +91802,95295,27533 +32084,49238,71837 +27760,49498,42233 +63825,68222,54429 +30911,47640,30392 +48144,15002,40683 +48201,56760,43308 +6748,22776,71702 +9939,8217,15059 +86803,5507,17618 +28687,32621,47795 +55678,28095,6094 +52813,5423,33585 +75034,76702,13578 +34525,35449,41507 +77900,91248,56411 +84767,99158,97198 +36088,52001,61413 +25943,45313,92064 +76566,37475,66340 +53987,66674,98478 +66439,7912,58450 +29615,34043,86257 +72033,16331,62157 +29999,14480,58957 +85536,21226,46325 +32957,68291,30825 +6665,35149,33600 +29532,32961,99478 +21224,23839,41395 +33804,28703,33688 +82306,3127,23183 +26801,13739,25258 +20639,41372,50307 +51128,93110,43100 +20838,37418,40904 +78743,77956,36177 +21613,63082,38106 +91262,60103,2094 +28349,50193,30218 +46976,84460,42130 +39230,52160,85950 +96761,7540,88530 +50985,57711,98828 +29594,16128,89453 +57942,74260,31160 +42096,13199,51899 +46999,70204,98790 +24462,6327,21124 +68911,11485,54469 +46107,4233,44067 +18541,92186,17783 +99303,13645,5538 +30661,85543,69960 +23204,90971,4640 +49923,4131,99195 +94937,18435,7591 +32855,36740,76472 +42502,17630,2824 +46225,47042,1569 +41864,63565,46908 +48455,57066,77128 +10315,59276,58102 +10362,16562,55029 +26910,27470,76231 +46389,9972,72262 +48426,77197,77117 +62542,53201,48937 +23376,15849,54694 +16703,22302,25445 +17267,36329,10782 +70380,8148,44828 +23649,28848,26011 +67945,36324,19920 +86286,79990,82907 +51826,46630,41325 +21031,33372,36354 +21357,21825,63739 +83047,82136,89473 +61093,50283,66097 +9113,4993,99148 +56705,90901,36163 +21113,82473,11613 +90599,13064,21549 +50256,6051,50576 +58743,1480,66580 +80861,11194,17480 +86094,91312,98739 +47008,41563,97129 +5492,87115,70081 +36563,88975,51161 +36314,14576,10710 +54468,55186,15233 +19256,78899,42507 +25180,34866,59417 +38606,10833,99048 +32098,58657,51321 +37110,44501,21489 +99092,75215,89123 +75975,66931,83359 +19985,12049,90940 +23245,25086,19765 +5912,46008,85360 +54291,75034,53720 +68310,13052,17883 +44172,4098,21318 +77217,48539,28784 +18280,99809,32806 +66453,2943,92996 +17266,55079,30201 +66099,13900,3761 +86167,3570,42997 +37750,38478,19503 +61098,36847,74065 +55927,69273,79177 +52096,50475,20228 +51104,13698,73215 +64788,92575,79276 +23588,72561,91221 +6918,62790,91061 +76130,86439,6198 +25069,59707,59270 +6327,89715,32194 +17621,56772,22499 +85040,81665,48821 +653,65986,41802 +18088,59786,97704 +97086,51513,20148 +3456,9781,53999 +10154,15284,20346 +37482,8802,13732 +44485,27548,74142 +91476,72717,38108 +63241,8032,59039 +42883,97955,28064 +65273,43568,72639 +13954,95436,63802 +5618,83777,34831 +71214,91349,91729 +3329,77681,38821 +39465,44657,91927 +72320,67337,33222 +95138,738,95105 +68395,96453,22507 +6307,1296,62986 +55664,80909,60201 +41232,61059,41558 +94070,20857,45046 +62162,76613,86379 +83875,98849,20336 +50350,42245,5410 +56450,27268,63961 +34163,85020,49621 +83366,52220,83864 +25506,46046,8801 +55097,16045,79507 +16007,56636,65189 +26026,80019,11164 +34925,37001,77219 +56913,95897,41091 +77708,29976,53159 +86539,2745,74811 +75192,34713,70890 +23021,63373,49491 +56444,66645,90290 +2250,1791,64116 +36234,50305,99493 +39017,21060,67471 +79740,75048,16475 +17593,1582,37614 +4678,88143,82368 +2438,41645,3270 +96957,85260,76030 +39613,7332,11306 +51657,89105,23007 +57640,87327,79406 +54267,41195,31924 +43088,73192,7063 +55453,52926,93692 +19291,73206,34191 +81121,44750,46178 +60629,97254,1588 +37243,13470,27965 +70349,80666,70417 +62045,17964,88834 +21827,31559,93705 +41570,25497,60596 +29948,92236,90378 +32278,28436,63562 +67574,87757,70962 +72568,58031,38113 +49394,16259,68022 +55799,28006,11389 +42694,29393,96893 +26294,35535,9905 +41048,79679,67504 +52185,79353,39673 +47757,97639,41754 +11179,61492,48668 +73044,95568,36567 +28025,26777,84346 +25326,82602,42681 +68360,41873,98533 +62431,12188,77068 +18560,9852,35988 +37227,51623,47419 +35757,70342,4627 +77604,49585,22009 +46333,18134,79365 +7853,90095,78991 +11885,69611,95040 +67143,53344,56899 +81975,54979,20018 +18768,20643,59579 +83674,10363,7158 +82836,92110,96075 +35224,74482,6883 +26542,701,69971 +68523,93301,24322 +84902,159,37223 +77815,75009,58090 +52121,6337,38732 +69199,20692,8058 +58965,42364,27641 +32089,82642,75273 +33539,72711,79473 +44815,17667,65453 +97037,3362,33435 +32260,76548,82524 +85432,63487,12804 +77946,91091,63830 +86642,26467,78241 +30942,94351,68449 +46506,58046,6593 +10322,46197,26732 +36815,49257,43684 +59123,34251,68369 +99496,77819,13067 +90412,23013,52730 +44330,59682,39575 +51504,78095,32788 +10779,45118,25424 +34046,36587,62915 +24778,38060,65526 +98006,93184,6149 +74689,60613,33378 +32921,9455,85370 +36117,70634,19 +60609,98610,40865 +80973,50440,30991 +22282,15727,81569 +62752,9453,80543 +19110,98582,67990 +56029,32167,31003 +96145,46138,69360 +57269,30221,36957 +15290,96227,71555 +86889,65402,71945 +45144,25347,43208 +54153,35453,23941 +39966,88775,53004 +89559,2831,47289 +17857,36034,48476 +92527,63065,95542 +70816,36028,55247 +84027,24812,22503 +50978,90051,54596 +58828,90234,93335 +39939,35557,12551 +69214,27220,9819 +41937,6173,1914 +10257,54617,65062 +31495,31851,33877 +76537,38564,44896 +51068,95296,52020 +95739,46371,70020 +72652,13952,30106 +12229,92467,12336 +81213,47808,33360 +12438,87387,55733 +49899,3057,87843 +59673,47682,35763 +38972,61975,47870 +36654,2275,44258 +20626,13802,37822 +4808,75779,25234 +92707,36645,44064 +42283,78141,49946 +83139,60924,89073 +12961,70703,31983 +2910,83366,94371 +66099,97664,59700 +51799,26817,11712 +34854,42221,24698 +66571,41481,65106 +25584,38368,55231 +66075,59904,72808 +55083,52995,78960 +30785,21508,85178 +24376,47824,99943 +49760,23267,19141 +44509,65663,1843 +55595,2688,73788 +59472,96732,75870 +35631,75025,51086 +20371,25799,29333 +1290,23209,32511 +98619,72455,95907 +27342,49336,37942 +19953,86159,18234 +24317,64127,25401 +76176,97522,66206 +87408,15932,60393 +92066,36746,92720 +8505,18640,2218 +9424,60441,5715 +54386,24206,97697 +30514,59832,60369 +55483,21270,16926 +80239,99457,87435 +95904,5982,94915 +58389,72204,9695 +28084,95863,26897 +77807,17120,82151 +63572,75591,60257 +33447,55674,86898 +6378,80313,42236 +92703,9588,62931 +59802,35546,93238 +32942,62347,21898 +13736,44694,93901 +46858,82114,96076 +56876,45275,39479 +76797,64900,21618 +23410,8505,46640 +18089,19211,86035 +62116,2805,2631 +9719,91254,85541 +69517,22668,94419 +88506,17049,84219 +43510,41726,48502 +94039,68338,49091 +80708,61253,72392 +5331,41455,19079 +35150,33012,73212 +50066,86992,75820 +24974,31306,77319 +4769,51367,68064 +49306,19437,28482 +32736,36455,9964 +90327,1898,39888 +67116,35035,15275 +72365,18775,12832 +7951,39228,39345 +554,71783,99542 +33584,72575,28368 +27291,74009,73416 +77676,94780,59151 +80967,71494,83831 +22443,64816,35723 +7583,24419,5262 +81494,92878,96183 +54391,41682,33677 +13877,20443,903 +16236,92333,15288 +46450,31156,13407 +67278,12011,2885 +98978,8225,61603 +68639,608,54596 +28223,43844,83761 +25004,79533,95348 +12841,45100,94916 +65346,98504,58564 +56795,14083,7562 +90673,38829,39895 +19833,89002,37795 +95604,57181,98524 +1471,96388,39134 +12840,44284,7018 +59422,20922,50135 +51014,68247,96229 +67465,51968,76698 +95110,31795,16504 +61852,54426,44358 +39747,77766,86130 +69551,51802,68220 +57173,34611,72865 +64099,90099,87603 +76580,41630,48154 +80015,61179,59967 +80244,18991,20298 +88355,99025,82835 +78338,57561,79359 +8356,86460,18595 +75881,56831,56144 +68311,83507,80477 +62369,31981,77474 +6882,27533,60883 +73843,91163,10147 +87282,81904,87702 +83699,76158,44678 +69157,6855,40840 +56412,712,45425 +83002,9336,14670 +20460,89793,37178 +94241,38343,61638 +14866,54350,62844 +23240,57416,31743 +52783,83593,71273 +15844,166,47980 +2377,57186,4725 +36472,69928,48164 +61381,1027,67583 +65798,8529,39449 +60146,55696,86599 +5861,46744,48927 +80674,53816,43191 +7043,37954,45129 +1569,37330,99907 +29479,94703,75885 +67051,44733,32892 +32987,2598,62124 +7744,76985,74106 +24343,25487,85624 +4646,63894,27524 +2692,70688,11970 +19186,12216,32310 +15541,21391,4677 +22049,30447,83829 +7380,43490,7365 +13520,8396,63309 +52117,77513,93386 +87657,37846,56044 +92832,22258,84937 +67947,49,3017 +84372,97345,90307 +38059,19588,67220 +3566,86928,84429 +18349,60680,84034 +83534,50982,22537 +65853,5579,88767 +71682,23991,19619 +46853,83536,89731 +31236,75134,46614 +4737,93284,8264 +25245,58674,40085 +46457,8821,35237 +21658,38629,33837 +17926,71773,60869 +19721,12483,83651 +90324,78397,10664 +46918,63331,55894 +71477,51691,14292 +47530,88013,25033 +25966,66029,79899 +92389,85236,92930 +50766,64771,54258 +3600,7785,86490 +66972,50394,97370 +64693,10884,34559 +57757,19383,74853 +4411,67058,5104 +70378,69057,25411 +34414,77670,78830 +16194,86185,16445 +82152,25100,72189 +14261,63140,47489 +84299,53077,19956 +94681,16447,1090 +696,76982,41260 +35681,68007,72834 +12222,15818,32555 +80960,82141,26340 +51809,60266,46057 +29710,29932,87762 +478,24029,21658 +2761,38602,21527 +31038,19751,27053 +96832,28512,11287 +35170,6577,18799 +63642,40466,8750 +42799,10716,85271 +9682,82322,77985 +19087,80395,18980 +55551,9273,4040 +82788,97494,91368 +43910,61996,24653 +69872,24867,60011 +45346,19961,25310 +6360,29908,93850 +90460,11072,1654 +4663,16803,2121 +81026,62305,70892 +86479,28320,25602 +243,11476,31128 +32218,59128,85389 +28309,81727,5251 \ No newline at end of file diff --git a/AdventOfCode2025/Solutions/Day8.cs b/AdventOfCode2025/Solutions/Day8.cs new file mode 100644 index 0000000..d3d7744 --- /dev/null +++ b/AdventOfCode2025/Solutions/Day8.cs @@ -0,0 +1,165 @@ +namespace AdventOfCode2025.Solutions; + +public class Day8() : Solution(8) +{ + public override string SolvePart1() + { + List boxes = Input + .Lines + .Select(line => line.Split(',')) + .Select(parts => new JunctionBox(long.Parse(parts[0]), long.Parse(parts[1]), long.Parse(parts[2]))) + .ToList(); + + IOrderedEnumerable<(JunctionBox Box1, JunctionBox Box2, long Distance)> allPairs = CreateAllPairs(boxes).OrderBy(pair => pair.Distance); + + const int numberOfConnections = 1000; + var countConnections = 0; + + foreach (var (box1, box2, _) in allPairs) + { + if (countConnections >= numberOfConnections) + { + break; + } + + box1.ConnectTo(box2); + countConnections++; + } + + IEnumerable networkSizes = boxes + .Select(b => b.Network) + .Where(n => n is not null) + .Distinct() + .Select(n => n!.Boxes.Count) + .OrderByDescending(size => size); + + return networkSizes + .Take(3) + .Aggregate(1, (a, b) => a * b) + .ToString(); + } + + public override string SolvePart2() + { + List boxes = Input + .Lines + .Select(line => line.Split(',')) + .Select(parts => new JunctionBox(long.Parse(parts[0]), long.Parse(parts[1]), long.Parse(parts[2]))) + .ToList(); + + IOrderedEnumerable<(JunctionBox Box1, JunctionBox Box2, long Distance)> allPairs = CreateAllPairs(boxes).OrderBy(pair => pair.Distance); + + JunctionBox? lastBox1 = null; + JunctionBox? lastBox2 = null; + + foreach (var (box1, box2, _) in allPairs) + { + if (!box1.ConnectTo(box2)) + { + continue; + } + + lastBox1 = box1; + lastBox2 = box2; + + var isolatedBoxes = boxes.Count(b => b.Network is null); + var distinctNetworks = boxes + .Select(b => b.Network) + .Where(n => n is not null) + .Distinct() + .Count(); + + var totalCircuits = isolatedBoxes + distinctNetworks; + if (totalCircuits == 1) + { + break; + } + } + + return (lastBox1!.X * lastBox2!.X).ToString(); + } + + private static IEnumerable<(JunctionBox Box1, JunctionBox Box2, long Distance)> CreateAllPairs(List boxes) + { + List<(JunctionBox Box1, JunctionBox Box2, long Distance)> pairs = []; + for (var i = 0; i < boxes.Count; i++) + { + for (var j = i + 1; j < boxes.Count; j++) + { + var box1 = boxes[i]; + var box2 = boxes[j]; + var distance = box1.DistanceTo(box2); + pairs.Add((box1, box2, distance)); + } + } + + return pairs; + } + + private sealed class Network + { + public readonly List Boxes = []; + } + + private sealed record JunctionBox(long X, long Y, long Z) + { + public Network? Network { get; set; } + + public long DistanceTo(JunctionBox other) + { + var dx = X - other.X; + var dy = Y - other.Y; + var dz = Z - other.Z; + return dx * dx + dy * dy + dz * dz; + } + + public bool ConnectTo(JunctionBox other) + { + if (BothNotInNetwork()) + { + var newNetwork = new Network(); + newNetwork.Boxes.Add(this); + newNetwork.Boxes.Add(other); + Network = newNetwork; + other.Network = newNetwork; + } + else if (OnlyOtherInNetwork()) + { + other.Network!.Boxes.Add(this); + Network = other.Network; + } + else if (OnlyThisInNetwork()) + { + Network!.Boxes.Add(other); + other.Network = Network; + } + else if (NotInSameNetwork()) + { + var target = Network!.Boxes.Count >= other.Network!.Boxes.Count ? Network : other.Network!; + var source = target == Network ? other.Network! : Network; + + var sourceBoxes = new List(source.Boxes); + source.Boxes.Clear(); + + foreach (var box in sourceBoxes) + { + box.Network = target; + target.Boxes.Add(box); + } + } + else + { + // Already connected + return false; + } + + return true; + + bool BothNotInNetwork() => Network is null && other.Network is null; + bool OnlyThisInNetwork() => Network is not null && other.Network is null; + bool OnlyOtherInNetwork() => Network is null && other.Network is not null; + bool BothInNetwork() => Network is not null && other.Network is not null; + bool NotInSameNetwork() => BothInNetwork() && Network != other.Network; + } + } +} \ No newline at end of file