diff --git a/Cargo.toml b/Cargo.toml index 2c704a6..9420c89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,5 +31,9 @@ path = "src/day6/main.rs" name = "day7" path = "src/day7/main.rs" +[[bin]] +name = "day8" +path = "src/day8/main.rs" + [dependencies] anyhow = "1.0.100" diff --git a/src/day8/act.txt b/src/day8/act.txt new file mode 100644 index 0000000..6c2f87f --- /dev/null +++ b/src/day8/act.txt @@ -0,0 +1,1000 @@ +96308,96375,66842 +52621,1479,29614 +79213,87747,77565 +22875,9010,68731 +58112,11083,91722 +24708,5404,6883 +45973,8952,70502 +21569,42617,95307 +91813,29567,46447 +91802,14479,55428 +11802,65255,26160 +42356,64252,98573 +31359,89172,27171 +71029,81486,82588 +98019,47833,54412 +69256,58239,39805 +31066,99829,21911 +86667,51367,78765 +21148,82593,83755 +89496,65271,93080 +6215,56663,41205 +65231,48811,4016 +84510,55187,73472 +68369,4764,47123 +83467,13334,1442 +17147,38533,29623 +33507,66005,59889 +16443,78886,59215 +8848,66984,31113 +38503,12041,63461 +66582,9872,42427 +57768,84773,40913 +87552,33856,78234 +71666,92512,29798 +52209,32340,34863 +30542,54037,79244 +10247,17110,28579 +83249,1683,91904 +22043,97952,801 +61587,67068,76476 +7285,94172,96500 +14493,72642,22439 +21984,54861,78163 +15116,41573,67280 +54498,5585,93804 +99932,4266,56711 +84847,13488,80046 +53203,81922,39461 +81329,79186,86588 +32193,56494,40049 +92685,98173,53766 +81784,57937,18598 +39939,7615,7906 +25578,62072,76597 +74040,33023,37751 +29840,92090,57592 +28963,41012,46607 +30136,46240,44739 +5483,94540,89175 +1568,4413,8875 +10444,5231,94339 +7100,79355,97450 +80040,91545,62145 +99356,49925,13895 +56467,95375,16420 +61795,52078,65247 +63342,9708,5851 +79283,87729,65460 +42743,79342,54572 +61629,33358,18041 +75779,5754,69435 +27788,21011,32001 +9904,22263,55223 +44777,8733,80344 +33301,31614,51350 +37405,18745,57098 +16150,73792,4398 +54388,71787,84424 +16873,67887,7575 +77506,71580,95636 +44093,51613,96105 +48098,62767,57724 +60521,10018,38076 +61590,93770,32207 +23411,79030,45539 +22421,83557,86012 +88366,70242,43094 +81637,80801,65255 +23414,57173,10087 +25142,22058,51309 +53526,79034,79920 +30495,87803,78910 +25686,55081,2102 +79608,56649,84800 +46019,16634,42435 +50429,49604,65058 +37724,8283,68091 +16075,84280,88128 +26287,7996,26421 +7274,10532,82421 +70722,19777,93426 +54918,85895,92182 +87220,32662,66026 +89769,35283,33240 +6254,40376,42121 +52166,58605,38545 +55959,48773,24205 +9332,94397,17221 +81313,68954,3579 +41687,64269,75042 +70779,1576,71910 +30879,45497,57332 +53736,426,36635 +62537,64056,60542 +35115,79838,87568 +96419,99383,32664 +80976,70443,43425 +71021,83949,24476 +85733,26837,76232 +23431,76532,54881 +76367,3314,87694 +11304,29086,40173 +64182,88857,33921 +25089,31354,71205 +55527,83111,83714 +67014,87977,56553 +47184,56189,40271 +31964,78877,7445 +70326,99288,10896 +79888,29904,15945 +43591,86458,35693 +9784,79886,98370 +52848,96085,67012 +95472,49749,34906 +71867,95093,47919 +97397,78144,13042 +72671,1202,19470 +55485,89986,75068 +85765,4107,57904 +7543,87473,22937 +98629,61520,82581 +81246,15882,9748 +57750,89836,3647 +81832,71287,88670 +63337,53123,71094 +92188,19900,43925 +74616,98615,90203 +4275,64828,44458 +53220,6835,11464 +41999,28186,57057 +60388,72439,18951 +5536,56828,30403 +97751,39213,36074 +76299,5198,63981 +54593,64854,43588 +26028,66701,83345 +53977,59362,19027 +68362,42502,75230 +24140,30683,65184 +10091,43446,23813 +82295,33416,10498 +51575,50654,47583 +32604,46564,65300 +28424,39232,26160 +78608,97655,89138 +71982,86097,54378 +88502,97115,52364 +41189,13811,92127 +69332,76539,25810 +43922,61431,45686 +24294,32974,30611 +31597,43282,55572 +27985,59458,57903 +23764,41135,75757 +48954,40895,47201 +38381,99929,73492 +35023,37715,30934 +68091,86037,31523 +71139,36020,97214 +66531,48574,30660 +61778,86410,15530 +14948,9367,25473 +7615,95567,69060 +47304,52545,32111 +11373,72023,44675 +1350,62042,10566 +96762,59483,56902 +81564,80606,38760 +27004,70067,2433 +93229,2794,17635 +1888,64649,99938 +32542,60277,30800 +74190,25219,94601 +70964,93492,7881 +59604,97235,89986 +25150,86455,55047 +98168,82626,30055 +55170,16425,17539 +48943,14882,13775 +66216,94204,24600 +40660,60013,73888 +23482,48855,59046 +94751,33039,20608 +72598,66500,20321 +98199,28991,8172 +14503,72598,35255 +90487,94511,71528 +98756,20495,76594 +4155,86320,59885 +24380,32,40287 +20239,58980,85627 +579,96937,81165 +91732,44414,58578 +13705,81488,24151 +65725,745,41442 +84033,37442,47992 +29739,70120,47177 +76603,26614,17331 +12524,83607,66214 +33539,42682,29743 +36507,83904,40087 +3332,39463,67410 +80744,66725,88780 +31136,53939,74741 +51456,72255,53924 +45805,85036,70706 +32127,64235,89550 +91041,31804,32881 +44804,5952,1651 +80120,85913,68538 +79760,43950,36060 +89517,33903,12605 +52066,29557,63062 +38811,89651,67817 +3546,70624,88244 +54104,31131,51965 +44799,43843,19204 +50728,59944,79084 +57759,20964,23407 +43139,85586,11614 +67330,36035,59664 +99901,71961,99058 +23596,69381,7109 +42226,27966,26328 +41589,82940,57443 +73252,41009,98546 +85000,43525,99169 +92396,75980,69209 +40216,11717,22359 +66922,75407,76656 +89209,9918,70856 +50670,85083,23378 +59373,21749,30320 +23280,22118,67372 +41707,85081,43275 +40262,98637,9114 +55589,60842,20125 +66078,6051,10557 +99502,93691,72105 +39840,95242,48679 +99914,88481,13364 +35254,50678,44445 +85949,59502,70044 +71034,18285,40132 +13023,19669,56148 +20433,94379,25852 +97559,18714,6729 +95286,17417,58493 +77849,13017,87276 +83275,80321,15211 +99341,70424,73319 +16412,57479,65548 +44232,77053,87621 +2729,30194,70672 +74903,10917,73145 +87876,29774,25979 +90819,16770,65345 +88260,7245,15744 +73586,53401,64718 +44371,79328,39717 +52508,18252,34434 +78049,11146,82321 +66024,83004,63590 +59101,84137,80336 +51612,79951,77255 +70469,16653,81597 +16277,88238,15713 +81391,55957,3631 +44149,94060,70678 +56204,96001,32664 +11589,99764,8671 +36249,93265,65597 +50613,77046,48783 +7945,38820,38221 +66551,39449,45953 +88057,94891,75947 +36453,53422,70731 +7360,76036,61366 +67122,76587,91731 +46372,25704,52596 +29884,37066,30601 +12263,10055,41949 +20266,22722,3896 +51918,24962,29916 +63281,98069,56350 +87560,72239,27574 +78954,95069,26553 +46464,23335,83842 +34999,85219,90104 +93275,51582,57299 +70340,94603,61242 +39706,19568,50022 +57473,22537,62826 +73172,32093,66935 +41127,86064,90887 +20223,93940,36585 +67561,57131,87640 +54112,18863,17293 +70732,21279,90100 +63593,58306,34970 +69581,92038,10714 +15139,37704,31629 +85716,6449,29094 +9013,65166,54286 +89891,45574,12967 +36771,35310,58960 +32224,419,10989 +63187,97976,95680 +84461,84248,34920 +95097,46902,16134 +44693,21101,79828 +46339,17254,21066 +33901,42906,58995 +26947,7675,55954 +54771,87500,90942 +86246,40881,88555 +21145,78936,85241 +96013,70676,30958 +53933,96239,49302 +51154,39724,37341 +38506,80009,58050 +24541,25538,84371 +94637,14792,33934 +66882,52100,25084 +47254,21669,71414 +89875,43933,80389 +49404,14248,37028 +5749,81898,97970 +84181,34480,864 +93410,74386,56409 +54857,87448,40726 +50077,88065,9151 +6878,14491,81798 +94362,72036,28559 +31830,33522,29294 +98745,88754,76644 +20416,40703,39389 +74775,96653,21975 +95818,56273,73036 +50380,97488,57560 +59049,32967,692 +49242,39605,5768 +52883,32023,82080 +81443,47121,51760 +39710,58276,44981 +78509,4762,27045 +15021,30393,12076 +66044,80591,54003 +9808,84165,63418 +66909,66011,56687 +80816,61811,72788 +54812,39142,73638 +13468,37623,25108 +23121,31637,1461 +42610,96261,56353 +46751,64713,67210 +7483,64244,59331 +60959,4650,82032 +20069,16227,97699 +80418,59587,2191 +4872,34976,47042 +65120,5148,8303 +40745,2436,65546 +80064,55531,47677 +63759,92739,36730 +85831,76632,39843 +90537,35532,69952 +34613,47429,33974 +33202,53680,40641 +38644,31778,43085 +47129,33956,90163 +27156,21700,62900 +3302,55934,15569 +26332,94503,28564 +94647,33376,80375 +10755,97794,93763 +64204,29202,15409 +10207,95805,37757 +39717,19913,8932 +54917,82247,8122 +66837,23527,65112 +52541,16561,27815 +41261,80414,15973 +64340,56800,24771 +61738,29060,34291 +43410,7291,87483 +79821,24135,27955 +6415,25147,98506 +14792,69533,37638 +50293,72942,83423 +19862,55394,66711 +21652,83777,69194 +8763,1100,4584 +72307,90314,43694 +20756,53992,12533 +37514,60743,6964 +15383,71290,5760 +1139,31529,5868 +81320,15314,81409 +53048,48259,23888 +97264,27416,4289 +44328,33469,98645 +28594,54804,17149 +12056,99736,39705 +84800,32804,88524 +33908,69457,56427 +95720,29772,70313 +75012,44861,19722 +87615,87058,4529 +52765,14556,40356 +55485,36773,83152 +34389,15851,66283 +90137,22913,23445 +64969,23204,22421 +56233,14901,48140 +79913,59261,83817 +48058,98306,75266 +34766,60752,82248 +34194,7574,87008 +6369,8071,42469 +28198,34863,47922 +86198,6643,31813 +80972,89533,66935 +99216,2964,1388 +4702,868,72643 +63614,14195,69210 +25118,56942,44788 +26088,16523,82787 +55118,61855,94295 +48426,12423,28280 +32004,60312,3051 +84429,53376,98290 +61378,49774,1648 +13783,41015,31021 +44007,59578,10667 +97702,69596,54835 +62926,43030,77807 +23789,47224,20505 +22397,23388,36838 +40639,88961,16689 +87086,26055,27601 +23834,49280,95187 +29993,29578,48705 +95581,47806,79740 +79737,66044,66265 +12928,96085,34016 +18184,48238,97350 +69767,96821,54341 +16536,24422,74117 +25699,68117,84257 +79184,73416,8090 +21859,42185,32186 +10211,16045,64040 +92352,65022,30316 +62557,83795,37447 +75003,52018,83069 +66400,55288,93741 +49178,86507,7491 +69280,49087,92226 +14107,61685,39392 +32230,36320,21224 +73590,14505,16342 +54369,98664,57063 +43904,24331,53850 +36407,97338,30342 +47750,55764,13571 +35030,46587,81753 +99442,5029,81264 +24450,13261,91422 +68862,69138,47472 +2205,35702,4322 +65696,58825,34747 +40270,57675,9672 +25823,24694,99580 +23284,59269,50501 +52748,57960,93644 +17407,17532,8583 +28046,71008,29364 +48799,26513,55246 +48148,1742,13528 +96721,39254,96121 +78541,727,72019 +59573,16918,1837 +37,6538,73168 +38357,24425,34627 +28608,35667,47798 +18497,73653,3508 +81141,2656,29358 +5532,79850,39757 +83077,14001,27958 +95755,99479,50573 +13154,71332,75685 +56807,99402,45387 +63907,70590,1549 +82737,67421,81483 +47646,17743,77333 +37405,13258,8135 +5062,4463,68691 +80238,45466,82737 +69041,65907,90557 +33885,69655,72424 +85979,26236,80933 +65202,60035,83303 +8351,67160,55896 +80023,11675,52165 +5372,54467,74342 +98650,10886,42037 +95733,65863,60319 +34289,9275,2790 +16365,69404,24279 +19299,72881,69190 +83495,62206,316 +5269,98457,94460 +50966,51195,55879 +73535,23373,17690 +98063,42023,99300 +74480,44229,57636 +42995,97660,95942 +6071,62174,98497 +24754,14835,65442 +54756,72438,52150 +48775,84391,60856 +86745,11794,43578 +48694,62995,45745 +55090,33836,23824 +72390,51910,62849 +80398,14983,66292 +11074,73512,87841 +82359,58934,14031 +33881,65484,40933 +97703,74159,63299 +44695,8376,59804 +59230,7776,217 +4559,32017,1662 +57531,91031,5118 +15422,95062,71156 +43253,98405,84229 +52271,94107,92836 +74525,76035,69690 +66271,54283,54493 +91433,31939,42412 +43044,77444,45763 +80497,65991,59809 +74186,62299,99231 +79248,1343,81205 +84457,97342,59922 +33217,47949,90777 +32547,97664,18254 +84424,42504,45907 +44427,41425,80158 +41897,69225,48742 +47793,91675,89027 +19871,37569,41945 +59018,25706,28862 +92791,73394,66878 +29534,75031,56277 +12696,25636,98516 +50359,63043,13192 +30808,42994,89900 +89641,44059,49745 +97569,89532,26634 +4904,7952,75194 +1079,29098,45678 +87394,4752,43002 +23101,30061,57871 +30886,26849,96660 +77246,81109,94413 +41006,54940,15862 +63881,82473,48860 +87843,44245,2632 +67380,56063,13637 +8094,39991,40483 +23208,81510,69366 +288,94287,30458 +52636,32850,13922 +41874,37995,69931 +91097,9542,70562 +69741,54006,83959 +53831,3720,82940 +90303,61648,96341 +58112,21628,33736 +46097,95191,74301 +55145,82651,71220 +91956,87892,65986 +51116,96962,99482 +20191,91001,46275 +27436,108,63491 +66104,67297,91027 +38207,80986,97392 +63544,37682,6024 +12210,14570,6322 +79665,3314,9783 +96511,93749,49995 +59198,58588,69015 +53588,23198,56891 +29253,879,15463 +58123,64010,27058 +82403,73848,29561 +45181,81953,13168 +59976,17718,73776 +92767,54302,89733 +75651,35927,35424 +40888,41817,41333 +93609,10925,34737 +8454,99478,9437 +24974,6140,2861 +92394,99161,72436 +95211,14516,44379 +39166,62745,95589 +21274,7902,67898 +50453,27130,32834 +80014,64395,74468 +29595,8115,69232 +88004,61392,34176 +18679,21736,9215 +83605,36437,63932 +11118,18487,35790 +77899,26697,80952 +87571,94080,12143 +19777,53958,49471 +64373,88368,51340 +65041,40663,30942 +56993,64257,84105 +64270,14803,95441 +81881,92421,15829 +9203,69399,52840 +54199,17163,31244 +14494,69152,79418 +72019,27378,44828 +21416,64346,40956 +22785,3970,75755 +65003,93523,77076 +24361,76555,35392 +54675,78773,82179 +8066,95963,59907 +15461,36783,63065 +386,89474,29317 +15146,95998,76177 +94258,67586,38080 +56175,3887,89932 +36030,69444,2338 +88244,36297,10554 +67833,42809,73725 +11,21690,79112 +79711,40029,45204 +93421,40555,30610 +34199,40464,90685 +96911,39133,2580 +26326,17027,12842 +81775,93043,60097 +7774,99299,88492 +56828,27409,14424 +2519,50802,72522 +24078,9185,81162 +20094,18647,17923 +51303,1785,13862 +68038,58966,88589 +73171,16555,29697 +49952,74582,73611 +75988,8569,57886 +2322,30749,8338 +35674,36514,97207 +12278,40035,15740 +53228,42456,57650 +73318,20588,15491 +32636,91216,97456 +48366,68587,1927 +82501,51138,70160 +38294,26246,80749 +24712,81010,36155 +8634,76588,59962 +10872,39794,53879 +48895,35932,90441 +67753,98256,14952 +54631,92729,45955 +39960,7844,18075 +80111,88449,14667 +69711,89315,36714 +43784,55067,49868 +33755,27042,87532 +19741,76024,5479 +89992,83968,935 +30031,43164,26134 +36898,88376,51888 +62035,15836,11459 +26597,42865,46652 +36925,76124,21009 +36874,24521,48086 +28273,26331,96912 +33039,76851,98517 +23954,25362,92110 +69891,48811,46723 +84437,27332,29220 +34677,77362,12783 +9255,59233,20354 +9897,58134,92508 +17539,9327,88727 +41292,15648,50975 +64367,88361,84417 +17690,97470,36965 +35954,85059,55266 +98810,56860,4987 +94707,62674,24329 +41986,45909,19313 +2068,94026,45068 +88706,47887,31206 +38787,38581,9344 +54819,65563,50911 +66593,34005,56420 +98011,57012,56214 +96920,6792,34135 +74277,17101,87425 +60547,95927,74542 +46378,85369,50650 +85948,91294,17027 +97923,37702,3316 +34264,25959,29665 +2114,28419,73251 +38111,49929,91618 +80435,2449,37503 +45108,17553,71106 +79522,29746,23098 +41980,68062,42167 +12574,76829,90407 +91710,81018,85965 +69558,28312,50062 +45186,55308,1511 +76365,40024,45440 +14459,97088,21660 +94912,89724,94322 +14710,40114,50116 +73514,59931,66375 +57656,57057,27874 +32561,76454,2866 +16577,46518,77366 +27392,44099,10651 +36498,79051,90024 +11861,35501,26495 +16704,86737,53393 +71419,32706,96586 +11537,94063,78173 +4417,95604,25745 +21217,91843,87779 +77276,74689,58313 +34069,29643,36686 +98166,84973,53749 +79786,6212,33992 +7896,96472,99323 +84218,92215,92651 +91520,65481,60221 +81581,30965,15249 +79329,98515,8714 +8469,39478,46582 +17016,52404,65351 +19228,57001,50519 +41065,79039,35887 +28065,93245,20031 +18181,14899,50145 +96217,95889,7425 +40706,67245,63489 +10668,72339,28291 +44624,68165,22656 +50740,41242,66571 +93928,72984,94968 +22134,96167,96612 +79767,77609,21464 +48587,82839,82322 +42878,12173,48342 +19924,77866,76218 +7776,85727,70564 +50016,63389,88849 +6582,93233,51085 +86491,97728,5065 +10494,21466,8631 +16997,54114,10113 +21608,7313,36611 +61163,19012,14530 +47208,7608,19542 +97288,33928,14549 +10029,75454,8747 +32302,80323,36094 +2153,46248,45732 +40663,87563,83167 +44378,81608,89959 +7735,6661,16124 +81590,11545,41627 +16025,94084,52252 +85938,85452,55197 +63503,90358,73598 +89217,62144,89159 +37166,94259,51421 +67418,49090,57876 +39490,69364,38520 +89207,25910,63768 +10234,14984,27375 +37400,77483,5889 +22865,39056,44327 +5758,60680,60183 +55523,29926,31257 +56132,53109,70472 +23866,78244,18278 +99274,38670,71870 +59826,37729,62460 +70913,31223,71813 +63662,84157,7684 +29027,54855,72565 +43055,10051,76716 +86603,9865,31786 +3403,44794,62299 +57858,25394,29398 +55310,87654,90014 +8507,55852,7081 +25399,42713,72662 +96647,84716,15403 +98970,36550,44707 +70282,75860,32256 +67469,88082,29041 +22896,57406,76799 +15717,44744,37518 +1645,32398,78006 +90822,5667,10956 +12305,92491,81395 +64426,74379,64455 +16932,32924,90628 +48810,8780,47155 +22525,40644,68262 +47452,50326,80004 +41226,21658,70762 +51125,62431,8831 +68864,12959,9819 +37379,69313,16085 +50902,57171,35569 +88551,57714,93400 +77808,77883,39853 +4956,35790,62840 +21709,7689,98166 +30304,92310,11112 +3434,97660,39582 +79555,83234,36013 +58105,31720,69879 +65395,86617,27818 +5691,89850,91906 +5293,91642,71688 +6133,32564,71397 +3638,38899,77514 +9211,81982,914 +77475,95485,75102 +23036,95101,27339 +4662,90461,18932 +59407,79002,36837 +20506,74521,63103 +6414,12625,16431 +34321,20087,96201 +64510,47054,78914 +18668,7431,14173 +56156,81626,51152 +59520,13975,50532 +7055,99186,73353 +9269,46850,69213 +3907,66820,18348 +98927,948,20045 +37299,1071,34643 +84657,66773,57711 +90266,44173,86179 +71556,39185,15685 +39055,99295,52935 +63346,42115,12017 +39320,6906,32450 +4184,51620,92617 +49446,71066,49165 +42501,41473,18382 +37725,83461,98764 +55444,37822,7901 +94714,41543,79748 +29371,66318,66215 +47738,75333,19338 +27157,32896,52861 +95616,96121,46065 +82868,412,79570 +49293,28636,85131 +19731,45578,94176 +72202,98485,47025 +30591,34224,48892 +87061,19543,43575 +58104,25999,27357 +72410,58755,9429 +43220,57126,63740 +43448,57083,1848 +51106,74937,25363 +8663,64846,17443 +70269,9565,66126 +59647,67782,78556 +64558,83028,83001 +9020,35850,4690 +94141,9025,10475 +40126,19004,48415 +6271,46260,82805 +59530,99140,87533 +83042,66613,41872 +55209,56265,86263 +77594,33154,545 +86649,66293,20778 +74940,21060,79331 +6994,78664,11476 +85908,7202,5093 +70135,89170,80551 +92603,26943,89307 +96806,30713,13654 +91761,13860,77616 +22973,14934,8703 +57454,63424,21851 +9777,11941,15456 +31652,48285,13035 +27910,935,54021 +8794,88615,82496 +99499,82996,41254 +14544,59014,96621 +80410,628,19186 +33326,36163,57162 +9765,55917,2011 +18270,30809,62143 +79290,47673,30824 +98257,16454,54399 +43494,91517,42103 +97217,54770,18572 +1310,84968,41521 +57455,50284,93471 +74738,25219,85499 +70703,99300,81190 +40348,50626,6187 +54104,81377,41756 +77344,8124,53401 +62719,66360,2845 +29769,16004,45838 +82130,12908,89454 +3907,78905,37868 +58301,64192,82393 +65808,98317,75563 +41675,17711,71724 +17284,87553,14500 +84504,72087,32587 +26426,48613,72107 +47659,30958,91083 +99221,72156,38268 +23663,55812,43006 +33573,45205,18795 +31093,43015,23024 +18156,96011,89689 +25983,50115,22147 +61052,61630,30311 +48334,79615,73912 +47869,85142,64015 +51941,29408,5994 +67503,77247,53628 +89192,33485,5905 +44588,7902,71760 +27585,45796,95819 +94410,98517,32257 +22326,42583,37398 +37579,64636,22536 +50506,55594,71027 +65263,8286,57842 +31705,44633,94040 +50253,57916,76455 +45364,64661,69299 +69136,89819,47212 +90499,75990,62947 +9436,5047,81793 +83866,55848,34452 +40381,41965,90649 +38283,16032,28024 +45573,34285,95799 +80545,10636,41930 +60943,39418,2734 +66442,88111,25771 +76185,79346,1164 +41030,81008,65033 +95438,86810,64383 +97306,92389,8061 +8129,74968,64795 diff --git a/src/day8/main.rs b/src/day8/main.rs new file mode 100644 index 0000000..498de35 --- /dev/null +++ b/src/day8/main.rs @@ -0,0 +1,219 @@ +use anyhow::Result; +use std::{ + collections::{HashMap, HashSet}, + fs, +}; + +#[derive(Debug, PartialEq, Eq, Hash)] +struct JunctionBox { + x: i64, + y: i64, + z: i64, +} + +impl JunctionBox { + fn dist(&self, other: &JunctionBox) -> f64 { + (((self.x - other.x).pow(2) + (self.y - other.y).pow(2) + (self.z - other.z).pow(2)) as f64) + .sqrt() + } +} + +impl Into for &str { + fn into(self) -> JunctionBox { + let mut niter = self.split(","); + let x: i64 = niter.next().unwrap().parse().unwrap(); + let y: i64 = niter.next().unwrap().parse().unwrap(); + let z: i64 = niter.next().unwrap().parse().unwrap(); + JunctionBox { x, y, z } + } +} + +struct Pair<'a> { + b1: &'a JunctionBox, + b2: &'a JunctionBox, + dist: f64, +} + +impl<'a> Pair<'a> { + fn new(b1: &'a JunctionBox, b2: &'a JunctionBox) -> Pair<'a> { + Pair { + b1, + b2, + dist: b1.dist(b2), + } + } +} + +struct Circuit<'a> { + set: HashSet<&'a JunctionBox>, +} + +fn sol1(text: &str) { + let boxes: Vec = text + .split("\n") + .filter(|s| s.len() > 0) + .map(|s| s.into()) + .collect(); + + let mut pairs: Vec = Vec::with_capacity(boxes.len() * boxes.len()); + + for (i, b1) in boxes.iter().enumerate() { + for b2 in boxes.iter().skip(i + 1) { + pairs.push(Pair::new(b1, b2)) + } + } + + pairs.sort_by(|a, b| a.dist.total_cmp(&b.dist)); + + let mut box_to_circuit: HashMap<&JunctionBox, usize> = HashMap::new(); + let mut circuits: Vec> = Vec::new(); + + for pair in pairs.iter().take(1000) { + print!("{} {:?} {:?}", pair.dist, pair.b1, pair.b2); + let b1c = box_to_circuit.get(pair.b1); + let b2c = box_to_circuit.get(pair.b2); + if b1c.is_some() && b2c.is_some() { + let b1c = *b1c.unwrap(); + let b1c_set = circuits[b1c].as_ref().unwrap(); + if b1c_set.set.contains(pair.b2) { + println!(" nothing"); + continue; + } + let b2c = *b2c.unwrap(); + let mut b2c_set: Option = None; + std::mem::swap(&mut circuits[b2c], &mut b2c_set); + let b2c_set = b2c_set.unwrap(); + for item in b2c_set.set.iter() { + box_to_circuit.insert(item, b1c); + } + circuits[b1c].as_mut().unwrap().set.extend(&b2c_set.set); + println!(" merge"); + } else if b1c.is_some() { + let b1c = *b1c.unwrap(); + circuits[b1c].as_mut().unwrap().set.insert(pair.b2); + box_to_circuit.insert(pair.b2, b1c); + println!(" b1"); + } else if b2c.is_some() { + let b2c = *b2c.unwrap(); + circuits[b2c].as_mut().unwrap().set.insert(pair.b1); + box_to_circuit.insert(pair.b1, b2c); + println!(" b2"); + } else { + let mut set = HashSet::new(); + set.insert(pair.b1); + set.insert(pair.b2); + circuits.push(Some(Circuit { set })); + box_to_circuit.insert(pair.b1, circuits.len() - 1); + box_to_circuit.insert(pair.b2, circuits.len() - 1); + println!(" new"); + } + } + + let mut circuits: Vec = circuits + .into_iter() + .filter(|s| s.is_some()) + .map(|a| a.unwrap()) + .collect(); + + circuits.sort_by(|a, b| a.set.len().cmp(&b.set.len())); + + println!("cirt tot: {}", circuits.len()); + for i in circuits.iter().rev() { + println!("cirt: {}", i.set.len()); + } + + println!( + "Sol1: {}", + circuits + .iter() + .rev() + .take(3) + .fold(1, |m, i| m * i.set.len()) + ); +} + +fn main() -> Result<()> { + let text = fs::read_to_string("src/day8/act.txt")?; + + sol1(&text); + + let boxes: Vec = text + .split("\n") + .filter(|s| s.len() > 0) + .map(|s| s.into()) + .collect(); + + let mut pairs: Vec = Vec::with_capacity(boxes.len() * boxes.len()); + + for (i, b1) in boxes.iter().enumerate() { + for b2 in boxes.iter().skip(i + 1) { + pairs.push(Pair::new(b1, b2)) + } + } + + pairs.sort_by(|a, b| a.dist.total_cmp(&b.dist)); + + let mut box_to_circuit: HashMap<&JunctionBox, usize> = HashMap::new(); + let mut circuits: Vec> = Vec::new(); + + for pair in pairs.iter() { + print!("{} {:?} {:?}", pair.dist, pair.b1, pair.b2); + let b1c = box_to_circuit.get(pair.b1); + let b2c = box_to_circuit.get(pair.b2); + if b1c.is_some() && b2c.is_some() { + let b1c = *b1c.unwrap(); + let b1c_set = circuits[b1c].as_ref().unwrap(); + if b1c_set.set.contains(pair.b2) { + println!(" nothing"); + continue; + } + let b2c = *b2c.unwrap(); + let mut b2c_set: Option = None; + std::mem::swap(&mut circuits[b2c], &mut b2c_set); + let b2c_set = b2c_set.unwrap(); + for item in b2c_set.set.iter() { + box_to_circuit.insert(item, b1c); + } + circuits[b1c].as_mut().unwrap().set.extend(&b2c_set.set); + + if circuits[b1c].as_ref().unwrap().set.len() == boxes.len() { + println!("\n\nsol2: {}", pair.b1.x * pair.b2.x); + + return Ok(()); + } + + println!(" merge"); + } else if b1c.is_some() { + let b1c = *b1c.unwrap(); + circuits[b1c].as_mut().unwrap().set.insert(pair.b2); + box_to_circuit.insert(pair.b2, b1c); + + if circuits[b1c].as_ref().unwrap().set.len() == boxes.len() { + println!("\n\nsol2: {}", pair.b1.x * pair.b2.x); + + return Ok(()); + } + println!(" b1"); + } else if b2c.is_some() { + let b2c = *b2c.unwrap(); + circuits[b2c].as_mut().unwrap().set.insert(pair.b1); + box_to_circuit.insert(pair.b1, b2c); + if circuits[b2c].as_ref().unwrap().set.len() == boxes.len() { + println!("\n\nsol2: {}", pair.b1.x * pair.b2.x); + + return Ok(()); + } + println!(" b2"); + } else { + let mut set = HashSet::new(); + set.insert(pair.b1); + set.insert(pair.b2); + circuits.push(Some(Circuit { set })); + box_to_circuit.insert(pair.b1, circuits.len() - 1); + box_to_circuit.insert(pair.b2, circuits.len() - 1); + println!(" new"); + } + } + + panic!("Sould not reach here"); +} diff --git a/src/day8/test.txt b/src/day8/test.txt new file mode 100644 index 0000000..e98a3b6 --- /dev/null +++ b/src/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