diff --git a/day8/zig/input.txt b/day8/zig/input.txt new file mode 100644 index 0000000..ef01911 --- /dev/null +++ b/day8/zig/input.txt @@ -0,0 +1,1000 @@ +29236,60929,22649 +23324,41787,23887 +17774,52222,2947 +99391,51442,81759 +27698,36135,1248 +25179,74700,99077 +22359,63229,97582 +12701,23906,8607 +32425,92327,71859 +63369,66221,54998 +62230,75624,44397 +81401,59250,29692 +2011,28286,19842 +72514,98365,30692 +71709,75164,11254 +51016,91446,2712 +913,19597,50313 +58508,88466,13087 +88152,34002,45619 +52716,15002,25661 +56002,96653,70321 +33581,60694,97566 +31777,78032,26127 +98264,19761,20850 +89365,21653,96346 +57501,19176,54290 +84321,16250,39647 +30561,5049,15527 +62554,52987,44873 +55879,64013,66600 +46068,64344,77050 +75991,87138,36336 +94091,13583,71803 +91867,29315,49640 +9020,51917,60599 +67491,6695,58781 +92349,2234,57819 +87239,74635,75064 +3915,86208,9443 +17234,71142,32306 +32776,12726,89009 +85424,1254,44304 +90301,94201,35545 +76851,18936,77280 +90582,80260,25685 +89847,76461,82992 +40880,98309,44881 +60179,79802,17608 +67191,26488,56828 +92933,52638,5275 +75651,22071,13235 +39782,87069,46750 +56554,58630,95524 +85938,44160,92832 +78646,24585,63741 +2460,8565,5713 +32542,22110,23219 +38786,41192,91311 +54112,33759,6584 +41019,32884,88207 +83392,54445,52295 +98309,72811,79958 +72227,76369,8145 +17626,33339,45129 +17298,27764,60174 +38495,96583,69643 +12706,79779,46534 +97968,36206,81423 +43812,52102,90451 +27837,62375,23063 +32056,67850,27733 +82372,20072,71896 +39407,87881,2230 +56915,35359,29071 +74645,68830,87638 +49259,44511,46831 +8271,47021,36215 +98536,38599,53253 +85081,52089,81871 +44392,48108,46256 +88709,53535,11964 +87699,96694,98533 +99325,74599,70238 +54955,15192,25994 +54270,59014,55097 +98480,97192,54805 +32464,37718,74918 +76475,8406,36483 +51178,30985,4978 +28450,90308,74108 +3495,75493,30552 +31058,19731,33822 +69761,34941,74305 +52008,85133,49083 +51784,42595,35996 +12569,48303,23079 +98272,38146,22796 +75320,73383,85577 +89281,72685,58263 +95695,60635,58145 +69764,66623,91521 +75147,81882,76037 +78908,96255,61508 +45979,92061,16216 +14272,29782,94989 +69519,70701,96335 +37870,54623,31408 +43559,70443,44078 +33260,90735,30338 +92100,14116,54985 +88709,17964,17196 +88754,70800,8266 +45845,47632,81485 +96252,21440,27375 +47663,8280,10385 +88690,77447,21817 +27304,12479,38263 +25826,30224,58021 +74812,71465,47073 +44492,46697,21660 +91444,31473,32647 +64049,77180,27408 +62668,18933,46845 +23617,34972,17047 +17047,4311,5748 +20439,75407,65464 +6369,31242,58888 +34435,14503,60081 +3265,91263,48154 +79265,88680,76953 +50574,51120,59028 +35142,20140,23107 +63930,74857,14052 +7132,44606,93138 +14568,88132,50047 +38680,8397,28096 +51580,89065,56031 +76728,3817,14263 +50683,63705,42776 +93722,14018,13354 +89871,81366,96064 +88690,48803,86070 +33164,74637,4008 +70664,34145,50861 +171,12350,70397 +73064,55846,5483 +19342,81573,27007 +94437,77853,30875 +32549,71639,17323 +90446,10436,62373 +85779,2005,25175 +93835,85262,1406 +62389,37554,20589 +74181,49742,50247 +54927,25525,43869 +72950,39835,10761 +36192,88355,54498 +7629,5667,64575 +78050,72448,90160 +14490,87541,28248 +50042,84464,75254 +92713,54866,17172 +85710,90281,67082 +49618,3373,67579 +13356,50076,65503 +70586,95221,33608 +14902,60343,75033 +44255,48821,70734 +91875,47982,12857 +14901,84567,41261 +52064,58291,77152 +69130,81381,17527 +76177,38895,9171 +50231,31293,62928 +22328,46251,71782 +19523,70273,53488 +84811,64272,14740 +99466,87586,87268 +9502,44131,39206 +1525,51343,909 +70449,74840,83056 +36293,95673,16906 +8990,36894,32718 +93370,1734,64741 +49438,23078,78467 +93482,92200,89344 +20928,80833,28102 +53382,13170,26187 +52597,41574,5479 +40634,13852,8666 +55795,12917,78885 +78103,96788,46076 +91411,77125,67640 +12039,32083,18082 +95243,85322,6291 +5280,15938,71738 +28264,46806,72278 +6840,1208,27959 +71318,14331,77813 +13536,43286,53217 +22455,23104,29682 +49707,42678,1115 +65119,75399,52565 +43213,552,55833 +21684,54053,70060 +45719,30776,89438 +97510,984,37031 +67447,11908,89052 +68621,36595,25337 +72387,48657,32947 +79225,55360,54380 +87787,83197,18981 +67398,9962,25819 +64059,67181,35867 +93593,12202,72764 +40407,79148,60886 +89222,35620,22676 +78022,66609,53492 +13655,41328,12889 +45330,79180,55912 +10097,13403,17871 +11152,88445,79330 +66384,95952,98116 +47231,41714,74252 +47560,24130,14370 +14031,22635,53064 +83488,60737,68074 +9906,38295,86850 +64489,28890,64919 +34081,16246,96416 +52481,83448,31732 +81824,46893,45171 +14101,27815,19826 +97964,31851,74128 +58660,33208,31611 +34351,31372,69600 +25095,37579,48828 +8648,96044,10646 +91838,50032,56594 +41007,17807,91794 +44197,79984,33492 +5967,6070,27120 +58222,22130,17069 +61986,92929,25113 +25707,44233,12347 +98080,11163,97040 +63212,27525,59075 +86128,53744,54732 +55728,45092,77208 +71077,47020,18957 +14092,37805,81058 +68583,87109,79810 +30012,17980,5531 +86274,79427,29832 +79780,16894,50729 +58899,33925,93111 +37234,81618,7939 +70215,45467,8625 +59052,73884,34667 +6435,23124,17852 +88491,38562,34014 +36336,67445,64624 +67973,93171,19545 +39824,48051,10565 +44156,44562,22572 +74862,41453,54292 +4470,69058,52242 +69040,2424,85857 +22164,47984,88528 +38584,65869,1213 +74099,96984,73511 +43970,18896,81818 +89715,10712,88647 +96068,7627,883 +30711,5611,94128 +5973,32619,1304 +91157,70073,8264 +34885,99179,12331 +61831,68897,27308 +89524,70967,76464 +7782,77134,13993 +69311,96216,75901 +17600,85459,71370 +12863,92876,83849 +75284,57417,50613 +38376,95561,47199 +78949,3930,42822 +49713,34910,11721 +57736,34997,49165 +99054,40731,14511 +93569,62654,13709 +1272,82134,56314 +34940,56541,6806 +9085,16402,26618 +83924,84201,65912 +8086,59826,10646 +55915,56867,94468 +16580,25791,22460 +80283,59084,57376 +17333,24893,48839 +33606,47838,16650 +96876,40696,38654 +32036,87589,5471 +81066,35114,96246 +54596,56045,57983 +97687,32770,7445 +54513,47268,46245 +26628,49704,85946 +88132,16936,96291 +23372,17366,20621 +26650,69594,76299 +49856,99677,15320 +47859,81255,82669 +39328,35019,65824 +40987,50594,38791 +15631,92667,41787 +69687,48597,390 +44149,38015,74085 +44135,74310,74710 +56381,39480,58615 +63760,99216,29017 +6048,54425,2334 +88649,87270,34167 +77357,12336,13809 +6887,3140,94504 +11512,44084,5065 +40585,48462,74970 +64973,44501,26023 +4352,91113,65089 +28294,952,85539 +68461,69496,73336 +50530,33383,89381 +43104,38565,14786 +46511,65676,11326 +45103,9908,25838 +72771,12964,77024 +18999,46911,77983 +65231,98514,1262 +63339,63982,35762 +67570,64223,63631 +72319,79177,40162 +26642,94482,52893 +37880,58818,89425 +67616,54552,7490 +42228,83751,79828 +34631,54172,60004 +293,23964,38595 +37177,58477,9764 +22113,3472,97276 +2778,20297,40392 +1586,15950,99491 +82249,54917,4169 +95043,41318,37400 +61719,53112,42711 +1013,16244,53584 +42009,11752,5650 +68508,30385,60300 +75405,9544,58766 +21851,27987,22976 +78141,21337,47882 +38172,18088,7245 +7574,59236,31707 +374,89501,87114 +71152,3687,82204 +55385,23760,96517 +86104,75026,11180 +96670,94860,87257 +11097,33752,65365 +77144,7821,7945 +5714,70450,70688 +2288,62316,20844 +30618,10514,80337 +50999,9938,44234 +15462,78788,19617 +95506,48281,86039 +84025,76704,68153 +52408,75388,7701 +62961,18812,28973 +9273,50772,84301 +82965,25609,83778 +5941,12893,92067 +23249,24530,54664 +86733,44416,99186 +79855,25825,64608 +2859,75237,48901 +67494,18715,10933 +75841,6452,26653 +59513,34598,35037 +80433,55159,58080 +20692,32457,87428 +26751,26694,56036 +89531,7534,88351 +68193,64298,71648 +93174,51155,51627 +96487,95860,72474 +65168,97511,41086 +84374,51021,43489 +28034,47711,61296 +75676,67164,37840 +6404,42546,52830 +94463,94061,35443 +94822,28836,74144 +46543,21930,85968 +57027,93356,34026 +20904,31036,58812 +43369,13750,70403 +72988,6680,52983 +49028,22497,17667 +27971,83841,72290 +54035,15504,52997 +48580,67292,29429 +23248,82125,70063 +43485,83946,90361 +30810,44056,5243 +71831,85315,28467 +99496,54680,37669 +25323,78883,35472 +59469,73395,31127 +38326,27372,85119 +18503,35906,27588 +27642,83354,91851 +27614,49493,83701 +92873,85052,42911 +3879,42399,60001 +72051,83049,36032 +89209,85017,75695 +52151,99087,14869 +26488,84155,1933 +21434,82292,49693 +70719,24456,28164 +17738,96662,79924 +75229,47831,39053 +88580,26155,83753 +5885,39753,29797 +53273,98116,58742 +18496,8583,90606 +73662,8887,81167 +53422,62573,75918 +97926,72055,6188 +67815,10558,51880 +10661,80909,70980 +77665,91867,23574 +55662,94148,23083 +59944,10248,18342 +45514,80808,82201 +42560,62353,21186 +8038,32062,75952 +53816,68094,19882 +61544,83477,56083 +74,84501,48954 +93421,79449,79018 +84084,55601,66255 +89949,75042,45865 +15551,94515,82472 +21763,67645,32897 +30740,44721,74482 +85241,35287,18718 +14728,94085,77297 +19084,21296,85194 +3732,89134,43730 +33670,42728,23963 +15033,36092,68742 +35721,38,21412 +19129,41864,46107 +84110,71578,71220 +1723,81357,8757 +96740,93502,63048 +67922,78128,75310 +18821,46421,2266 +66588,31562,82072 +9671,52048,32339 +75852,77005,6601 +99845,74496,19574 +62280,38777,85947 +85344,36220,89376 +90784,29714,67981 +55852,19110,4911 +62189,18304,42964 +31957,29042,93090 +48401,78769,55517 +94591,85156,73317 +7616,99605,82810 +83801,56603,29232 +84739,92036,76644 +5060,661,35439 +78471,52599,57440 +56253,13613,68790 +30037,53335,10315 +28483,30208,6646 +28667,21317,92076 +19253,19769,97395 +42328,98068,657 +74857,93223,62279 +89748,42927,69691 +44532,91738,39508 +91305,23755,72584 +39398,75195,81793 +36601,48872,58520 +99941,49541,89444 +74435,41037,49194 +1773,42311,86463 +43893,62039,60628 +92434,88870,66195 +29298,35344,68793 +63824,65132,72639 +91135,39195,80671 +20725,93090,57037 +51061,63829,89136 +43854,7766,52905 +86631,30171,40613 +28400,93160,67154 +13291,28849,46923 +73725,61607,3551 +56019,2879,41378 +83989,14979,12708 +74208,38212,28494 +27037,37894,14943 +59763,99993,4919 +11109,906,99806 +21409,75638,47845 +80209,71678,3223 +34383,57620,4748 +10432,17717,92509 +31258,10533,8552 +31782,87228,76895 +46674,92414,18128 +73619,51145,5861 +58505,28307,32259 +37849,72597,69562 +69422,3136,16345 +71224,9945,2542 +75251,58558,73294 +77482,2722,87102 +94106,51189,14585 +2746,65725,66335 +5300,8549,60242 +35058,15222,77990 +77216,52765,54647 +70616,83032,44182 +45199,80688,38095 +75193,71495,15418 +6989,82835,2572 +91151,14845,17902 +82855,14408,54316 +18687,53923,92724 +84864,13239,31025 +86822,68041,92846 +60370,61488,87781 +87339,45295,35057 +47546,67954,80267 +35289,70902,85118 +32591,88169,58372 +34523,82041,42775 +41323,17483,70345 +43235,88463,91949 +35463,23229,47945 +83941,52580,20940 +79005,69929,75145 +96206,42845,37144 +48438,6577,79560 +58417,46165,46351 +13393,72445,81392 +30534,64451,69897 +48456,73203,33996 +45146,26848,53381 +136,66358,93977 +18446,59515,40880 +56079,59833,71804 +45243,78649,23726 +71152,50456,25208 +33156,61498,93533 +49651,91066,90017 +29487,19381,76977 +19740,87228,17953 +14835,93589,55249 +14337,75016,88044 +34659,25754,29329 +5935,28493,10243 +30893,10584,36390 +29059,69292,83826 +6284,25965,9964 +19890,61912,96666 +71989,87783,93469 +15886,13068,93686 +23889,58653,58943 +9586,64987,85913 +48042,57766,64407 +59723,23077,25949 +38991,40504,29105 +53279,54517,85869 +12655,61836,71643 +88335,26411,95898 +48264,36315,47338 +76242,98442,70678 +8560,29031,25497 +7011,23584,28357 +4056,53571,69329 +13546,3928,36801 +66759,42590,62900 +42576,6582,2509 +223,42850,65527 +67290,56105,37205 +26083,20922,72365 +38050,80439,13806 +36953,41012,75871 +7735,81076,79863 +53127,70122,86570 +82913,77855,80192 +66789,47426,55073 +6402,74366,85468 +12479,49050,50469 +81692,5699,28559 +13604,36658,29575 +47265,31544,52072 +58308,90383,81481 +83116,3946,34495 +74232,32189,99439 +44736,55268,64826 +27733,5047,44797 +77299,32249,99996 +1227,53961,33312 +57887,86519,96365 +17788,49227,41509 +43878,70212,83907 +96678,2919,29369 +56358,15650,58146 +17510,87833,341 +10561,34705,16300 +47960,14097,99121 +90025,99500,11337 +58092,53945,29847 +80527,83650,46840 +12884,38180,90629 +90870,26973,14997 +92661,87330,11713 +66261,10323,87881 +88762,99755,52308 +45887,66610,36257 +44995,97036,3748 +82214,45813,68168 +23981,94721,16711 +97214,7770,17284 +31546,21308,79663 +90529,12899,64428 +57437,46685,78908 +12148,38499,98665 +63077,12202,37034 +57028,80382,60827 +7424,86556,73802 +88045,23740,32556 +58714,78124,79545 +2847,93956,68357 +20365,21631,10442 +75827,86817,76975 +66974,50259,88537 +54276,32010,35247 +27111,88006,95783 +10471,64960,16150 +43924,55990,91561 +93301,98292,24857 +58712,5504,88295 +82158,53658,42852 +23896,93935,8507 +74023,25579,56426 +32838,43498,34833 +99414,25426,79869 +97458,83732,12246 +78741,30094,24759 +58816,61798,54529 +95844,72834,34499 +4170,8801,919 +76958,69837,95619 +4110,28898,88081 +65576,89204,31758 +72278,25530,65622 +95087,15967,95850 +74522,75129,37507 +48849,2682,20046 +96862,36220,97820 +16611,68228,53890 +64798,99505,48456 +40194,58598,77837 +80609,91760,35988 +29345,67179,62329 +64120,85352,89039 +36344,62374,17200 +67360,21281,20103 +65091,47575,11543 +54377,64539,21070 +50531,60695,4468 +63156,65316,48337 +39081,69839,6602 +18484,6670,43033 +82619,35535,30181 +59610,93711,3662 +73592,76824,20091 +5357,55696,71065 +81129,95603,18774 +82270,14171,3743 +67846,78944,34878 +49799,29792,62938 +61312,78077,87704 +75961,58989,88402 +70714,36048,94047 +65322,83218,39648 +43146,73660,39585 +89034,79880,81461 +94039,3723,43380 +60001,73303,14606 +51342,87233,97928 +19536,80344,82842 +22863,55769,35011 +37624,8159,57671 +25761,69941,5589 +64688,84882,70764 +89058,4967,61784 +54625,77836,42197 +41231,55619,77761 +58033,40312,29275 +61549,78420,29914 +97275,4177,739 +39676,2183,1153 +8377,80223,14696 +11199,23424,37851 +60248,47954,64816 +63645,62728,3572 +22336,97349,9221 +68026,36196,66190 +83125,12944,93283 +44007,48115,24517 +96271,89773,90445 +51692,96666,80616 +14911,98700,80558 +1438,52764,89614 +39519,4275,29014 +22832,46614,10622 +65630,8436,25666 +62134,82290,5210 +51472,75260,39461 +5687,39849,76941 +43816,36403,82811 +78116,73608,71209 +99308,23460,53569 +93098,12552,66804 +13847,74871,27526 +96724,55378,91673 +76843,43603,41699 +85056,79117,63589 +72676,94910,24784 +24514,23806,84033 +72348,30114,61944 +42093,19705,60888 +57441,58561,66261 +89088,88217,55314 +21494,31543,84332 +21884,53142,34367 +54599,72918,26186 +68425,9085,66747 +23828,41646,83488 +74804,89911,74719 +50795,58139,3344 +18962,91029,93685 +18323,30691,76878 +18306,51439,59725 +59623,16618,43856 +36320,33364,82869 +20315,404,43871 +28656,36436,2935 +13328,92433,85045 +24018,39379,1401 +28638,82078,29911 +18896,73792,63428 +35898,98238,63255 +76583,65108,65354 +33375,42967,49723 +20488,15426,91994 +75660,71326,47399 +81899,15937,50176 +51390,4739,57655 +92169,34636,5711 +67926,52009,98569 +93207,12016,57499 +19422,90859,53401 +59336,70550,79318 +24783,60379,35871 +50762,38160,42395 +55880,99320,85972 +54200,13306,56032 +91554,58858,10517 +46889,71248,37311 +91630,70366,30871 +16398,90384,9046 +1801,86891,32208 +74988,25808,34990 +22689,45964,79525 +62969,22388,49185 +28755,82623,42453 +49435,66991,41116 +19897,72208,1763 +72319,14238,51580 +12717,56898,50590 +18038,45337,31313 +68343,24952,75937 +13093,77919,3096 +21300,98393,61991 +29791,85814,99665 +343,3699,21725 +42777,83520,70225 +89730,4340,37921 +66952,61768,9289 +20514,3305,86715 +71924,70612,64142 +70529,69370,76591 +85030,44493,59983 +69514,7943,61871 +6970,37163,56564 +42947,38619,60360 +85256,38329,58422 +75881,80504,72064 +48399,5288,93540 +34749,52648,90102 +33133,12219,18576 +46014,1234,90956 +99221,70103,39097 +63969,98026,71899 +26948,81698,47223 +46365,44968,41833 +48891,99551,7283 +50508,69604,58651 +19789,22385,74326 +21529,6784,28998 +84011,55242,10167 +67269,73198,32257 +13812,75824,65634 +90312,42966,66387 +52791,41164,88925 +40945,16525,76962 +28250,4979,22490 +66412,55201,46125 +8854,72341,46752 +43425,39655,31888 +47937,70494,24770 +757,16312,24839 +26312,60845,64099 +91760,22170,79126 +7438,97669,56686 +18308,75806,42135 +28873,37189,93895 +90883,94021,8911 +96498,13631,38160 +79746,13009,94459 +6467,36315,89052 +69464,57698,11992 +40360,30616,84900 +56022,38566,7883 +97651,93976,55045 +18186,38746,3562 +70670,72125,96320 +13462,44327,12781 +34993,48453,8057 +38175,72408,5140 +72472,26117,62917 +58412,22826,40616 +61863,98617,17528 +89361,52416,58024 +60355,16120,44189 +47564,61916,27377 +47391,31392,81564 +53952,88236,78074 +8020,53425,37291 +49245,94758,43387 +50721,95586,78252 +77188,79706,97584 +25708,99029,42022 +6544,50664,42906 +4798,47125,5146 +26774,33330,43556 +75735,78952,78415 +30655,36588,65500 +16791,30941,17756 +45385,14882,88852 +44187,2596,46004 +91279,65104,11759 +72737,4234,90260 +14997,78112,73048 +57696,83966,37120 +10658,74381,87044 +25885,91018,11337 +88832,48531,56507 +4271,1281,70956 +51462,28353,4013 +27416,73883,23993 +97546,62554,20898 +10637,50282,6729 +87876,33006,85586 +83090,96048,81258 +5376,24609,69812 +53878,28636,99300 +75907,7966,45014 +6640,61592,15366 +12635,52072,21325 +85097,69501,44453 +94215,65305,38362 +83097,1281,95181 +65098,10932,58768 +9428,65309,51066 +95698,76849,57757 +23042,87396,79112 +27112,48329,27025 +55639,92559,12501 +61605,82723,19356 +3298,43240,47493 +23511,2874,98596 +75010,7116,81264 +16139,76073,65207 +33173,40208,86904 +11831,76923,50412 +54525,40428,12706 +83633,94133,14925 +25540,21445,69878 +55847,39617,48238 +67188,59040,46543 +72728,74047,51831 +66501,68590,37501 +36862,73253,7404 +29185,1666,50428 +80604,81869,22122 +1394,18144,48294 +60730,3031,85750 +47269,15999,57920 +23833,18265,85226 +40488,64065,43377 +3975,15666,51378 +13554,38627,23872 +97689,27957,21143 +43709,63686,46499 +92259,25469,3278 +61138,82275,76015 +65141,58671,28486 +29702,25207,64396 +60525,24817,66396 +68882,92239,86375 +41255,62,37187 +86214,58340,49928 +17871,54058,53793 +20078,37885,76460 +91636,9498,80144 +93494,51323,51057 +48960,98604,81159 +76272,72161,83555 +71324,48466,3212 +28195,68348,7331 +73215,49717,87905 +47584,31910,53809 +88459,39267,79672 +32573,5408,4989 +75852,46070,4689 +3489,46505,96293 +42255,32348,65664 +1706,23875,78511 +21293,87355,37636 +81974,11916,58005 +70018,74392,28440 +40462,32654,44435 +22823,95017,89944 +19969,30058,65985 +32735,43165,10392 +87031,37428,18594 +97048,80371,56671 +1410,42028,99790 +32206,48702,34184 +8592,4288,12763 +43966,55329,18499 +11813,16379,96028 +29533,68131,65308 +2478,54036,72453 +9822,16122,88705 +79202,67043,37803 +45042,92044,71299 +49647,44552,91283 +9070,19093,5227 +31884,41764,41665 +46138,96858,70120 +1534,57579,89175 +76096,12987,71669 +45304,50371,5283 +14439,16877,93874 +74629,92424,85342 +38562,57237,64241 +35084,60432,35139 +91132,77685,13720 +5128,1494,86740 +19346,87422,55369 +27536,43037,35712 +22082,36023,28558 +39942,89539,80446 +41533,40108,37221 +99288,70652,72781 +59317,9409,11639 +7604,43986,51976 diff --git a/day8/zig/main.zig b/day8/zig/main.zig new file mode 100644 index 0000000..1a4a2e5 --- /dev/null +++ b/day8/zig/main.zig @@ -0,0 +1,118 @@ +const std = @import("std"); + +const Box = struct { x: i64, y: i64, z: i64, circuit: usize }; + +const Pair = struct { p1: usize, p2: usize, dist: i64 }; + +const CONNECTIONS = 100; + +pub fn main() !void { + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + defer _ = gpa.deinit(); + + var stdin_buffer: [1024]u8 = undefined; + var stdin_reader = std.fs.File.stdin().reader(&stdin_buffer); + + const stdin = &stdin_reader.interface; + + const allocator = gpa.allocator(); + var boxes = try std.ArrayList(Box).initCapacity(allocator, 1); + defer boxes.deinit(allocator); + + var counter: usize = 0; + + while (try stdin.takeDelimiter('\n')) |line| { + const line_trimmed = std.mem.trim(u8, line, "\n"); + var it = std.mem.splitScalar(u8, line_trimmed, ','); + + const x = try std.fmt.parseInt(i64, it.next().?, 10); + const y = try std.fmt.parseInt(i64, it.next().?, 10); + const z = try std.fmt.parseInt(i64, it.next().?, 10); + + try boxes.append(allocator, Box{ .x = x, .y = y, .z = z, .circuit = counter }); + counter += 1; + } + + var pairs = try std.ArrayList(Pair).initCapacity(allocator, 1); + defer pairs.deinit(allocator); + + for (boxes.items, 0..) |box1, i| { + for (boxes.items[i + 1 ..], i + 1..) |box2, j| { + const d = distance(box1, box2); + + try pairs.append(allocator, Pair{ .p1 = i, .p2 = j, .dist = d }); + } + } + + std.mem.sort(Pair, pairs.items, {}, pair_sort); + + for (0..CONNECTIONS) |i| { + const p1 = pairs.items[i].p1; + const p2 = pairs.items[i].p2; + + const c1 = boxes.items[p1].circuit; + const c2 = boxes.items[p2].circuit; + + // Both + if (c1 == c2) { + continue; + } + + // Different circuits + // Switch every box from circuit c2 to c1 + for (boxes.items) |*box| { + if (box.circuit == c2) { + box.circuit = c1; + } + } + + // Check if we are a single circuit + const first = boxes.items[0].circuit; + var found = false; + for (boxes.items) |box| { + if (box.circuit != first) { + found = true; + break; + } + } + if (!found) { + std.debug.print("{d}\n", .{ boxes.items[p1].x * boxes.items[p2].x }); + break; + } + } + + var circuits = try std.ArrayList(usize).initCapacity(allocator, 1); + defer circuits.deinit(allocator); + + for (0..boxes.items.len) |_| { + try circuits.append(allocator, 0); + } + + for (boxes.items) |box| { + circuits.items[box.circuit] += 1; + } + + std.mem.sort(usize, circuits.items, {}, comptime std.sort.desc(usize)); + + var task1: usize = 1; + for (0..3) |i| { + task1 *= circuits.items[i]; + } + + // for (0..boxes.items.len) |i| { + // for (0..boxes.items.len) |j| { + // std.debug.print("{d}", .{adjacency.items[i].items[j]}); + // } + // std.debug.print("\n", .{}); + // } + + std.debug.print("{d}\n", .{task1}); +} + +fn pair_sort(_: void, p1: Pair, p2: Pair) bool { + return p1.dist < p2.dist; +} + +fn distance(p1: Box, p2: Box) i64 { + return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y) + (p1.z - p2.z) * (p1.z - p2.z); +} diff --git a/day8/zig/sample.txt b/day8/zig/sample.txt new file mode 100644 index 0000000..e98a3b6 --- /dev/null +++ b/day8/zig/sample.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