From 5a70dd3810e665bae6d1fde6f5745dde0b4a42ac Mon Sep 17 00:00:00 2001 From: Nikhil Vengal Date: Mon, 15 Dec 2025 00:30:08 -0800 Subject: [PATCH] Solve day8 --- day8/input.txt | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++ day8/part1.py | 61 +++ day8/part2.py | 63 +++ day8/test.txt | 20 + 4 files changed, 1144 insertions(+) create mode 100644 day8/input.txt create mode 100644 day8/part1.py create mode 100644 day8/part2.py create mode 100644 day8/test.txt diff --git a/day8/input.txt b/day8/input.txt new file mode 100644 index 0000000..20ee62e --- /dev/null +++ b/day8/input.txt @@ -0,0 +1,1000 @@ +63538,35975,6036 +62007,91073,28432 +37830,29993,86856 +78327,9264,49554 +26915,51616,78731 +36611,9427,38471 +24684,64944,33926 +714,89567,56501 +19419,5354,37361 +59581,49971,4485 +62304,39975,49586 +1782,37208,37994 +14749,73771,16414 +12926,28109,53978 +54488,92503,53295 +5690,80786,19409 +64666,96799,91304 +79617,523,91727 +12020,62437,80329 +11279,27040,32587 +90050,3399,95234 +47628,91906,64675 +41018,75754,40501 +54220,59243,19601 +4049,24901,26622 +30647,72881,39988 +39107,69396,45741 +50950,67682,81177 +83799,40687,36088 +82695,11697,18885 +10166,95936,80991 +26822,57446,93250 +33757,28963,90007 +89191,60025,50584 +66740,3680,12564 +53648,71412,39065 +64008,17966,39011 +36681,85556,28535 +9011,71304,21739 +31788,94657,83695 +93793,58626,71969 +60082,4008,67598 +80808,25193,37139 +10942,58498,93519 +72593,94454,79658 +7020,75029,91087 +85137,883,21984 +80882,49486,70603 +38342,56208,56796 +40883,29987,32596 +45981,51324,66807 +99651,10723,6062 +40120,93070,29033 +79000,75952,53719 +80430,6931,96029 +653,33242,37166 +87768,96007,44019 +61365,36180,36600 +69243,63727,30039 +12180,5476,29676 +35685,17309,27264 +4568,20767,63359 +7186,3870,51345 +80948,74398,63795 +6106,29928,87257 +80774,85890,93826 +72723,29610,12957 +55117,76205,23047 +37828,55019,96612 +93112,10630,91623 +74116,39510,44497 +9171,94564,18899 +49930,62335,61634 +96831,57593,86812 +23306,70920,62571 +82328,75941,8247 +12851,79173,80142 +44816,58987,53434 +26343,31861,68510 +20158,73252,8833 +58426,34980,33179 +50976,90848,92022 +99037,9437,21622 +14693,48462,1997 +59264,93265,40655 +54852,33406,52304 +57004,61608,48289 +7319,62502,50007 +286,45064,62716 +4294,19364,88870 +51699,19777,86315 +69141,36378,93649 +21362,40993,49493 +23869,9527,83792 +38368,76548,55553 +90722,23052,36374 +60716,46246,32676 +7901,8078,83322 +51238,35726,86573 +74373,76970,45553 +90983,6207,36736 +26707,99946,11535 +7607,19822,61499 +22332,11292,95140 +41433,93362,38117 +230,8449,39838 +70852,78024,18577 +89828,55109,53197 +4573,69833,63032 +17152,91597,97545 +26417,8747,24026 +27414,50597,52582 +57883,87089,32946 +31752,15407,12380 +91561,3906,11429 +67998,97875,23785 +2446,65578,9021 +81801,17909,20173 +14679,65352,56814 +34384,71944,70190 +51296,54534,68903 +45085,50520,96574 +71993,20150,83701 +8105,7749,12430 +48960,85686,60752 +755,6555,49067 +36135,33413,49955 +32933,6824,59135 +88299,65909,8351 +25279,8923,90821 +42872,52325,41433 +41406,40279,95092 +15880,31889,98974 +26804,80043,66995 +88804,9856,6019 +22261,60506,38189 +97911,35988,32200 +81239,92415,54263 +46354,23132,86791 +65119,38141,56733 +6703,84883,76348 +58238,44675,33073 +24423,70838,21617 +67599,85607,66705 +94624,91937,1582 +24839,7877,83964 +47865,62381,46209 +2914,36273,31806 +47112,78299,89878 +53074,83606,71174 +89643,84623,82443 +73912,14652,60190 +57124,6415,65859 +79181,38765,2548 +2495,50171,88190 +15403,52545,52306 +85918,10054,25804 +14689,71784,40797 +47093,74573,49697 +10768,96014,81193 +74838,96470,40639 +71822,97936,50711 +59262,83170,84311 +13791,74950,36031 +41994,5386,71113 +70326,54435,5580 +96557,26132,97484 +81847,10090,92933 +39061,74853,7179 +52439,42413,16671 +34735,51708,72087 +44037,49785,84509 +95678,61540,49626 +64818,76627,56951 +75662,21623,14441 +26412,21986,67024 +41861,10690,9355 +17479,74926,6550 +82472,22454,5468 +7406,65627,56269 +58015,54196,51205 +2123,19058,77057 +75376,36014,8290 +68253,53269,50093 +54222,11323,45914 +26815,73235,66060 +26679,38032,27600 +66191,15096,36658 +57881,70202,80203 +86917,84806,36127 +58503,35454,49408 +90272,28442,16795 +85098,76260,74191 +59190,76131,4576 +17221,70730,71351 +50703,504,40388 +65732,50023,53625 +47478,93188,14880 +19004,88502,58735 +9787,71875,68898 +75076,97674,56806 +74469,14973,47768 +98801,2774,85705 +35218,30414,57293 +23127,76522,30778 +59450,70170,22329 +66610,27376,86440 +61019,97780,81570 +52287,89868,95066 +31256,11297,54460 +69602,50222,752 +86704,32011,85458 +69604,34322,54303 +37891,79969,43525 +64632,83375,40785 +56954,49589,48932 +73994,22352,1876 +48400,64669,77199 +34105,1579,80362 +10467,78834,88981 +52676,85932,27517 +22080,19504,293 +89185,66830,11450 +2826,5772,41132 +94984,7869,72916 +98206,30429,24283 +31073,5563,69997 +21687,5066,70027 +72860,67191,44875 +44077,96320,40952 +15281,67478,88359 +67991,76601,54899 +43393,57727,17696 +77868,34353,93534 +40811,15261,27205 +60996,45975,56695 +53622,95303,31160 +47943,31374,92268 +69308,16138,5637 +91789,70817,18464 +46086,62222,11751 +23720,90493,95158 +45847,77991,24499 +45714,9478,79365 +35997,7833,30607 +11720,70757,8565 +18387,72837,40809 +2183,12364,164 +28953,83682,27906 +10312,79548,62283 +36080,51734,38144 +6350,45981,38809 +79368,10492,19737 +18954,55006,38949 +94894,90259,71752 +63626,35561,67788 +22702,63889,97916 +13177,8144,63574 +13185,29841,82258 +201,42733,59231 +3519,5425,97023 +30527,81029,4018 +79203,44442,38109 +42525,82061,52845 +31753,46102,46170 +10298,4230,82384 +59744,66010,15253 +20574,24903,68777 +32535,99883,28836 +20929,32,28200 +85209,27095,70002 +85038,64846,90432 +72772,94851,24326 +52893,10562,11354 +96062,11125,35219 +31177,98399,58710 +98533,57818,4188 +65886,24947,13038 +11727,55718,34887 +42668,53296,31288 +60200,63969,59847 +51057,16838,30273 +52034,2572,92292 +50640,19183,40516 +32394,53855,70900 +356,72979,60268 +38138,78901,13222 +56205,68993,57834 +8770,14935,12360 +94098,21547,88183 +32703,85018,79302 +91916,20381,47667 +9810,20490,92637 +7432,42751,61445 +54880,34755,45387 +18051,64455,80673 +37601,23713,9570 +59155,36963,98342 +54283,89408,17229 +25457,71985,15559 +33951,45066,80053 +49570,21366,63155 +28474,60340,95906 +76796,86381,45977 +96854,34606,9202 +54677,44940,76614 +72452,54025,28998 +83617,88254,19357 +20902,73158,9963 +13794,34386,93531 +6706,49325,56477 +26154,1257,47606 +96238,24491,5007 +97836,77290,10215 +16600,38019,94110 +56630,35105,55019 +10770,9514,53915 +12167,91239,96796 +72448,13730,56730 +32944,84327,10557 +94841,29912,63319 +36754,32506,34458 +82493,53635,97370 +47792,23932,13751 +55965,76499,91996 +57854,40039,67980 +54288,23748,70824 +5794,42952,94431 +13813,63084,42008 +99589,50448,20245 +21485,28669,27666 +57153,9182,24409 +38671,93262,88917 +25417,29053,9757 +98723,77030,99144 +87586,62242,57170 +57329,741,5842 +83138,48384,34509 +96863,5263,47328 +49046,34872,22115 +41848,76381,57613 +1793,77295,47484 +2141,85643,67324 +70373,24682,20123 +73108,72061,11392 +83497,75332,29688 +57388,85209,38965 +29191,99970,44366 +42383,34783,30584 +41510,83696,37078 +91115,65126,19681 +81611,66043,85831 +51368,98564,90555 +20700,67202,46504 +4288,45265,45030 +11912,34080,58393 +11095,38028,1115 +56210,53283,83254 +26803,65613,90920 +75020,87446,79496 +50742,49897,14589 +17892,82542,76937 +1170,68749,45524 +97137,93386,85329 +92291,77805,85267 +94400,89584,52977 +93242,99931,18546 +78218,47811,14102 +51006,74848,70269 +63699,67981,31252 +96279,71841,71276 +424,2131,7937 +95455,17552,91193 +2653,95150,20571 +10368,97919,8899 +2530,12197,17584 +65856,46712,26396 +13880,43530,84271 +93476,44473,24208 +87115,77063,29214 +63358,34626,64833 +4064,36625,17049 +90364,49882,92152 +7920,29690,8139 +4087,26286,12257 +75145,10929,41845 +22028,76601,71750 +54081,81454,89139 +84508,3259,10451 +83802,67249,76556 +30682,95176,95778 +38032,59523,60934 +44608,94302,70063 +60284,73064,68511 +15999,912,277 +93357,44777,60757 +34962,57951,77660 +8634,64357,32152 +96604,55978,75959 +89653,38045,80540 +9205,9233,51876 +21519,52607,51969 +18901,18103,88502 +49017,84163,94456 +90662,68378,66355 +10952,95132,33915 +27307,61421,32658 +81328,94137,94943 +35542,79632,48032 +4593,25960,30948 +82735,76171,59204 +2503,98989,69146 +50511,91263,21193 +96988,13572,80622 +84091,42444,2213 +9326,51188,37730 +82721,32966,55596 +33414,95684,47802 +37200,91253,54702 +53619,28130,54335 +1003,27444,78863 +56491,2567,41903 +38676,36626,83003 +2197,1996,71956 +57105,63377,3536 +57267,68925,76839 +13357,50409,95507 +61600,23360,13141 +30337,94653,80816 +81933,69495,15982 +65580,56799,28755 +80982,5433,44158 +48891,7215,9909 +99134,40796,27414 +84814,95660,62192 +8467,77052,91869 +48385,40898,28210 +31344,74357,67919 +73379,25994,52261 +62295,72904,47081 +53896,86189,75014 +21003,42922,79629 +68801,94995,46218 +20827,43660,34202 +42144,22745,43463 +10436,88331,69267 +13442,89362,10339 +28157,33447,57048 +71138,91531,13154 +9662,276,5496 +69392,67318,79881 +34421,91512,41089 +26063,20317,32143 +52504,20773,10084 +94371,69425,7797 +31906,55066,18131 +72370,63552,2319 +66395,46903,89321 +33781,48998,83974 +36244,74692,48759 +84961,94048,18671 +21171,80125,95369 +61748,97854,99688 +83448,7820,57445 +20239,52827,40573 +66522,95723,75644 +28458,67531,5458 +41407,2326,95346 +55038,43476,93499 +4500,21018,50968 +68450,70793,22014 +52901,46432,25027 +51714,52757,41762 +84107,11614,9452 +62623,62504,10531 +56152,4632,91707 +45591,5349,57970 +9353,76019,48841 +60982,35345,41288 +49361,66906,57648 +42739,68815,81401 +53454,357,91739 +90908,65668,50876 +44552,51394,3855 +70582,27283,85925 +2033,76094,18359 +41650,22393,83023 +71101,52605,68817 +28742,37102,16178 +62118,98787,53607 +16667,20351,32731 +54405,69253,93230 +35033,74016,38487 +35337,95308,78152 +84888,70707,66870 +73717,24109,47498 +40225,33611,54194 +90610,85801,89578 +67701,29305,46672 +6527,65922,70029 +53445,47027,9374 +92801,85359,54848 +75442,9733,99671 +58036,30668,80845 +27736,7852,31615 +57486,34240,89855 +22784,35993,60445 +96698,14085,49434 +72572,6770,63132 +35,32794,894 +11229,62949,17880 +91935,86086,48431 +65102,74789,81924 +45784,7485,987 +8928,42077,22123 +81597,2579,91127 +2726,51478,40054 +35212,47577,28929 +99819,61077,39087 +57870,53300,12727 +63387,69472,8760 +22098,55980,80393 +59551,42746,60343 +3205,76958,45156 +94099,67987,44825 +21077,45676,93377 +54982,40550,82326 +40424,72637,52952 +67444,87560,75900 +42831,35888,72807 +67650,64487,5635 +17114,28099,34762 +52796,16830,7533 +61353,5526,33750 +68476,919,26534 +30143,30204,6387 +31325,89587,61275 +16274,61326,25517 +83543,12609,53409 +64563,22940,23000 +24863,24984,54263 +72184,56634,27517 +60547,48883,81776 +66908,72099,5147 +88278,81549,46709 +57956,62399,63971 +40329,24939,41158 +97814,12750,76896 +90780,24470,5787 +26145,57075,77179 +57971,57566,37259 +7498,4977,17623 +90054,80517,29154 +47425,32124,52543 +26234,23674,70295 +90083,8289,98721 +21546,8270,92358 +12607,15006,1584 +10754,86662,71035 +17529,14944,17909 +57749,91515,33862 +52726,99772,4797 +17230,11319,29834 +84251,93245,58642 +36258,47480,91163 +9870,31461,24714 +86713,19825,94009 +2662,80983,26063 +73251,28625,788 +98595,77460,56260 +35328,38444,37986 +79318,95128,69640 +80244,85098,85206 +81013,72272,15173 +35728,5410,30750 +74062,86136,24217 +68331,4966,98992 +67555,73110,10276 +9314,47734,37211 +39797,35755,31991 +45743,84190,78917 +85817,6482,79669 +66754,19792,34070 +63450,30448,59642 +97814,80471,79284 +53916,29266,69609 +8492,97930,52853 +92764,8467,12595 +20647,80041,31353 +87085,79376,67682 +16017,4248,85762 +97784,24729,85090 +84016,27173,24357 +45910,19288,80618 +66916,79659,42640 +55956,24629,87410 +59500,97319,94004 +70427,34997,50752 +53369,86925,29422 +83818,85090,7402 +36342,18725,24545 +10013,8630,4919 +84756,23480,15505 +57516,36201,13815 +93743,91513,66197 +86181,60355,76238 +96403,76397,31942 +85641,75190,39223 +23174,68264,69196 +91801,69560,42617 +68180,58744,87475 +1535,27751,58581 +53749,57036,74529 +46962,44517,34426 +24287,53618,71293 +93182,72944,74745 +42744,11393,66027 +70555,45351,48674 +21559,57114,15956 +13506,25280,66927 +16949,28936,50323 +82902,43391,26742 +42416,61064,11606 +19897,28988,86353 +22861,36182,21070 +17469,84560,24709 +60125,8784,95805 +10672,93894,70820 +81390,5915,10985 +74158,57251,38343 +2081,76456,76397 +41431,64643,77617 +84450,16175,9687 +86219,81591,7154 +34977,20912,68149 +7430,84084,16274 +45786,54952,39318 +54130,58593,7076 +87192,81786,18120 +76388,25087,99273 +44782,97180,38693 +22285,33173,29740 +2241,37922,69903 +31805,32034,31069 +85958,60683,42116 +42638,48521,64048 +6800,32213,4158 +91790,16688,6877 +19517,92304,29751 +53801,9499,65817 +2226,82885,83167 +18001,24956,99048 +59783,5267,18200 +29437,1932,33814 +61413,2012,47551 +79414,79240,83068 +71398,80116,75901 +36604,74946,61063 +98638,45049,72041 +93978,79884,98515 +6366,80083,99070 +34790,54853,57073 +5883,50438,45373 +52812,14669,24191 +36808,51632,67564 +5950,72446,66168 +44734,51028,53615 +57622,92555,81477 +77600,61014,33197 +60361,13019,16620 +96052,85651,25516 +3190,77302,76932 +28305,8253,38018 +8491,85047,52592 +14016,68689,88764 +33628,47091,18977 +39854,40777,93301 +21763,41513,76809 +285,78961,72377 +45777,23691,10681 +17357,20211,19125 +33752,79508,9200 +22673,80114,45280 +35020,75100,70123 +95477,36284,30012 +40197,92501,61211 +42766,32621,42735 +59244,77029,46399 +75411,10191,16251 +72255,33031,28776 +57201,32876,24090 +83838,2334,74204 +72562,90857,81731 +8308,32172,40739 +55576,4365,39574 +70552,23147,1922 +5414,48222,94229 +40450,45982,50565 +40288,67386,40253 +38142,13974,79406 +20788,29337,11343 +40377,24796,16158 +7818,96112,10084 +44202,59469,7839 +85140,55977,59956 +41584,74819,83713 +82431,18994,71137 +31079,26383,85072 +8159,13060,10209 +71642,17446,48143 +60910,99437,95446 +18498,58693,31872 +81400,84337,85395 +60341,82345,26099 +7608,32453,60464 +71867,90068,61998 +55924,23463,32866 +51757,60567,83887 +91640,68632,70262 +27695,91844,48609 +85957,39198,83471 +73879,40842,70275 +32104,60515,82380 +30728,10247,56104 +74785,3823,55022 +84231,49006,8492 +43437,92687,16381 +19801,23940,22360 +91259,34410,11144 +46005,52952,91551 +185,76169,60564 +91649,78317,63178 +9464,73495,7832 +83646,55750,41603 +69432,1722,7048 +72935,95896,96236 +82883,67072,88324 +22014,35799,46614 +1918,80380,21941 +21222,64181,38065 +45375,25383,59266 +63282,28516,48424 +80142,59118,88279 +6685,55329,21530 +86399,60211,81789 +5914,83599,25169 +69431,6277,11454 +19887,13096,17040 +11958,97195,32820 +49236,6533,94887 +63970,32520,26266 +528,40183,44535 +99411,61084,96830 +43612,95835,41357 +50281,25725,50452 +56333,72152,95183 +25752,93060,82207 +30222,51037,31644 +36678,37947,36429 +96622,43920,79387 +41561,52405,76169 +51161,9437,40969 +96115,2436,96848 +24473,30395,84078 +79640,77019,2914 +46268,65740,40190 +67162,82755,3425 +14543,37381,22284 +68115,83464,15315 +91013,94713,84119 +96939,38523,7728 +76565,40385,79896 +66302,81025,68507 +82105,88078,49820 +38900,46674,95033 +16504,58503,81452 +51549,50201,17557 +63512,3711,27104 +47030,93596,17140 +26891,29495,54420 +30579,18766,80973 +89940,52195,49826 +65913,89576,87037 +6946,97953,58551 +20458,45862,1846 +8310,9867,15673 +12208,65133,13200 +31351,58457,4309 +15910,29741,44392 +9451,99683,24427 +51085,52701,42882 +86069,38158,20072 +23646,71621,69985 +28622,57186,7994 +68096,17735,85849 +73241,71080,47444 +27849,76521,39823 +12528,2895,2613 +64274,24531,92326 +88578,32322,25536 +60658,40517,253 +60621,94729,73845 +35077,41733,87100 +88094,73198,7944 +59917,28974,88098 +7652,53651,78960 +76508,61671,77964 +80844,41658,84682 +76970,84458,71304 +51507,12636,8928 +14335,56896,33621 +94726,53446,79001 +14812,40954,42936 +70856,19024,62657 +33752,57622,17212 +85753,85917,54141 +79037,17836,78239 +64653,10291,82492 +63115,19171,17622 +93213,90493,6666 +50861,26470,88927 +9388,37242,58509 +56593,33612,34748 +78232,83508,86001 +28,21252,14597 +10527,72735,74971 +27126,85196,7192 +38883,55149,70337 +45061,40982,56513 +98099,81767,83498 +7589,26523,73891 +37451,88846,38792 +5504,14543,16749 +20083,45505,891 +98957,69223,4552 +44216,69722,11776 +34296,94264,68429 +44189,577,25331 +88920,7595,29277 +35178,71417,24328 +44036,52010,68052 +23125,40386,71448 +61357,80645,24548 +39902,91015,50765 +66718,45985,75182 +80128,9671,44474 +40204,92659,41695 +30082,77198,98796 +97851,83446,70342 +61809,31225,7063 +23491,55873,83911 +52619,96742,33940 +50066,56717,39541 +768,26156,63059 +22731,53557,78892 +24980,68674,13146 +73061,82047,10015 +59003,9966,63062 +67020,95630,54424 +30201,77880,93427 +22873,85579,91865 +48534,67004,72807 +2363,11204,93405 +28121,54602,16491 +87880,44702,74914 +72672,68498,81369 +86893,87991,30095 +64907,71605,43995 +98006,41009,99263 +10571,14646,29761 +78506,83455,160 +40551,95019,56711 +70473,21420,16667 +717,51700,27628 +39191,38592,89802 +32395,10985,21364 +35962,3399,72153 +23349,60075,86143 +51250,75460,52600 +69422,662,44798 +65652,28801,800 +55909,91183,16683 +95177,42427,2584 +77760,18445,60103 +97543,47398,71738 +83936,77945,39059 +72742,36608,16539 +41846,39035,43735 +7589,77830,69628 +46907,16538,22834 +40657,30312,27222 +2269,97636,81219 +42561,66404,51999 +92260,66511,45675 +65439,11820,8813 +84318,95277,5615 +85727,64079,82892 +15298,69586,57179 +19040,9343,67119 +79877,54474,62265 +98497,96957,28294 +77194,32600,51928 +50191,80116,44269 +17649,6924,71962 +63774,4237,23850 +25443,81170,74984 +47693,26064,36325 +40537,66696,85634 +74275,63976,37220 +71602,85199,51013 +92924,36113,66096 +79336,42722,98472 +46868,18629,66659 +91006,18958,99020 +76405,99628,7808 +64402,26487,97715 +66898,10112,11295 +17259,43070,21906 +50408,29118,99281 +16355,46211,64313 +50021,900,90163 +20578,98323,77072 +20998,78267,82968 +62466,74521,32805 +85255,98740,62426 +18074,80966,94726 +29623,97822,93248 +58807,46041,86844 +33528,44382,20787 +97265,51718,40264 +92060,99990,34543 +16001,54678,29678 +36269,95017,74525 +21414,33378,98399 +93332,46692,11267 +34305,12031,58755 +3981,15406,22251 +76679,67945,65177 +25668,42839,17716 +26919,83622,8904 +39915,53521,95194 +16118,23754,25441 +32721,81210,60101 +96117,18025,20269 +12016,83085,600 +99911,8380,26935 +77248,4060,57988 +87561,66134,54702 +69170,26176,32827 +88242,45383,56873 +44201,83013,33865 +39516,35589,76116 +89898,46725,98180 +16582,22256,5767 +73656,77784,90960 +76298,42128,15608 +80326,28716,14579 +51967,2773,96359 +21987,9071,46882 +78372,83739,53536 +37040,89258,86264 +21006,11952,96952 +4489,7005,2379 +23533,93727,41548 +78955,50296,82887 +39979,42396,75530 +12650,73175,66294 +58773,73182,83985 +3041,23270,65455 +31924,62729,35346 +6145,96763,78472 +24630,9498,67768 +86418,12306,16283 +41300,45659,12034 +68039,80663,47913 +80896,96736,19057 +53652,87360,96911 +89836,93241,71681 +57464,51024,41412 +89678,7357,17881 +96600,84989,49423 +1599,74890,23623 +64118,29778,5464 +73397,76312,45259 +48998,1756,74894 +84528,16533,42132 +3121,39235,55374 +28841,3719,48762 +24419,11102,3666 +46713,10430,3035 +36952,79339,19975 +58456,43115,64360 +59561,38426,32218 +89925,55569,39744 +60698,70906,93287 +38070,53675,47266 +74363,60091,78280 +12885,19098,12924 +49677,66799,34962 +48220,46218,22852 diff --git a/day8/part1.py b/day8/part1.py new file mode 100644 index 0000000..b2513d4 --- /dev/null +++ b/day8/part1.py @@ -0,0 +1,61 @@ +from functools import reduce +from math import prod, sqrt +from pathlib import Path +from typing import TypeAlias + +Point: TypeAlias = tuple[int, int, int] + +FILE = "input.txt" + +class Circuit: + def __init__(self, points: set[Point]) -> None: + self.points: set[Point] = points + + def __contains__(self, other: Circuit) -> bool: + for p in other.points: + if p in self.points: return True + return False + + def merge(self, other: Circuit) -> Circuit: + return Circuit(self.points.union(other.points)) + +def main(): + lines = Path(FILE).read_text().splitlines() + points: list[Point] = [parse_point(line) for line in lines] + distances = sorted([ + (distance(p1, p2), Circuit({p1, p2})) + for i, p1 in enumerate(points) + for p2 in points[i+1:] + ], key=lambda x: x[0]) + big_circuits: list[Circuit] = [] + for (_, small_circuit) in distances[:1000]: + new_circuits: list[Circuit] = [] + for big_circuit in big_circuits: + if small_circuit in big_circuit: + new_circuits.append(big_circuit) + if len(new_circuits): + for circuit in new_circuits: big_circuits.remove(circuit) + new_circuits.append(small_circuit) + new_circuit = reduce(lambda a, b: a.merge(b), new_circuits) + big_circuits.append(new_circuit) + else: + big_circuits.append(small_circuit) + circuits = sorted( + big_circuits, key=lambda x: len(x.points), reverse=True + ) + return prod(len(c.points) for c in circuits[:3]) + + +def distance(p1: tuple[int, int, int], p2: tuple[int, int, int]): + x1, y1, z1 = p1 + x2, y2, z2 = p2 + return sqrt((x2-x1)**2+(y2-y1)**2+(z2-z1)**2) + + +def parse_point(line: str) -> Point: + x, y, z = line.split(",") + return (int(x), int(y), int(z)) + + +if __name__ == "__main__": + print(main()) diff --git a/day8/part2.py b/day8/part2.py new file mode 100644 index 0000000..d7c86c0 --- /dev/null +++ b/day8/part2.py @@ -0,0 +1,63 @@ +from functools import reduce +from math import prod, sqrt +from pathlib import Path +from typing import TypeAlias + +Point: TypeAlias = tuple[int, int, int] + +FILE = "input.txt" + +class Circuit: + def __init__(self, points: set[Point]) -> None: + self.points: set[Point] = points + + def __contains__(self, other: Circuit) -> bool: + for p in other.points: + if p in self.points: return True + return False + + def merge(self, other: Circuit) -> Circuit: + return Circuit(self.points.union(other.points)) + +def main(): + lines = Path(FILE).read_text().splitlines() + points: list[Point] = [parse_point(line) for line in lines] + distances = sorted([ + (distance(p1, p2), Circuit({p1, p2})) + for i, p1 in enumerate(points) + for p2 in points[i+1:] + ], key=lambda x: x[0]) + big_circuits: list[Circuit] = [] + last = None + for (_, small_circuit) in distances: + last = small_circuit + new_circuits: list[Circuit] = [] + for big_circuit in big_circuits: + if small_circuit in big_circuit: + new_circuits.append(big_circuit) + if len(new_circuits): + for circuit in new_circuits: big_circuits.remove(circuit) + new_circuits.append(small_circuit) + new_circuit = reduce(lambda a, b: a.merge(b), new_circuits) + big_circuits.append(new_circuit) + else: + big_circuits.append(small_circuit) + if len(big_circuits) == 1 and len(big_circuits[0].points) == len(points): + break + assert last is not None + return prod(p[0] for p in last.points) + + +def distance(p1: tuple[int, int, int], p2: tuple[int, int, int]): + x1, y1, z1 = p1 + x2, y2, z2 = p2 + return sqrt((x2-x1)**2+(y2-y1)**2+(z2-z1)**2) + + +def parse_point(line: str) -> Point: + x, y, z = line.split(",") + return (int(x), int(y), int(z)) + + +if __name__ == "__main__": + print(main()) diff --git a/day8/test.txt b/day8/test.txt new file mode 100644 index 0000000..e98a3b6 --- /dev/null +++ b/day8/test.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