From f4183f26c032f3b79fa975b8fe1eb453661fc93c Mon Sep 17 00:00:00 2001 From: Devon Sawatsky Date: Mon, 8 Dec 2025 04:59:29 +0000 Subject: [PATCH] day8 part1 --- input/day8.test.txt | 20 + input/day8.txt | 1000 +++++++++++++++++++++++++++++++++++++++++++ src/day8.rs | 33 ++ src/lib.rs | 16 + src/spatial.rs | 22 + 5 files changed, 1091 insertions(+) create mode 100644 input/day8.test.txt create mode 100644 input/day8.txt create mode 100644 src/day8.rs diff --git a/input/day8.test.txt b/input/day8.test.txt new file mode 100644 index 0000000..20c6fd2 --- /dev/null +++ b/input/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 \ No newline at end of file diff --git a/input/day8.txt b/input/day8.txt new file mode 100644 index 0000000..28720c5 --- /dev/null +++ b/input/day8.txt @@ -0,0 +1,1000 @@ +19811,63901,80424 +56472,26644,32079 +77528,24129,29189 +53533,94958,85776 +93168,69326,27460 +25374,91449,95696 +96129,76282,72430 +80100,69230,78980 +63046,75012,45443 +48923,26202,95974 +18380,35864,5685 +10377,91999,83841 +18215,31413,43273 +69608,47324,31546 +74388,93328,70320 +7488,75918,69838 +3402,16390,43595 +61505,84673,4512 +84158,58795,66886 +85461,84839,45157 +55232,17224,51398 +35761,77776,24081 +81650,1370,1703 +11297,95673,39240 +25368,3794,96381 +31893,59581,83142 +61121,5160,19889 +4829,38017,11633 +51020,6358,31830 +90869,94064,99116 +50255,99219,43018 +7581,50550,29351 +59667,39449,80754 +11289,71781,52195 +72898,75800,49342 +14519,85836,78944 +75078,35968,51444 +9620,19765,71878 +84052,94801,28054 +72618,23498,58857 +78616,81248,96697 +2079,22191,39236 +71386,21281,24930 +9154,3724,73394 +61950,91606,34692 +66507,60009,2528 +99431,76247,79160 +89693,80180,16981 +34456,33695,53921 +24601,81277,79889 +77036,22134,45737 +42069,73464,71541 +56434,65127,82549 +59647,90286,18929 +5834,6709,55511 +56513,16545,20517 +4325,20798,55038 +83963,59491,40901 +91600,60483,98350 +64239,54023,19748 +18934,17655,70517 +29421,1715,50292 +93589,70619,21682 +54809,42502,22370 +85716,90285,21129 +19659,4752,89967 +45183,31182,26351 +56478,3706,75767 +76841,54463,10838 +14107,1129,60689 +96635,17276,59040 +30691,82119,42177 +88318,72067,70875 +91904,83010,61959 +25074,25841,51517 +21112,30406,18775 +8324,21828,65391 +73077,47615,1276 +94230,24986,33586 +15618,87608,81102 +92050,71735,26685 +89228,79626,30622 +66366,17759,51633 +85322,74490,57964 +17237,73526,43846 +5834,12316,14166 +9278,45893,96833 +33627,28165,83788 +86926,22237,80297 +31748,12903,88689 +63755,79782,86198 +38772,53598,12888 +2169,26610,16688 +2340,75351,19483 +51160,87750,31219 +90519,25360,20683 +78041,43468,6310 +93889,76633,67582 +90185,80468,69643 +82915,20204,41153 +38677,32451,14620 +76581,22670,99977 +38232,44501,58232 +25188,64312,83600 +28522,70590,64923 +79024,25865,90440 +81150,26724,21842 +8567,1245,50914 +81807,29752,74627 +61158,76395,64935 +19158,2452,6107 +22118,14241,16382 +24726,7286,84878 +46530,89315,49229 +63489,53184,77743 +41806,4473,56796 +55834,21351,28613 +76005,84959,26713 +93292,23154,84373 +37327,43296,40876 +81256,39939,64161 +19247,33012,27994 +74387,107,11889 +6245,88353,18422 +29900,26067,13036 +28913,13816,59311 +8074,37782,34953 +77584,10697,86255 +58554,12913,69509 +86099,12682,60061 +30083,72465,29376 +41934,1462,40706 +81846,751,7414 +59573,14000,28774 +86161,80881,23697 +94742,64212,86778 +42849,13589,56059 +60876,37327,7101 +64427,33129,92490 +97873,3249,14341 +28014,5851,85764 +2221,4054,90020 +6589,43790,2416 +13351,62945,79616 +37219,48800,65731 +63672,23104,82403 +64932,52688,91813 +76107,80904,33639 +44158,473,88251 +14708,81063,33847 +32692,39861,9391 +447,84114,10262 +33278,11518,96968 +56501,45291,9608 +88389,17476,31993 +50797,76742,46926 +21861,99835,90288 +3986,78555,41383 +44875,44797,86262 +11526,58218,38272 +75687,38352,69458 +88867,96578,11311 +39355,85692,85713 +15477,37111,72142 +95935,9393,63283 +69451,12959,61205 +98520,5974,70909 +6144,9418,30730 +96258,44445,35265 +92764,32300,59606 +42983,79338,74537 +25798,87291,47116 +41304,65610,84929 +86509,6137,66583 +86384,4591,79527 +20475,57453,34821 +80819,92747,12513 +9682,27456,92563 +38688,6746,62361 +3682,27195,80177 +72692,63496,67642 +62961,39138,76992 +40826,3771,16666 +12359,63605,34287 +40332,9457,39359 +34596,86486,7009 +63022,27023,96152 +51637,29842,22317 +87240,35421,31220 +20435,81925,39081 +64008,24442,49259 +56973,76393,17297 +87911,96543,64428 +23762,34754,78689 +78907,93621,99438 +93331,8732,97082 +68707,64659,50231 +82112,55191,57667 +23944,58917,50002 +68230,52727,15360 +75459,15864,5228 +34303,80546,35999 +44028,49442,16674 +8150,1119,98674 +22471,70273,57876 +86341,13749,47137 +832,59477,56492 +52365,97091,14470 +17545,27204,18271 +44182,68155,22931 +93690,90582,21197 +63501,92103,2420 +32868,87558,86243 +93528,96090,37782 +11575,26144,5553 +65882,75154,90491 +25960,54961,33702 +41043,46190,30747 +42871,69787,35877 +69061,79083,24878 +28661,90268,67864 +10779,61821,20133 +80729,63970,87035 +50138,18797,81089 +96077,34756,13203 +67768,50801,56084 +88405,74067,73882 +81910,47760,23240 +8535,57152,15402 +25317,37540,43266 +63320,85760,18110 +49312,47097,76115 +25651,52362,92747 +71254,50808,55842 +15473,83688,87161 +80693,99299,35536 +16511,76084,35052 +13533,12597,358 +59031,1091,67689 +87348,82217,87376 +8157,32720,71537 +19009,21003,16117 +82501,1887,12274 +459,33618,34333 +67036,4148,14892 +77817,68790,36382 +88282,56775,61100 +82705,40354,47087 +26065,66579,4970 +25567,994,33845 +75522,36137,27159 +77746,55935,97178 +1234,61523,61927 +57928,92637,98933 +28480,77661,67505 +17306,26135,82053 +74596,76509,53005 +67607,59955,25511 +86805,12710,78195 +97785,32852,86994 +9415,30864,40984 +67661,5280,23530 +33460,99673,16779 +48100,53787,17786 +73587,22520,25582 +62755,22493,27384 +83205,16489,4617 +62309,80142,84926 +80462,62062,94863 +20967,53365,99542 +80746,89465,8697 +55951,60358,83213 +73994,30449,53979 +42722,17591,36224 +87190,67653,76864 +7538,17296,26862 +36019,44938,98314 +34425,34460,2079 +9664,6894,65255 +67328,65001,12579 +36386,93580,1066 +66274,91220,58226 +97935,75837,76921 +97292,73543,62881 +76688,9307,18417 +25080,82552,98645 +28701,87652,36807 +59340,63999,76326 +51435,49596,4379 +91935,73656,87221 +31099,50758,81931 +95994,76695,86365 +8559,43271,20825 +64194,13170,47376 +82719,4053,4458 +68153,33715,17440 +86979,70992,23758 +63929,14943,20735 +54059,96047,67620 +90430,99558,66276 +31334,86285,75149 +98315,23414,95838 +79699,1796,24744 +64662,43057,23674 +82642,27541,40005 +58008,96149,44469 +38429,70163,25068 +77752,79050,62344 +54237,53644,73334 +9322,59901,66138 +82643,9968,38143 +39518,53305,29525 +71315,84108,22607 +86216,90227,72144 +43523,64759,83295 +70047,60319,8440 +62587,83506,82453 +54745,7148,73053 +75112,80138,10295 +52206,6301,14514 +86949,86347,53019 +71450,84192,18337 +83241,26758,50971 +83111,52273,14367 +86555,66442,7734 +8673,10344,67356 +8575,28519,94069 +45843,72014,46504 +20214,60294,55324 +73897,84286,7063 +14497,35646,33159 +78742,11879,60615 +24094,20685,42857 +11884,29808,26234 +36322,32587,91732 +10712,43415,10274 +7426,9808,48324 +81974,7483,78316 +17783,42120,43640 +15854,2400,44314 +42417,13879,32784 +37677,29537,26927 +32160,70397,59430 +95276,30298,62435 +84031,38093,92161 +70339,16302,48638 +19925,78230,19721 +36181,95485,77688 +26613,4084,69309 +86928,29344,38194 +82438,86979,31105 +13508,14424,64061 +1544,46188,58559 +76868,79413,9985 +35308,62538,54772 +65083,8589,42759 +60122,79164,81502 +42454,99015,47153 +27150,27799,45663 +81832,85798,61989 +96410,72345,6569 +59176,37863,13799 +74992,46560,93891 +47147,87623,67859 +9760,14366,71917 +38608,43679,6314 +9957,94204,39848 +37872,84341,18797 +10728,31641,95460 +59328,25972,84127 +93198,80907,90161 +59793,60153,12700 +47878,43038,85124 +37329,22291,37297 +77925,50089,19756 +46332,22443,29813 +97970,94929,12935 +32832,37115,34996 +7499,21023,92879 +56041,96573,29323 +75934,44899,77626 +46438,55682,63742 +49590,42688,46298 +85039,62072,13265 +2152,10437,40310 +84812,37534,32959 +42831,43299,34940 +79833,25833,6189 +17425,77,87620 +70035,17028,66357 +44699,93506,64133 +26071,65119,16840 +75801,19788,16680 +2464,16223,45866 +10113,2621,4243 +73995,58225,1984 +23547,35431,79325 +44188,55903,57790 +40521,67812,69740 +83261,27507,50374 +1145,53212,1217 +78452,15661,53331 +37714,32003,23524 +61960,70572,34404 +82392,2203,59760 +83885,87292,64240 +88124,42935,52255 +88136,46453,30331 +99617,5929,66908 +84854,16773,63241 +28500,63982,24453 +29764,8869,7270 +41654,71044,35856 +49340,78914,74173 +87296,66814,50584 +81358,55828,6930 +57557,99385,89952 +81573,52002,81896 +16354,41837,85135 +64625,60014,36716 +45985,11829,96695 +31230,94212,72499 +81038,28808,52029 +66299,97135,39447 +60436,17058,26867 +26821,92712,22921 +44305,86415,5331 +20582,37708,74086 +53105,41334,69427 +55361,94123,20787 +89609,54698,11286 +65174,72996,89210 +14462,74925,96093 +369,1423,12102 +81348,91522,20747 +80184,17963,19284 +27628,72040,8065 +17476,68412,70807 +60083,87171,94145 +46388,56309,13161 +42631,41522,2442 +52667,55436,51631 +36975,37301,6713 +64149,46822,73948 +18327,79704,31893 +78555,56935,9680 +60191,21720,47622 +54364,1402,63657 +72531,61636,61182 +54775,36458,47966 +21183,36917,92307 +8199,27034,98741 +3155,26251,34581 +79986,32596,30351 +94937,35979,67438 +70085,23486,32284 +85225,61234,93929 +45241,40635,82602 +33396,67124,98715 +77909,71316,13352 +36830,27736,36406 +76321,51084,895 +71062,77989,74926 +61924,79668,16949 +68462,19140,80662 +50596,95202,14557 +46215,77912,30128 +28497,87737,11515 +58169,44744,50107 +31137,27619,70290 +77881,65634,28401 +52061,98481,42430 +13293,83245,61313 +96139,71515,47167 +79353,30430,81936 +36813,37397,56422 +8570,94518,75911 +78594,78038,96861 +93356,95735,78898 +23903,65596,24789 +10807,85711,86308 +22923,59760,70072 +35343,75779,89252 +37668,76222,74313 +79178,40537,33196 +19844,60421,18493 +61456,66856,36942 +30357,80858,39689 +45301,72648,18283 +85606,17987,99814 +91773,60010,18981 +85713,61096,75890 +42256,5887,74972 +99272,74302,994 +20979,84769,45589 +31699,56218,33676 +41559,9163,86890 +23892,27334,89475 +14822,22776,10715 +37667,65920,6351 +32112,81968,17075 +90843,17172,2673 +96916,43900,55505 +94957,25352,5827 +7289,50474,95225 +77665,76450,59127 +75742,48626,95646 +7591,15387,55440 +22733,63473,46411 +19433,62499,79181 +93309,61722,70184 +24379,83969,84973 +16874,83921,69806 +52840,61098,14578 +15737,30790,68500 +90187,3322,48832 +2830,34450,52062 +46035,9997,23146 +51242,86174,73660 +64461,74769,34791 +9710,45256,36435 +41047,19773,72003 +15294,17535,55142 +73757,18431,91478 +74522,58511,49255 +59123,67071,87838 +57192,98568,69179 +23435,72939,35565 +25258,95498,91417 +51888,32939,90519 +81589,30845,8108 +75496,53112,42267 +99240,88793,39410 +37175,50634,83343 +5426,96323,45274 +5771,16845,17342 +67815,11937,21756 +31448,92069,33611 +71929,76152,73690 +27221,20673,67371 +83662,10295,69459 +79530,50485,57181 +33456,61011,45570 +17392,64200,54390 +86609,98501,8821 +15009,95179,33540 +19379,52923,47142 +39624,58537,20536 +44222,69386,79271 +61775,97795,50366 +16739,36539,75572 +71437,56783,27916 +95672,47904,20468 +49879,2124,70882 +75390,93535,98190 +64921,24227,69903 +78184,72258,81657 +28708,44193,99168 +452,79372,30788 +37556,59092,16594 +76882,42902,18506 +76781,53697,30647 +18629,22726,74081 +12963,69962,18766 +35016,31989,69764 +83196,60514,19101 +12077,96106,73134 +93278,47440,69028 +86532,89374,81139 +97986,26301,88467 +53983,62742,59081 +20375,35156,2600 +36730,80019,90622 +26781,57491,51462 +51607,3233,55344 +86527,60362,70018 +32612,63361,50738 +95878,57913,8932 +50567,83830,77679 +14610,13478,80070 +83756,88629,86663 +75713,48667,57674 +55820,90569,73614 +63376,31891,14912 +89521,60460,29381 +79863,38559,51035 +51468,91332,30691 +24637,31579,22339 +87532,83514,68636 +28952,32941,36059 +38303,64977,77598 +33647,14736,87999 +42735,4549,16941 +6566,27990,26298 +15820,36391,10265 +50379,38288,47656 +56743,1648,64257 +70197,96759,73037 +82134,16893,56994 +3389,95349,15379 +63765,94194,23204 +45841,28949,97461 +26217,48585,93864 +1266,91667,34045 +23078,88036,17024 +33499,39651,30563 +25554,18842,30273 +86546,83059,81037 +35753,19754,71205 +40311,75499,6921 +20317,6652,37344 +28182,42272,70728 +32903,5540,6860 +76036,67776,70592 +17783,60076,82378 +57975,7646,1752 +67874,34892,45471 +34346,70294,66266 +41414,77576,39882 +57801,17807,71798 +20349,20211,64823 +14860,70205,13593 +5070,73845,64482 +94131,91239,75691 +96784,30610,62319 +41809,28299,46550 +89409,81409,59341 +87820,75287,68617 +10649,4404,696 +11784,33700,59413 +73944,55344,42792 +55697,72654,157 +5016,69277,21926 +66508,99033,44917 +31425,72862,78962 +89179,85001,45188 +57726,64047,5739 +77496,64820,64560 +92417,19239,79246 +58700,71320,93844 +89859,80072,31222 +43318,75829,23661 +6017,23792,20575 +83362,55569,37877 +97083,45044,33220 +12065,73003,70043 +50518,5948,44557 +57309,83963,58344 +91788,95409,62983 +31292,58901,22534 +26532,43129,65580 +19182,1280,87351 +93970,6620,96527 +4658,25023,8400 +9077,15456,3646 +22554,9994,72248 +38789,20563,39619 +62867,19184,34319 +57598,82637,82994 +64212,91682,6492 +87608,66783,58765 +80198,9816,87378 +20054,26469,74941 +82246,75648,160 +4074,48052,73658 +51106,9044,13290 +74926,26678,18703 +4993,53210,50968 +82986,47086,48291 +32100,28586,9809 +91129,30486,25870 +22497,13350,95359 +14009,65738,21491 +78501,71773,72361 +41810,66661,25736 +47075,94382,56069 +50279,40907,51427 +39977,50320,10036 +34198,68577,63662 +84518,97980,21557 +56207,44939,96264 +60108,61364,92726 +36300,77356,81287 +30075,80166,75056 +89056,79654,81981 +68136,59755,53159 +14842,66543,97137 +65814,44988,42054 +88989,25007,77870 +43726,16632,42865 +86466,43695,5595 +21836,49422,40865 +49227,89854,70959 +15797,73857,57588 +29875,59816,72598 +88454,47592,15337 +89545,5687,69400 +84613,32176,66828 +95869,39150,67340 +60875,67660,91914 +76146,87023,14388 +55959,11135,56069 +2249,84266,91780 +79180,14086,71440 +63001,26614,35620 +54539,18037,17309 +1558,10867,88872 +44899,31996,49311 +41929,26066,2537 +89941,86765,31971 +88092,36628,34299 +5682,80787,58527 +96888,89602,44511 +99228,44384,63071 +53497,44337,52002 +86233,98233,68229 +51975,41192,90639 +93997,31147,73228 +80920,84194,70981 +45797,12863,7480 +70167,4134,2559 +22641,8865,79038 +70110,88521,38429 +78889,85491,49229 +12666,2698,91505 +88461,12686,37429 +30000,76265,74240 +70372,45926,3826 +66297,82641,59310 +76580,24861,87559 +42284,99010,44791 +21376,89287,73468 +22462,81305,28663 +64619,17244,73971 +56073,66105,23581 +87024,20292,89228 +77032,17755,13489 +68668,36461,89034 +98003,81337,38405 +71767,83532,68907 +93686,5125,61060 +85537,42959,43046 +67957,80517,32053 +17729,38600,81536 +70491,20300,99081 +99246,53897,33878 +39524,93580,17510 +6972,3673,55131 +15805,31783,86457 +34109,98739,93119 +70193,55571,8171 +5887,67593,89966 +11019,35736,97762 +32879,57994,16752 +61376,75055,48899 +30930,29484,84253 +64877,80684,31511 +52705,13471,72054 +51243,99505,19217 +82483,82815,25259 +77931,32937,94215 +48860,133,35086 +14640,73229,73489 +75961,39570,20897 +27338,15796,7896 +1895,37430,61052 +87232,58934,45914 +21524,23498,17095 +43125,55902,93575 +80969,26254,93398 +59632,17165,45845 +46762,76154,73936 +13867,41935,88868 +65682,63921,64317 +62144,60101,57769 +17838,91167,73333 +98363,59355,5771 +82492,12654,1751 +202,15862,41316 +61397,47059,45142 +33400,93137,88393 +96214,44075,39775 +42896,60476,19098 +29291,1825,33872 +19562,57186,86051 +11559,58307,51590 +7188,94277,37622 +1444,73415,9850 +62875,31855,38456 +57024,64198,92533 +44396,46599,57851 +24499,16974,49274 +79176,34449,47985 +84121,92757,15373 +32844,64343,44475 +44277,12758,96990 +40415,83995,17773 +44477,83897,44587 +87874,52552,53469 +82280,9909,31546 +79356,49464,95175 +15218,55924,59929 +9819,79704,84250 +9338,82517,69606 +57233,34324,53315 +80048,4077,5287 +96745,83896,89879 +11087,81720,68852 +96849,99593,1034 +76625,87880,10339 +72990,78200,1409 +56058,45796,7719 +43278,43316,8210 +64985,87647,434 +14108,87099,77947 +66772,3555,10295 +87400,73824,92134 +73474,88228,76642 +13497,54640,36351 +4043,12369,46995 +95132,1331,2069 +93277,15101,98818 +12397,61103,38512 +10212,13631,45995 +86062,41166,8039 +58661,66625,52204 +24474,17045,55761 +85101,42605,76653 +36653,30252,27214 +841,29789,894 +18750,79154,42505 +43962,10656,30900 +3813,76470,36439 +93856,66682,99229 +87423,57120,32218 +29290,15766,91578 +96475,70508,34619 +2200,29714,33937 +79075,40479,53800 +41299,16400,91855 +90648,24661,3360 +87089,62732,41525 +51608,75471,55763 +89216,30888,64851 +19103,46634,74429 +43723,7451,32477 +2595,11567,9371 +25642,36860,66095 +49086,82439,93386 +65515,88795,66470 +64903,57499,26666 +68286,73158,50267 +26246,57150,15395 +98948,59998,34092 +43920,73144,2976 +68935,46651,55010 +75188,19536,71437 +94428,34063,92570 +52881,15010,53734 +20995,96960,25093 +39618,33148,10332 +78252,35233,47084 +20468,42163,5477 +86128,77267,50139 +75143,18182,2299 +11097,63366,32588 +18921,58748,60703 +90414,54382,5076 +23796,92996,16943 +84729,17895,81177 +69686,2205,76228 +95769,14384,21319 +252,35451,69089 +23340,30613,49295 +41858,45789,36354 +33,28577,45663 +11889,54351,68305 +88873,26983,66233 +86471,90079,34873 +57541,20638,34455 +25244,695,20334 +34134,80714,25794 +20569,68280,3322 +8667,26273,46395 +68133,17007,94043 +21487,8103,64437 +29560,73097,62716 +32523,18955,22396 +34558,99550,4781 +33343,95788,63429 +90191,78358,541 +61035,86186,95253 +70726,84551,97581 +58340,89588,39079 +4479,12219,19026 +7531,31924,36487 +95754,31075,77517 +57045,87096,92359 +10026,83776,89447 +27272,86804,11705 +92211,93388,60345 +73961,87102,53998 +83075,34175,34496 +12549,71811,20990 +7436,85903,70014 +34450,70,97461 +25276,8824,97522 +91088,33617,74285 +8693,8968,62657 +11684,87690,68977 +78863,53669,21973 +74897,91362,54245 +61668,2006,28255 +43804,54180,4244 +68033,63538,37548 +24848,40148,99039 +39485,77454,77755 +12037,46195,47449 +94249,38595,57871 +56835,62808,15824 +36748,44322,97234 +74449,59448,27874 +92769,5328,29031 +71952,5787,60374 +51500,65137,57036 +75126,38563,58017 +91605,83071,85330 +95142,74242,61389 +48538,81258,20560 +42894,72720,815 +35268,91261,72793 +46686,55700,41021 +87659,28342,53570 +75844,33667,57794 +96291,93113,88151 +36075,79308,38704 +29725,13612,82191 +75856,51,95679 +76888,88151,37029 +86875,93273,75313 +91069,8123,51210 +38764,51477,57409 +16757,76747,69360 +67060,40243,38330 +9124,19472,61055 +25475,39383,80548 +68662,45737,50093 +10605,20544,58159 +89687,31428,85417 +34706,4824,26547 +31692,11892,72989 +35017,72971,66558 +52376,36785,54438 +77199,36841,78787 +63226,40307,19604 +27918,52813,89106 +543,12459,97260 +22721,92653,77226 +22047,32420,77473 +50107,23096,1266 +89689,10137,1445 +99626,5426,67539 +45135,19027,72283 +91663,57343,38515 +16231,63012,98967 +24384,74762,3138 +75068,1121,32120 +92923,61715,17282 +31189,44207,1389 +20868,89128,58615 +82536,78750,7953 +53165,92905,5378 +6454,87128,91320 +72058,92250,16673 +62458,21836,79821 +81067,1638,21535 +56324,80191,58416 +5039,17656,1501 +49871,45912,84662 +54569,26670,96845 +57648,52234,41510 +34468,46762,63901 +73184,95006,98350 +53794,7658,6271 +21564,95139,66193 +49201,55477,31114 +10108,85551,31370 +90862,91400,92611 +5826,90177,71681 +59477,22810,73219 +1031,38454,13095 +25784,50057,58569 +40353,99246,78101 +17937,14538,73868 +25614,71008,36169 +33379,9819,60131 +5475,25938,4283 +40321,63581,53244 +93504,49061,94176 +36875,39683,99617 diff --git a/src/day8.rs b/src/day8.rs new file mode 100644 index 0000000..98ce26a --- /dev/null +++ b/src/day8.rs @@ -0,0 +1,33 @@ +use itertools::Itertools; + +use crate::spatial::Point3D; + +pub fn day8_part1(input: &str) -> String { + let boxes = parse(input); + let mut pairs = boxes + .iter() + .combinations(2) + .map(|pair| (pair[0], pair[1])) + .map(|(left, right)| (left.euclidean_distance(right), left, right)) + .collect_vec(); + pairs.sort_by(|(ld, _, _), (rd, _, _)| ld.partial_cmp(rd).unwrap()); + pairs.truncate(1000); + + pairs.len().to_string() +} +pub fn day8_part2(input: &str) -> String { + todo!() +} + +fn parse(input: &str) -> Vec { + input + .lines() + .map(|line| { + line.split(',') + .map(|coord| coord.parse::().unwrap()) + .collect_tuple() + .unwrap() + }) + .map(|(x, y, z)| Point3D { x, y, z }) + .collect() +} diff --git a/src/lib.rs b/src/lib.rs index 78f0a97..dfb8769 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -120,12 +120,28 @@ pub mod day4; pub mod day5; pub mod day6; pub mod day7; +pub mod day8; mod spatial; #[cfg(test)] mod tests { use super::*; + #[test] + fn day8_part1_test() { + // let test_result = day8::day8_part1(include_str!("../input/day8.test.txt")); + // assert_eq!(test_result, "40"); + let result = day8::day8_part1(include_str!("../input/day8.txt")); + assert_eq!(result, "1490"); + } + // #[test] + // fn day8_part2_test() { + // let test_result = day8::day8_part2(include_str!("../input/day8.test.txt")); + // assert_eq!(test_result, "40"); + // // let result = day8::day8_part2(include_str!("../input/day8.txt")); + // // assert_eq!(result, "3806264447357"); + // } + #[test] fn day7_part1_test() { let test_result = day7::day7_part1(include_str!("../input/day7.test.txt")); diff --git a/src/spatial.rs b/src/spatial.rs index e841cc4..2d0b07c 100644 --- a/src/spatial.rs +++ b/src/spatial.rs @@ -1,3 +1,5 @@ +use std::collections::BTreeSet; + use itertools::Itertools; #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] @@ -6,6 +8,26 @@ pub struct Point { pub col: usize, } +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub struct Point3D { + pub x: usize, + pub y: usize, + pub z: usize, +} + +impl Point3D { + pub fn euclidean_distance(&self, other: &Self) -> f64 { + (((self.x as isize - other.x as isize).abs().pow(2) + + (self.y as isize - other.y as isize).abs().pow(2) + + (self.z as isize - other.z as isize).abs().pow(2)) as f64) + .sqrt() + } +} + +fn connected_components(pairs: &[(Point3D, Point3D)]) -> BTreeSet> { + todo!() +} + pub fn all_coords(width: usize, height: usize) -> impl Iterator { (0..height) .cartesian_product(0..width) -- 2.51.2