diff --git a/07/input b/07/input new file mode 100644 index 0000000..0ff99e5 --- /dev/null +++ b/07/input @@ -0,0 +1,1000 @@ +88578,88119,36620 +47284,65523,33494 +58606,16747,55999 +40991,85566,60119 +91623,26594,26700 +16770,70975,76232 +23079,51888,72508 +55737,44238,74352 +14593,1047,59712 +27244,82475,55158 +4325,32328,55224 +98318,6894,97698 +92311,45887,78669 +66357,34523,28202 +3826,79572,50455 +84470,53406,3296 +13657,90366,65383 +58672,30180,40602 +26285,62771,88350 +43575,28960,16123 +66092,77305,11399 +26612,83394,52761 +43538,81007,13081 +32446,83253,26021 +79902,35490,75208 +99729,61350,3536 +93236,24783,11960 +9418,99969,89504 +32299,19174,8470 +68257,93173,309 +16818,73927,61700 +39911,55516,62598 +98229,56193,41991 +82257,49065,68948 +99586,46327,29721 +27410,38674,30875 +14998,68776,53629 +17324,46301,14563 +95555,95332,62013 +73743,91108,82277 +14659,56829,92354 +24437,78491,60477 +31291,2749,74867 +31601,80728,44055 +60327,88204,76478 +22305,76302,63080 +64963,47589,50308 +49236,6939,72495 +49669,92268,88424 +72559,11385,76222 +81137,72017,29565 +43664,18932,18272 +56714,37255,46428 +52970,31593,35032 +79087,68235,56733 +12508,38481,70923 +18167,15792,86011 +42842,31509,86810 +36499,81350,58014 +86811,49038,22716 +15222,11404,45691 +94012,95743,49835 +23645,51255,48863 +85111,98452,48996 +99946,58307,35175 +46040,17130,80225 +1382,93348,50937 +93006,66929,23123 +95932,91681,6506 +75680,62579,65680 +53738,65644,18103 +19379,52012,17535 +6526,61808,34359 +48792,96578,3035 +258,65029,21788 +69629,93850,66808 +66734,16528,99029 +71968,47703,6743 +70575,94570,22517 +94402,5739,16549 +14187,47877,11513 +56204,24621,7083 +43685,7753,59557 +77821,34305,66262 +53238,23288,4487 +94657,23308,42069 +94788,55191,62716 +98258,71480,52179 +78837,44360,64698 +90127,71002,4610 +15103,80080,29482 +45110,95850,54489 +82813,78990,3202 +18651,90094,47614 +84271,55430,2264 +92192,76742,54028 +15998,19957,50618 +86876,37987,62950 +64480,58947,21261 +89725,21657,87703 +41835,26387,48999 +90522,49124,65871 +31670,99557,50809 +36947,50855,45723 +18749,87539,62358 +46869,21125,32563 +67622,57288,74567 +73157,5144,32827 +53195,11971,90266 +98125,7165,44773 +60723,69364,6778 +80264,20533,50571 +97937,32404,87327 +36686,96669,99139 +29955,88425,63681 +21072,71322,98402 +41045,37772,33585 +14299,41821,89231 +21639,82041,6922 +57825,99703,92545 +62186,1461,82959 +71523,60212,81856 +80533,18960,97007 +60572,21702,48132 +81438,88213,28382 +72393,67254,94704 +63491,59558,52412 +47468,56643,601 +10483,53497,51221 +92823,54077,65579 +15749,2864,83036 +14106,48677,76161 +41155,27150,80418 +85319,77736,52604 +36357,37413,75387 +38522,86460,81429 +87139,19234,33260 +2045,5895,54921 +12883,49661,31979 +66977,31307,22576 +82507,38443,78239 +83185,4579,22123 +47468,93052,75972 +34416,8876,92296 +47848,52742,82787 +17107,57479,72524 +41163,49255,1871 +86438,27165,66231 +59255,96018,39815 +17374,2167,52233 +64139,86094,97794 +97477,50013,21444 +6364,73142,10821 +83010,91800,92783 +52376,54944,59349 +15771,74734,50157 +48014,96320,56648 +61024,80857,11151 +21537,73660,19876 +69896,52549,68833 +74023,97096,25402 +92397,66269,5459 +34353,14555,8617 +96527,17308,72150 +50663,67435,29516 +27375,28443,38444 +55584,94705,24498 +64327,91112,14611 +68844,48709,17730 +55558,32975,41214 +58806,37368,47286 +86290,52900,10056 +66220,84867,53765 +28329,7680,77279 +40360,7164,54302 +11454,49187,66678 +57392,3797,70847 +2434,70699,63093 +49989,91650,34832 +37816,4930,47372 +65539,74066,22742 +5844,85041,70935 +65329,11043,97306 +80026,40080,92152 +897,80326,88609 +1610,69699,34305 +42575,44106,8338 +88353,95711,20420 +8920,64255,75460 +88359,35446,18772 +40540,99321,35951 +47543,27619,60230 +7275,25951,61120 +43104,98183,13384 +85885,78432,50972 +75218,88816,23228 +25312,76966,18981 +53524,79075,82222 +67672,46513,65462 +96641,22301,56110 +42758,77109,98146 +52963,39318,2919 +87288,65436,11366 +45348,47355,80636 +22314,85923,7284 +16812,39759,11195 +61372,72256,28005 +43689,95481,67127 +30777,72080,74244 +88226,19303,87504 +70055,1779,86562 +62613,33062,33771 +18516,72491,56513 +13407,69541,25411 +48774,4088,21998 +71728,67980,93146 +61518,92657,38383 +50405,88420,17669 +37055,45753,75139 +83965,22900,21539 +97853,61105,33734 +15445,9731,30921 +40059,90110,93487 +53279,85765,46846 +57867,90598,56679 +14701,83246,5622 +5026,74327,23044 +40661,69780,50646 +52466,68664,7485 +3198,74819,72603 +77212,37666,52312 +46268,77389,80995 +65960,60853,83038 +931,35054,34669 +78349,98930,36778 +12973,71294,73930 +71386,78712,40983 +99293,66910,98647 +32888,2802,23396 +70951,36583,11198 +62258,96278,61806 +58608,88263,93202 +54159,49239,45330 +27725,46219,66652 +72409,14722,34260 +87507,50958,74103 +67708,59992,3578 +16315,77120,64800 +16156,78549,87552 +78138,39194,5522 +34987,86015,92824 +45448,42838,61281 +83354,24416,18869 +59378,5108,39885 +97165,35422,81944 +28632,98499,49491 +19344,75937,90797 +44442,25615,33902 +50960,32184,93916 +57896,13308,61387 +53734,84672,18194 +8660,28733,4652 +78185,3157,18943 +98317,66564,73722 +39622,44173,13257 +80304,41566,77998 +2613,35622,41642 +12424,93436,36799 +55874,67410,88379 +53576,37098,28996 +33013,73365,26094 +41442,16895,93060 +69026,50404,23541 +2409,89035,88211 +53876,98704,18933 +21174,50362,52574 +62384,39994,25209 +49930,98823,52757 +45905,26601,42889 +53216,31422,95451 +11809,60789,41100 +17425,7129,21009 +191,59331,33074 +82286,57626,4379 +18996,25744,45777 +73469,93524,76170 +43165,83829,42679 +3489,90380,19287 +32130,82827,89429 +36788,57685,97554 +16496,54760,19802 +81414,88462,99738 +73314,24047,61708 +62101,47588,37247 +76559,84377,44008 +58802,37729,76039 +15010,75811,87123 +86933,94115,82123 +54009,43027,50596 +54859,83864,38417 +70884,85400,52967 +17627,45951,31465 +73990,73400,57850 +52021,18604,23930 +87155,37099,7360 +36814,97317,73876 +3217,97060,22855 +80471,52071,5789 +90240,54347,27961 +72653,17088,95274 +99522,76702,64574 +78799,52143,10644 +96717,37956,92741 +56362,29034,4448 +73447,23800,18279 +19230,90590,642 +58228,32856,16682 +31128,47114,22318 +77459,63932,87232 +80393,92179,71614 +62857,20743,3132 +58382,28939,54649 +56645,94728,79653 +58994,90751,73198 +65900,78107,89014 +90685,96942,499 +82143,71151,9875 +74299,1835,35686 +77183,79082,99241 +61967,66923,46218 +44660,5166,80608 +12440,87949,50417 +93660,31937,20171 +51566,73911,49147 +76489,70697,81120 +18200,25957,52203 +69689,24355,24167 +48075,56746,29142 +55367,7511,46569 +93532,58396,73816 +52087,84390,39320 +10307,46088,98507 +98000,40016,44082 +38433,87651,12631 +41767,95520,38953 +57279,41175,71466 +93367,88331,28212 +41147,35131,70028 +51993,865,96054 +26764,83674,88651 +41090,91802,43988 +21936,61758,95795 +18182,94724,96470 +5987,72144,66828 +25793,80778,31168 +74537,22398,16245 +33788,91256,62234 +40226,67461,71641 +69037,85276,84486 +60114,89239,18636 +78594,28511,483 +70567,32202,5127 +92907,22244,67532 +53367,28230,51419 +12074,70336,54016 +94426,19283,79413 +7719,42852,32624 +44550,91786,24090 +97273,3739,93760 +8831,75645,3776 +96717,82553,15939 +74863,10174,19805 +26696,51237,10575 +12286,83670,70284 +26504,47694,10852 +47738,25780,84304 +47083,68345,50461 +55218,9260,70932 +18736,145,57506 +72396,38545,15870 +36036,28495,2010 +38976,23655,89418 +99289,95832,62180 +77239,78871,40829 +10664,172,13678 +39821,83437,67887 +10299,72788,94927 +83400,25480,29054 +42411,43523,59394 +46661,86695,72759 +60626,21494,31729 +68666,61021,43766 +87881,31838,19206 +41987,24719,55464 +75537,55383,61279 +30045,46251,63105 +2764,83664,24651 +65808,49167,90101 +28234,6223,74430 +81855,74700,89081 +94227,56483,81006 +96802,10429,48855 +28096,20137,83805 +3425,91918,27848 +50614,46203,7156 +76465,59663,60926 +53923,21136,74495 +85388,66276,87336 +9765,87723,82726 +27125,65073,66716 +48124,34212,86025 +61266,39362,71303 +37360,689,7460 +58180,72545,86518 +90051,37290,47549 +57274,62249,28082 +62532,47721,22828 +75117,46554,43674 +95864,6455,88933 +40290,6083,36924 +92521,6928,26464 +59497,93747,23590 +18093,71649,90930 +94193,80055,31973 +14041,29596,98503 +55364,87998,80534 +52284,48295,8888 +47311,72900,94508 +3406,91750,20636 +6997,50787,78274 +79767,15581,51682 +8091,73539,7367 +57512,24650,85517 +46699,68150,33589 +55767,84255,45963 +28070,7738,4006 +24909,55346,90549 +29859,48240,24838 +79393,19012,95121 +97229,28011,49772 +42006,21000,77443 +81733,99744,93278 +86772,34673,12126 +19502,8203,28912 +49824,67526,1034 +28700,78641,50796 +88714,76573,79637 +9000,58932,40939 +97347,68200,88525 +81868,51195,73324 +19668,77366,63521 +69747,99475,20393 +99004,25685,26652 +67189,26833,99404 +82438,82069,75500 +63793,91857,19743 +56003,62275,99455 +21208,52161,24086 +12587,75911,75477 +60748,77278,44501 +29130,79526,96000 +11519,33212,21564 +64069,84475,6960 +83223,9102,9204 +48583,37369,34848 +85319,78194,98461 +42201,40008,32526 +90572,73261,23034 +3555,82822,72487 +86232,68174,62182 +7327,92475,47795 +61731,40954,93078 +89619,53775,5051 +20159,63661,35080 +10732,58177,98809 +66904,42146,3558 +28876,9491,57770 +55301,16215,90925 +38560,35173,60721 +38335,55880,41396 +69552,47655,23115 +42786,55539,81821 +57261,14542,86677 +29204,26290,66068 +26339,70222,36976 +74487,73724,43976 +20030,94128,40714 +64785,65197,87178 +27590,55060,20400 +8599,93405,62889 +94617,69964,53095 +55078,44070,12480 +83077,86697,2062 +95161,29458,72081 +62766,76286,1287 +27855,3131,56247 +98134,42162,31215 +99861,83101,94708 +66605,53108,24683 +16216,73581,70808 +13462,23078,91388 +30671,20981,90629 +963,98599,31141 +66767,72922,48643 +931,64677,98264 +17199,23020,79835 +78277,69206,82762 +31012,62614,78427 +55429,39042,69569 +24191,44063,99865 +97432,3336,46388 +31959,63839,63616 +81908,42463,66393 +19463,42889,53884 +94233,93408,29740 +14620,89726,88160 +30691,15039,42095 +81724,35094,87610 +58404,42467,50476 +7867,70143,82222 +68077,25131,28148 +26578,71526,7458 +52628,29441,67261 +11095,8743,54012 +55445,48996,42922 +48231,15996,91774 +75679,4569,54824 +73736,91340,1719 +89430,98540,60118 +45217,3842,46850 +21971,37216,32460 +56149,31866,61082 +81100,16951,97183 +64431,21995,70087 +47722,41080,13734 +96084,42720,26622 +73323,23020,95575 +38583,37329,96290 +51860,66773,84275 +18881,88538,85410 +88462,89453,68895 +50367,43426,7754 +27935,23484,34430 +40834,24518,43858 +76728,22465,59186 +32646,38248,3491 +58698,63768,70710 +16068,50742,20267 +5082,89786,34196 +29823,49831,68853 +66882,76621,29660 +255,70699,25732 +40256,60498,12575 +1878,45444,24183 +50575,59238,82269 +70539,30634,37234 +35479,72652,15913 +49775,13080,71167 +60364,33479,2091 +49755,92421,81164 +61373,65485,84204 +92251,76079,76207 +41051,46092,41782 +76761,39081,20090 +3337,54645,62752 +36924,58219,96896 +86726,97233,62042 +87387,7695,81557 +87662,86418,52145 +41810,82451,61873 +69267,34470,11337 +67991,7463,19226 +38236,39000,75317 +85168,83818,70798 +99619,6496,53450 +15220,24334,38894 +82221,64080,94642 +71679,22418,80530 +52665,57771,57414 +64718,38716,69754 +71179,61390,60358 +24502,17126,15936 +16804,87971,98613 +20108,67842,5243 +6851,12051,23271 +96082,22945,80393 +23430,43510,18599 +87644,45803,69870 +25063,62543,32491 +12726,49828,98597 +3812,59971,23955 +41102,33143,91460 +55331,97174,75617 +72246,41479,82895 +467,2488,83337 +43633,94881,10820 +13850,83940,21465 +74415,63797,2826 +96079,10381,85403 +26,46389,42982 +21579,45821,41231 +50470,76566,57660 +88565,8028,20208 +13789,65701,1194 +52413,39575,14459 +1688,2842,4220 +39545,97199,30824 +62146,38482,3550 +86310,8016,52708 +74706,59941,842 +12942,59307,81345 +63486,74217,82507 +20864,57533,65591 +38436,17094,99492 +66991,54702,27906 +45062,30019,35591 +71981,3060,58367 +23216,93621,66989 +50818,2227,31623 +87003,23066,69170 +40563,25541,26665 +67000,56666,55604 +89398,56986,56552 +23872,1222,31969 +28827,46115,71239 +36155,5112,90743 +86815,6091,26132 +50321,38914,57932 +30035,89738,6669 +29416,82243,84136 +57768,16871,39561 +36914,53480,93218 +84683,67078,2598 +31130,42003,21215 +86810,4428,11026 +45451,51107,82578 +31754,20488,82096 +38882,36981,43136 +70263,48024,92262 +32616,47,77272 +75783,52136,35616 +66230,90864,96061 +66776,20044,24418 +81351,65602,1911 +89303,57022,42225 +33138,98948,66556 +10344,87517,83293 +51448,7253,85107 +38572,7114,7599 +46386,14680,9309 +18259,97981,46026 +35717,7310,26690 +70546,55811,62233 +49180,10574,46285 +70554,4648,95031 +79648,94893,29864 +29037,2106,68762 +47564,91682,61919 +59863,86266,213 +21410,44682,62545 +86846,11011,67801 +44914,18488,90828 +47850,95088,57894 +28513,61009,50034 +33600,88452,24226 +83269,4009,39161 +1212,22056,75195 +7778,22167,17874 +79786,63238,61338 +75046,6563,43245 +98684,23301,55640 +38293,8608,34625 +91063,49078,36208 +20894,73292,49303 +96559,58636,20352 +87519,23549,85513 +50127,30756,23284 +1104,39951,4869 +3044,62917,33105 +85974,35110,14522 +17695,92472,95715 +19038,75952,68748 +45970,49331,89719 +72764,73693,52530 +18016,21657,24015 +27987,76912,85975 +20324,46638,30729 +86159,25024,78450 +91703,48733,47751 +61068,56277,46895 +64724,35091,27828 +74908,10619,12850 +53723,1565,57685 +34482,90720,2247 +48825,60634,41928 +91973,66035,53510 +82060,36058,52337 +60399,75824,9761 +25223,64490,87193 +43082,55997,60995 +60069,9675,25668 +82168,13746,889 +92109,66067,89185 +49712,2159,49643 +70809,87132,22374 +42176,46025,79610 +39169,79785,13752 +18825,34051,34367 +82252,6749,90664 +24367,42718,70613 +59734,12443,69837 +99291,28674,79553 +59851,50139,94341 +95566,89541,60142 +4569,69698,16896 +73351,59466,12724 +57451,26762,75305 +23361,53953,91096 +24659,25600,84401 +6701,47677,41957 +49981,73558,66019 +32211,51399,79308 +47526,58794,2992 +81276,54434,41783 +78462,94606,38348 +29645,11545,95388 +12768,60327,47198 +13631,37232,932 +15921,48493,78354 +40942,13563,1614 +80585,10552,82842 +65845,49345,40301 +37277,72640,48612 +76770,34551,72133 +70247,8839,11346 +92769,91963,43794 +66893,13056,96789 +78670,8721,50036 +64492,52865,84998 +73994,80260,30635 +3000,46773,48714 +7863,3564,16845 +34743,34383,2190 +34824,48127,39962 +11166,86243,27957 +20474,66853,92972 +55137,22568,3532 +74744,97234,47881 +31202,43977,35493 +60681,32125,70805 +62367,77506,45789 +58725,87234,21123 +5756,79120,49 +59165,65274,56916 +63331,3097,56263 +26716,71595,15213 +45380,11457,75524 +41835,6913,71059 +776,98134,83249 +37445,8259,34490 +95308,29768,36740 +67412,78669,4196 +90273,13196,7376 +74377,15408,99304 +73183,69355,97589 +78475,80184,16542 +66566,41437,5551 +29148,68594,25621 +49051,84679,53482 +85126,24907,37495 +59293,9297,37545 +61809,12015,17536 +71389,58549,4787 +82331,27739,31214 +77013,33020,68096 +82161,81626,13508 +2488,55568,45206 +28461,67942,49817 +84983,36136,21513 +97295,25849,80894 +64329,9807,44371 +4296,78708,73186 +73054,7426,5473 +44708,2200,36856 +89390,24656,77054 +37171,48832,91674 +70523,10711,73050 +76565,15553,82937 +54300,6616,63102 +24179,29751,52132 +30878,86308,42617 +7040,72237,89071 +56404,9204,3828 +22850,25685,12958 +64083,40897,5870 +80712,12661,89880 +28812,27914,73054 +78010,64424,93170 +27625,48913,30906 +36127,27193,45106 +48005,50030,84428 +65,90041,59062 +8862,18079,23000 +48615,5004,93097 +66137,68227,72716 +87591,77071,15009 +22171,56292,41452 +24045,89790,10918 +35254,57957,74760 +978,22560,41487 +11221,56682,26207 +4738,42547,23237 +19715,36633,13609 +68999,9734,99443 +5691,6365,99159 +72026,53780,84262 +99162,15204,73617 +1403,9689,25442 +91610,23025,37300 +80889,63369,87832 +7680,60094,72242 +61673,13638,77572 +43450,58503,44412 +45354,340,62116 +89875,38006,43217 +50335,46008,27007 +96936,29763,52718 +14263,57751,18256 +29450,53645,62417 +75044,90747,12361 +481,37481,96215 +13555,24321,17925 +35614,79531,68844 +84931,58893,87301 +44468,67113,16875 +69711,91869,94454 +85484,75271,96361 +26101,54530,5912 +22797,2471,91172 +16516,810,26693 +53613,4331,24742 +776,67920,75505 +25448,67347,71175 +24339,72871,91444 +18603,36814,12108 +38437,97567,60974 +62671,95146,54194 +14195,94917,49454 +31135,2103,70660 +98613,20118,50202 +11557,34197,28279 +31107,61214,39668 +40973,55230,90288 +99164,79291,67778 +71202,18860,11631 +10717,16166,97658 +94438,5055,32717 +95680,17091,40298 +41253,57483,84510 +17253,13432,74251 +33502,34783,5740 +63712,85338,86710 +63985,8493,48410 +2102,79526,99602 +6786,20011,62272 +60010,39536,1764 +17116,78563,83261 +2430,35640,23275 +68327,14833,42627 +57963,65046,69811 +23719,92143,76985 +95090,46249,11620 +17515,60765,16997 +79376,25884,44802 +78660,51960,88840 +48890,69215,16511 +35142,65805,44682 +35288,55328,68424 +89119,32187,52805 +62082,99840,30682 +64083,59987,73816 +70236,12705,73664 +42886,43064,61805 +60755,15294,16261 +37080,92079,24305 +52497,62169,25315 +67546,7715,62461 +87623,51908,32595 +4805,67774,39667 +697,7468,62032 +52614,11774,36370 +39837,26872,38519 +86231,22849,5597 +71105,66319,52501 +7563,71673,84206 +50223,53532,43260 +63026,14682,70232 +90432,80439,10923 +13637,55663,74751 +66472,63039,42717 +95759,24079,78226 +30181,56928,4745 +91020,61938,69903 +98496,15760,11569 +62354,34465,21134 +22178,22232,42331 +57611,47365,4049 +30362,93723,71394 +30500,92504,83267 +83043,31955,60472 +80504,67243,70035 +23456,97221,67969 +74067,5604,73773 +54671,91718,72635 +24520,90072,80220 +6926,39338,79600 +81335,63617,38725 +70138,72454,87636 +16792,76022,50219 +49748,24072,2437 +22794,6776,12300 +82241,4930,16876 +86623,15547,64495 +29715,10203,85760 +89234,7227,31498 +92355,66380,95013 +38843,88601,11821 +47683,601,36234 +34239,70275,33928 +20413,89296,69950 +78728,2493,86948 +77567,48082,5677 +93135,7264,64786 +74095,30004,9603 +53435,53087,48713 +27940,36862,55022 +81083,52501,28288 +87934,83721,48004 +29788,84151,66695 +761,52957,13225 +51895,33945,98200 +51551,70349,95462 +39624,3350,77191 +53642,8135,81199 +14778,90289,86341 +5310,73455,58587 +85817,29403,3380 +51579,76305,46815 +95073,83768,53622 +36556,29384,28421 +40081,28018,65241 +32909,20,61411 +85141,86740,60684 +4201,10192,76243 +87302,29245,50457 +137,25602,53668 +62121,88461,1777 +67298,13694,73695 +17882,3257,71995 +27136,71465,27170 +73286,88269,27881 +38049,81126,75993 +15385,14081,79374 +84347,65079,84085 +13410,58295,71812 +38304,67936,46470 +928,27966,35163 +60269,78746,29419 +47428,94300,27246 +105,84716,92796 +45951,26882,68946 +65664,37041,43532 +63553,86825,36040 +67585,81204,85742 +71366,70770,5726 +59402,59276,38107 +24340,88107,20120 +30703,92628,13223 +26774,90410,42146 +35000,68375,23807 +88835,69500,78910 +4031,79825,90186 +83940,75980,98683 +66950,66833,70326 +33433,93574,44544 +59586,47578,74473 +82534,92848,8791 +78978,18046,50017 +50917,92805,14193 +70117,27458,23062 +36478,47232,64904 +87280,45001,1040 +25234,25660,85324 +23427,23004,76376 +58327,67739,24729 +99521,63102,80380 +49355,98879,59808 +5755,27670,90969 +96231,77848,67358 +64921,62074,89511 diff --git a/07/main.go b/07/main.go new file mode 100644 index 0000000..321d2ff --- /dev/null +++ b/07/main.go @@ -0,0 +1,124 @@ +package main + +import ( + "fmt" + "math" + "sort" + "strings" + + "git.z1glr.de/advent-of-code-2025/pkg/aoc" +) + +type Point struct { + X, Y, Z int + Parent *Point + Size int +} + +func (p *Point) DistanceTo(p2 *Point) float64 { + return math.Sqrt(float64((p.X-p2.X)*(p.X-p2.X) + (p.Y-p2.Y)*(p.Y-p2.Y) + (p.Z-p2.Z)*(p.Z-p2.Z))) +} + +func (p *Point) GetRoot() *Point { + if p.Parent == nil || p.Parent == p { + return p + } else { + return p.GetRoot() + } +} + +func PointFromString(s string) Point { + parts := strings.Split(s, ",") + + return Point{ + X: aoc.ParseInt(parts[0]), + Y: aoc.ParseInt(parts[1]), + Z: aoc.ParseInt(parts[2]), + Size: 1, + } +} + +type Connection struct { + Length float64 + P1, P2 *Point +} + +func do(test bool) (int, int) { + rows := aoc.ReadFileRows(test) + + points := make([]Point, len(rows)) + + for ii, rr := range rows { + points[ii] = PointFromString(rr) + } + + connections := []Connection{} + + for ii, p1 := range points { + for _, p2 := range points[ii+1:] { + connections = append(connections, Connection{ + Length: p1.DistanceTo(&p2), + P1: &p1, + P2: &p2, + }) + } + } + + // sort distances by length + sort.Slice(connections, func(i, j int) bool { return connections[i].Length < connections[j].Length }) + + for _, cc := range connections[:10] { + fmt.Println(*cc.P1) + fmt.Println(*cc.P2) + + // if both have no parent, make the first one as the parent + if cc.P1.Parent == nil && cc.P2.Parent == nil { + cc.P1.Parent = cc.P1 + cc.P2.Parent = cc.P1 + + cc.P1.Size++ + + // fmt.Println(cc.P2.GetRoot().Size) + + // if the second one has no parent, connect it to the first one + } else if cc.P2.Parent == nil { + cc.P2.Parent = cc.P1 + + cc.P1.GetRoot().Size++ + } else if cc.P1.Parent == nil { + cc.P1.Parent = cc.P2 + + cc.P2.GetRoot().Size++ + + // both have a parent -> make the parent of p2's root p1 + } else { + p2OldSize := cc.P2.GetRoot().Size + + cc.P2.GetRoot().Parent = cc.P1 + + cc.P1.GetRoot().Size += p2OldSize + } + } + + roots := []Point{} + + for _, pp := range points { + if pp.GetRoot() == &pp { + roots = append(roots, pp) + } + } + + sort.Slice(roots, func(i, j int) bool { return roots[i].Size < roots[j].Size }) + + res1 := roots[0].Size * roots[1].Size * roots[2].Size + + fmt.Println(res1) + + return res1, 0 +} + +func main() { + if r1, r2 := do(true); r1 == 40 && r2 == 0 { + do(false) + } +} diff --git a/07/test b/07/test new file mode 100644 index 0000000..e98a3b6 --- /dev/null +++ b/07/test @@ -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