From 2167efbb3a828ea41f099d70f4dc612a62859498 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Sun, 22 Dec 2024 21:06:40 -0500 Subject: [PATCH] Day twenty-two --- 22/input | 2332 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 22/main.rb | 53 ++ 2 files changed, 2385 insertions(+) create mode 100644 22/input create mode 100755 22/main.rb diff --git a/22/input b/22/input new file mode 100644 index 0000000..335db2e --- /dev/null +++ b/22/input @@ -0,0 +1,2332 @@ +8747564 +185613 +15104438 +9384889 +1767035 +4936291 +1639555 +796125 +3343077 +7201871 +9186458 +13959873 +9601741 +4299593 +9617092 +3472873 +11201355 +2435545 +2755460 +16772405 +11073386 +9107634 +6241367 +11066033 +7016858 +10801904 +7939302 +6911393 +6391060 +3620532 +546950 +15900526 +3660881 +3123579 +6300612 +16634398 +6009608 +14045763 +11089138 +2659465 +15772179 +14790447 +9617677 +5609980 +14551378 +8121060 +9439080 +5758077 +8476422 +9900051 +6926818 +14166179 +11215932 +12990958 +9034871 +3388594 +13785795 +3237672 +13300034 +6805638 +5523878 +9614598 +530677 +16221658 +10209653 +14500292 +14882585 +10765936 +1726640 +8506116 +14946356 +3484897 +10336836 +290673 +8270383 +5901048 +5381012 +12682222 +11370537 +11959029 +7093419 +8715719 +12275185 +2803039 +2728700 +9303601 +340026 +5353652 +4988368 +12763446 +1798290 +10612918 +3236285 +3740873 +14109421 +10792465 +10765946 +15203605 +10449276 +7522691 +8863573 +1287040 +742973 +4830714 +10056132 +1253111 +5475218 +4163524 +9291516 +2168817 +2091463 +1112640 +13591593 +7574187 +2490943 +16014986 +1439919 +5494649 +10907031 +502243 +1942022 +14317007 +12424135 +1380367 +10293515 +302028 +2181059 +1700150 +13626405 +14508903 +11716319 +10383990 +13163608 +6869322 +2943639 +15286522 +9994360 +8499554 +1860866 +12320539 +7133338 +2784205 +405655 +8865524 +8340640 +7687034 +8365696 +3306418 +11045387 +8034327 +7102202 +2115586 +6395728 +13097049 +11647174 +15182334 +7206104 +13699465 +5702395 +12779856 +5541173 +9766770 +3562202 +12392570 +4861561 +322905 +15968671 +9100194 +13817207 +4310905 +7360383 +11135924 +14772354 +7185891 +14626109 +2691408 +4221304 +13874914 +1202189 +2446753 +10335823 +14686806 +9699196 +1600755 +2786010 +6185303 +12996201 +4820433 +138844 +4620370 +10252809 +1408094 +2103941 +9358998 +8636453 +15993511 +16402351 +3116725 +4557757 +7895259 +3828397 +7702679 +7106618 +8108423 +15745833 +2765374 +16151404 +7125842 +7574916 +13209710 +11532383 +813356 +10194978 +4507176 +14542117 +10836040 +14657969 +5356245 +7874169 +2438913 +15502110 +814201 +14057997 +7828828 +4572453 +10723014 +5576218 +12623294 +1045767 +4352808 +3151523 +10817344 +2625132 +1942037 +9062803 +15581470 +3223745 +12217541 +4140703 +4603068 +6267928 +12763510 +15374733 +10338296 +5583983 +470228 +6388002 +7045322 +7174490 +12874453 +15562153 +6763389 +8256335 +1274241 +8166283 +1012567 +4611702 +8352372 +1784874 +13602813 +10126463 +8732128 +12983436 +14478765 +1649429 +2321590 +15249938 +7330019 +6429329 +4907361 +3149013 +3079459 +9840681 +11618308 +12507332 +14813004 +13942590 +13300383 +7667207 +4924425 +10251892 +8541113 +11043222 +2793464 +8529447 +5070150 +10269742 +11986542 +11990599 +6804098 +2757470 +7488231 +11446499 +3175460 +4835697 +14501319 +14650536 +6174743 +8124772 +11762787 +9965141 +3633708 +2045774 +12428281 +248167 +15336391 +5449413 +14273754 +8576660 +7995004 +4023301 +14650340 +4553036 +6251185 +5307581 +5749299 +15486014 +6693164 +10677883 +13636331 +13678320 +13743654 +2799057 +2018064 +6323109 +237565 +2489930 +13626509 +14689386 +16563222 +10369880 +493990 +7413659 +12252062 +9001288 +4513437 +1269594 +1337595 +3997284 +8329612 +5047114 +1241011 +4647721 +10619418 +11460736 +5276709 +3477628 +4426057 +12986348 +16175433 +5228436 +4747843 +5832559 +4704476 +5458986 +9164267 +4168895 +176351 +5503561 +11423968 +12700281 +14790721 +10019033 +13407344 +14427931 +5525173 +14464184 +15080546 +8571516 +9967959 +13699327 +9986640 +9252847 +15063440 +12686233 +2468307 +12493209 +11060771 +15537421 +12033022 +15481760 +12429712 +6935282 +6982186 +7125890 +1054289 +15419678 +14902677 +12742795 +13169240 +9327127 +567311 +2948461 +6588737 +8933101 +12504980 +16343061 +6170920 +3622152 +12927134 +5147480 +3367671 +16593149 +15060708 +1992096 +11552017 +13917134 +300843 +6115238 +676042 +11466623 +16440583 +2653763 +4593922 +11404320 +16398748 +11794887 +3152971 +10162918 +8610464 +2456479 +184511 +14562571 +11292776 +16752627 +482373 +3195821 +5540925 +8446893 +7738249 +10022868 +10767031 +3872675 +16491849 +2466376 +2086563 +1617636 +16742541 +8670415 +15613119 +10514390 +7732406 +12209589 +4619609 +812429 +9949907 +7571064 +1080298 +7258067 +3424924 +16259773 +13829087 +2874539 +7168985 +393326 +12609981 +9811048 +9889904 +3629382 +14962493 +4063816 +1326460 +2278307 +9958442 +8973659 +9346042 +9025739 +4338508 +13355145 +9176419 +12080242 +6362940 +4019227 +2133868 +8525922 +3011698 +3100260 +6677916 +8790751 +3121603 +14687315 +4438279 +15622748 +12192820 +6808660 +1490826 +3678384 +11510773 +7607924 +4048452 +4876016 +359509 +2128615 +14594008 +11682982 +3818653 +4613088 +11374560 +12836078 +12593622 +6776963 +14261158 +14347667 +7552742 +11236285 +5807557 +15676165 +8984234 +3162938 +2939012 +12727169 +3735622 +11040546 +375601 +6319993 +1891932 +6605583 +1575550 +12402855 +8930197 +1192618 +15842575 +11245548 +9082754 +5804161 +4918495 +9684850 +14556135 +12204820 +355817 +12275217 +16591157 +12985025 +13247434 +9213522 +6203174 +10306046 +3282013 +5927393 +4800888 +794725 +14208620 +14886283 +9246214 +7217004 +13449865 +9874749 +15886008 +4490495 +8674010 +14730956 +3890255 +1162272 +15351381 +11128962 +14031947 +589154 +14538334 +9623997 +5681695 +8382577 +6865923 +11197191 +10403627 +257038 +8068684 +15733837 +1840153 +2523824 +5006844 +10186239 +12492230 +4527743 +7122716 +887017 +16721437 +7673796 +10481209 +16726980 +8313628 +5288911 +15423713 +12230772 +4211083 +8478732 +6883133 +8177915 +12905229 +16761992 +13384161 +1554715 +11144612 +11575850 +3187724 +11503765 +3334929 +2570991 +674146 +1804001 +11126295 +2956501 +5398533 +14221095 +14841910 +6195901 +1267310 +9022981 +739638 +9642052 +7588108 +11349402 +282776 +16496273 +16295846 +5593871 +2174197 +10319714 +8251389 +1050267 +14371907 +1499385 +3891933 +11458485 +6778670 +12593223 +1141946 +6301161 +11376292 +9946743 +11701414 +739168 +8313666 +10316600 +10396892 +7365596 +503664 +2381137 +4311421 +5099900 +12842134 +327335 +5100896 +2110258 +10626888 +14079893 +11604916 +11111266 +6691592 +9287277 +3846471 +3275426 +2722264 +8377127 +13259482 +10186509 +15119317 +7228350 +948362 +15257374 +4250831 +11789099 +13642432 +13080401 +9594641 +14355212 +9686106 +8918870 +8403059 +4480448 +5206475 +10671582 +2488109 +10355813 +10712845 +14267497 +12995613 +15505483 +13404093 +16351942 +7134619 +11065965 +12994484 +11685700 +5840494 +13438021 +14761891 +13377716 +2469152 +6042511 +15839917 +4021680 +16123515 +1801692 +3225878 +1580202 +10043357 +15804550 +1780275 +13981060 +13285592 +12424516 +482932 +10259309 +388253 +15389392 +9376596 +4478971 +10834090 +1973017 +11650884 +16536157 +10314860 +12145971 +15588656 +14967461 +8485547 +15349672 +2848622 +14460166 +9334545 +13000677 +14291438 +12306171 +12146009 +2733184 +4939123 +4336654 +14516845 +608633 +13711973 +216321 +10303270 +10309412 +12028755 +12092881 +6694473 +10509615 +4792010 +4782339 +5527791 +14461756 +8843080 +6757463 +9124780 +12580540 +9654372 +716760 +2187400 +11821599 +13945608 +8751082 +6526000 +14576427 +4585894 +16214201 +1897645 +2755855 +14012855 +8184071 +4377471 +9934323 +7123875 +3866390 +7332123 +8910607 +4795957 +4358109 +8522338 +16001243 +7639364 +4983416 +15851303 +15753890 +14925045 +4961064 +7684235 +12162254 +9417255 +2614745 +13620378 +10420050 +1408519 +455564 +1275800 +4294958 +3702946 +15876986 +8538138 +11553378 +3714434 +6816833 +14821209 +14655192 +12009409 +6999472 +16574453 +10233213 +12388864 +15027524 +1960174 +6212442 +12173250 +14575782 +7228819 +9498053 +10787402 +14124742 +11439046 +14987409 +8843494 +12938377 +3253599 +15519007 +5749996 +887062 +2188544 +1098805 +15375889 +7152421 +1871985 +11394829 +5273054 +2277322 +14858064 +2138751 +13687328 +10532706 +3830467 +2298373 +12765153 +612953 +10241755 +2860668 +2792543 +12884138 +5467715 +8482184 +5206216 +15196132 +7180848 +793138 +2206225 +1775530 +8816776 +16356591 +12556634 +9586546 +1162957 +3274783 +8993906 +12170608 +3401337 +11271739 +2421487 +8069452 +14421336 +675660 +840729 +1720669 +3516079 +9135038 +11818614 +4962761 +6528773 +8184439 +15555639 +12154353 +3780842 +10254099 +10437150 +15755569 +7895871 +4559478 +3416456 +1329115 +9227850 +1166108 +5803066 +3309568 +13900310 +2788222 +7549565 +10587739 +5475261 +12667527 +15092634 +12282439 +7421325 +16581712 +16482157 +7540590 +8242506 +4546457 +10243838 +13811800 +15964485 +2663935 +13271895 +8867250 +4343455 +5058992 +11372244 +12912270 +4304282 +13068893 +5857028 +13941140 +16689829 +5704773 +8486376 +7788887 +4214969 +1762997 +9970190 +12917426 +12489049 +11805407 +14378805 +8924751 +8758723 +8818657 +3767980 +9251320 +7495893 +14251197 +11821185 +12791454 +5814141 +15633515 +15292074 +14706793 +2954164 +7770789 +3166969 +11926097 +14520737 +3023036 +7565702 +1851940 +5772465 +4749487 +2380900 +10903549 +16746846 +6138128 +5848343 +1278083 +12702916 +13405530 +9999665 +5914441 +10513164 +9333816 +4307874 +9433585 +632468 +15214304 +14860543 +7530686 +4815009 +10770886 +7582688 +9044310 +8353658 +5617426 +5783756 +9001085 +7113213 +12516821 +10213572 +309929 +4078572 +4451740 +1574776 +8561957 +10368395 +4824037 +7663748 +12217757 +5526173 +14336022 +2325192 +1402788 +15445321 +14580234 +1508295 +10142433 +9158419 +6706858 +11773082 +14171178 +10613193 +10939638 +7622496 +4369397 +4647440 +13130698 +13836651 +13158397 +5513771 +4500731 +201873 +12785935 +3249030 +10951854 +5126888 +8514412 +16516522 +9266091 +8942896 +3724298 +9359222 +15419412 +7030437 +3338905 +6320308 +6109482 +16534181 +10371799 +13386869 +11724811 +5094080 +11973464 +9887030 +4616141 +9459759 +16590718 +14970927 +9597746 +6583164 +15634915 +15889158 +13292581 +3430987 +12891916 +14906282 +16744763 +3628699 +418193 +14865176 +11923227 +9848519 +14128269 +8378019 +3132948 +10889878 +721505 +9190766 +8683296 +15766091 +14508142 +4902594 +444057 +14987615 +16152451 +2957155 +8439085 +360926 +15114335 +8381686 +383262 +9740252 +15007396 +3194196 +16492947 +5664840 +11388699 +13521100 +13120431 +14701772 +355128 +753712 +5153863 +1999034 +5314334 +13045507 +9402738 +203570 +11383929 +9270534 +11119559 +4290992 +10157760 +13342255 +10373101 +3325446 +12927074 +7914000 +11220260 +7435385 +10837944 +7870903 +10691751 +1047625 +6488400 +6961747 +6719330 +13152065 +13498231 +7571702 +3709670 +5938734 +11663261 +3001945 +2247611 +4071720 +14471524 +9627082 +8122623 +3593608 +14881752 +10706443 +7887846 +14119209 +6901608 +15936363 +5434364 +5647642 +14799336 +2647371 +7493376 +16097900 +7399638 +8309697 +3446798 +824334 +10301651 +5644870 +5143852 +12134847 +8012570 +14272273 +10812296 +13241376 +10282584 +10496526 +2341268 +6697416 +6798131 +6786900 +6289889 +7678666 +11852075 +15525268 +3316178 +12096718 +11131517 +4474351 +14973816 +13235966 +11339776 +12854913 +12401013 +1737846 +7111859 +12283947 +12594836 +6272688 +14290734 +3926267 +8511398 +2029955 +13168820 +12778550 +16246117 +13433045 +12876309 +15625453 +7419040 +1431259 +3453191 +4480491 +5157995 +3641853 +1767700 +13309647 +3378181 +2174182 +11875468 +1615939 +11699237 +13130559 +6910022 +4783493 +16304306 +16333714 +13319020 +9033125 +772183 +10898587 +5545651 +1749088 +11130422 +10728184 +4505520 +716531 +11501263 +8914303 +3004751 +16422340 +16489336 +2245648 +10339456 +9989781 +6190845 +6553501 +3932263 +6572169 +3383738 +14079065 +2581142 +1579601 +2962236 +11305409 +3830212 +7180193 +3961473 +5413089 +4209603 +4693054 +15627310 +848331 +16139586 +3207433 +10282645 +458395 +16007971 +12542109 +15707643 +16408190 +6659344 +2389658 +5261213 +1283959 +5733086 +9546718 +3557084 +5833552 +13516384 +13566143 +13188493 +3360022 +13888521 +9992619 +10784195 +14033387 +5898929 +4683932 +13305953 +12880794 +2928791 +12288821 +3921797 +3069562 +8191365 +7035066 +3374694 +5462121 +6712022 +8177818 +3154008 +1410442 +9203114 +15554748 +16166547 +367208 +11729279 +3745450 +4779794 +4991889 +834789 +6917668 +11722258 +4049537 +15899331 +8118238 +15533803 +9056209 +650282 +10488268 +9101217 +16315635 +2622560 +9800899 +7517240 +10511819 +6084140 +3661564 +1800920 +10417480 +473655 +6464940 +15020014 +16359905 +5025139 +12097225 +835837 +10053746 +8134743 +15189241 +4633926 +9154390 +12125886 +12801972 +5620854 +9591264 +14543108 +16244405 +4748392 +4820835 +11901934 +10321694 +12595072 +320015 +4428462 +7796708 +494706 +9089656 +1425193 +3805087 +3255868 +10735224 +7843161 +5662014 +14198456 +1529455 +5124482 +15609025 +5965754 +7928903 +13406830 +10110649 +3845276 +1990086 +13941718 +12771898 +530711 +6508740 +793970 +14865038 +2253012 +2936215 +14517275 +2468389 +12758340 +9907176 +10274723 +1904680 +8283270 +14854523 +5285099 +7048012 +14050210 +13357818 +4705268 +15589553 +7561218 +6036991 +10946668 +4341259 +11763457 +14262949 +8039519 +8626318 +14329484 +3593180 +5501807 +6130654 +9932321 +2677114 +10753298 +14961310 +2669572 +12050327 +2689258 +8983330 +353883 +9141566 +12103023 +1561470 +1090251 +13175485 +6347162 +1949199 +13230203 +3030783 +9300569 +9990309 +11192259 +4992356 +12734205 +6852998 +13905787 +10376007 +8349902 +9088162 +9355716 +1243160 +7826535 +8125876 +9928748 +8582514 +5290819 +2721604 +2746728 +11593705 +3669098 +16486420 +16636019 +2801280 +2484171 +10186235 +2755962 +8005567 +9751637 +6015971 +16639021 +15538514 +16259189 +7181896 +16726010 +3595172 +4068086 +14877588 +7767394 +7663563 +16003818 +1192302 +10065664 +11058216 +4557677 +8934211 +14783701 +13184431 +10366910 +16715344 +4664422 +6881696 +11970622 +4673985 +8603542 +13232055 +14949753 +15043503 +7202441 +6449226 +15142509 +4043584 +16197043 +9950918 +12369609 +4340384 +406539 +3706919 +4277194 +4714020 +16410011 +9267363 +1418980 +9584262 +394214 +12526745 +9250625 +1636371 +15193948 +12642606 +10328715 +16274770 +16282294 +790917 +2188631 +4286150 +15159883 +3946616 +2609082 +11763815 +10429830 +13538583 +8824479 +9545124 +2477880 +14295969 +15821159 +6783962 +16482841 +7681763 +13807959 +8881856 +4194514 +5883902 +12599406 +9822055 +11637733 +13932156 +1123054 +4275004 +4019008 +354649 +2010630 +15499749 +6716605 +6856002 +12108207 +9745565 +10011563 +7984585 +12820431 +5260673 +16568182 +12249211 +11645523 +7902751 +12318646 +3658505 +14074095 +10764432 +402020 +1194627 +10754213 +13316760 +615574 +14033591 +1570615 +8004672 +2131723 +7301912 +3921416 +1087725 +14560474 +9858156 +1562322 +8470521 +8676331 +12232849 +4797451 +4482734 +8889219 +3264017 +393844 +12012980 +9661613 +3663129 +7820503 +5963235 +10033805 +1766509 +8434058 +14674205 +5907618 +6620314 +13516449 +4706446 +9882232 +15298365 +9292134 +9404611 +6452971 +4311441 +16597732 +10992122 +13252601 +2520549 +12327388 +10268194 +9666327 +15374439 +744878 +7394138 +16614508 +9339653 +3432793 +5451483 +16030892 +15725188 +12711066 +13293261 +10063138 +14880500 +7192550 +407266 +2120543 +15533002 +1513686 +9828676 +14198049 +4604545 +1586196 +950508 +13146477 +11650714 +3873499 +8661354 +4656255 +7847151 +12034130 +5726179 +6595799 +13573151 +5626397 +15587077 +5443562 +14383503 +7645858 +12526022 +15845374 +5685238 +4900457 +13356015 +16577147 +6062825 +8948787 +9720215 +4648279 +8402929 +1901615 +2045221 +12479348 +6058725 +13605326 +5821389 +12100020 +4114971 +4952190 +6144001 +7510269 +8700112 +913828 +13989371 +15715298 +15277223 +8363222 +1549604 +16240772 +7049151 +6835808 +3561472 +11857939 +14118131 +13870761 +16162848 +4762842 +1380646 +1082140 +7639698 +16368848 +3228759 +1051055 +16197746 +2957735 +14721313 +11900682 +2075743 +3489523 +3619553 +2488279 +3720653 +10040141 +12550992 +2546554 +10865837 +12913000 +2273706 +7855375 +6360904 +7944676 +5019828 +1550864 +16525217 +13933851 +12875769 +5390489 +969352 +2051418 +3442814 +14990536 +7331352 +2612474 +8259544 +5386540 +14136656 +1220702 +5809975 +15090857 +13269066 +9910608 +6123591 +9581731 +1427886 +12724017 +813354 +9111478 +278545 +12447085 +16522431 +10129263 +4342315 +12971762 +5332619 +10805780 +7998739 +14281188 +4617006 +5735301 +7031078 +11272585 +3578158 +13371858 +15307430 +8940871 +3652369 +10215950 +8590288 +2136522 +3009880 +15362156 +13167792 +142519 +14477797 +259729 +12988137 +377581 +14270582 +12533869 +10094173 +9452841 +13748885 +4222414 +13564091 +7620078 +14617158 +5318959 +5145318 +11644340 +16023303 +6972938 +14526821 +458503 +1101380 +732741 +5049919 +13693643 +10327178 +1397258 +4251647 +10509508 +14460116 +8754041 +2451710 +15851967 +2411835 +8045433 +7237808 +1696227 +16706836 +13328864 +4005939 +10947427 +8149530 +8359148 +11085095 +5180048 +1110463 +3634692 +1027987 +9552935 +9669367 +11204428 +6833824 +912673 +4697358 +15878812 +10602934 +6363028 +4649702 +14811613 +14097905 +15619559 +11200775 +9383632 +16035762 +10175616 +1091931 +1429404 +1776556 +11531567 +11156250 +15465087 +777962 +13840073 +502189 +11632690 +10817511 +13860382 +9816972 +6530704 +1108306 +13595400 +5856285 +5684792 +6078131 +5590123 +7600773 +14709433 +15534586 +489483 +3542282 +12273674 +9450442 +1199789 +6342208 +5993928 +2749739 +5765490 +295063 +10658783 +884109 +625222 +939840 +15571167 +9666780 +4855377 +14281288 +2624363 +12709073 +1021326 +16337138 +11080101 +12849117 +2747954 +6576617 +10315450 +7052420 +9034846 +11478712 +1209059 +11806565 +6047305 +12068943 +15002002 +11852238 +15821454 +10233523 +2317967 +1852532 +14651462 +5445678 +14782982 +2427541 +4476812 +3566920 +11454394 +6742965 +7338899 +15055018 +10052224 +14673435 +5207454 +10425806 +12813930 +3390529 +16251239 +12918993 +6077693 +931988 +14089970 +7462460 +15450821 +3828483 +2935674 +8279207 +3588278 +2162795 +12378647 +3122527 +16412832 +8796687 +11228358 +9145845 +13432561 +15497506 +16684791 +9301105 +4962280 +10374327 +160548 +4471942 +13956917 +12361068 +4795636 +1326719 +4307409 +16729770 +14788654 +11066103 +2422436 +13881217 +13703743 +5882257 +3581539 +15958499 +7128885 +6926030 +8941997 +4762693 +14318601 +214785 +13994310 +4658371 +16629166 +2044933 +8669911 +13865787 +11359907 +9236957 +7510108 +14501647 +16669427 +14175660 +2086118 +11739881 +1027123 +3144661 +11805208 +9282092 +7027632 +1793749 +2247180 +2412191 +6092819 +6505110 +10911007 +11896417 +4762841 +10627189 +3026277 +5621827 +1033334 +1054968 +495121 +7740519 +3176842 +14725736 +5111685 +16694814 +3057528 +1333502 +6659104 +4429850 +15869606 +7970617 +13339201 +12870206 +7470112 +8578302 +11747395 +11406995 +401041 +15209454 +5952382 +13325945 +1647503 +829422 +7290539 +630640 +12173032 +6608495 +13861434 +12184987 +3473882 +14661176 +13831511 +5856940 +10099088 +15822528 +3353749 +5191625 +2736571 +16019974 +1945171 +13519286 +231924 +192701 +10133761 +6489516 +4174263 +9275246 +1857432 +7315498 +851663 +2530675 +12961908 +652130 +13255881 +14759538 +2303504 +4339177 +3868773 +705751 +7027385 +13705691 +2156600 +2273842 +9555118 +10666477 +12737149 +7617020 +11667886 +16452233 +11237300 +3235405 +1758241 +12700299 +5603587 +15746415 +4170671 +8376083 +14655562 +4547789 +2069274 +7773580 +3278239 +12733173 +12384467 +7048195 +5077599 +229527 +9144990 +13090775 +16397359 +13717830 +8079954 +166649 +2099768 +12380609 +12928358 +9334263 +3017586 +11158521 +1062591 +6665857 +8662594 +5378754 +6241475 +7349334 +4830914 +16654673 +11120983 +6645506 +14403997 +6772452 +10262793 +7648110 +14298436 +13192974 +4431394 +2196960 +7844121 +252895 +15329012 +1253823 +3621470 +15141622 +8112159 +14817629 +10029121 +309782 +13569803 +4950744 +6525644 +15815991 +11784762 +8032574 +14570366 +8585302 +1179513 +280634 +16402757 +3198049 +9019211 +13410749 +12160000 +1857928 +4361306 +3079785 +15774960 +11844621 +10975437 +2433004 +9501061 +13106243 +1838579 +13936113 +1055643 +2365682 +10352535 +15607791 +5406101 +6561189 +10500058 +4216233 +11211015 +1461889 +3431762 +5102393 +10900303 +13328996 +4491141 +12284166 +10284069 +14982083 +8562906 +12728912 +12652142 +6273670 +15760434 +10021578 +10597019 +6440612 +342875 +13828880 +12376975 +13415839 +2395580 +15501778 +8323713 +599620 +9723728 +3281437 +13478765 +3059471 +16157507 +10652509 +15802772 +8318617 +6319667 +4950894 +2296334 +16397091 +7188009 +2071431 +2123990 +6963440 +10595598 +12911508 +2288294 +12562320 +16073063 +9235034 +9224934 +2281104 +1000368 +6817976 +15509538 +5301022 +11419825 +7872806 +14213879 +8508444 +13561272 +8306672 +5693974 +14914063 +11060831 +15018375 +6502838 +13098469 +16461892 +9883870 +5747998 +12437006 +230050 +10228942 +11238664 +8265436 +8911464 +11767616 +16061772 +14766629 +8374777 +9175085 +15259377 +6860106 +12952130 +13907808 +13682879 +16020646 +15338603 +10784608 +6193036 +14397951 +11938769 +11544592 +2009102 +9978473 +7256690 +7898414 +3450209 +2621466 +8696413 +870946 +11166088 +6752336 +12369956 +2825856 +7214847 +6137127 +13412507 +16272115 +11011068 +5570947 +14996109 +2040429 +1712184 +9751217 +8154972 +9237791 +4853021 +5153347 +5754553 +12195563 +5995731 +8043508 +5799408 +6735831 +565020 +13977806 +12475747 +6141842 +2171411 +3541994 +9700104 +6615793 +4446358 +14378803 +848344 +5613857 +3272692 +12824906 +2064457 +8459073 +4002159 +3418768 +3476971 +4420132 +2824818 +5994418 +11628116 +11104307 +14284483 +13911447 +16087193 +13696629 +6441661 +13131437 +1340019 +13373781 +9381744 +10081745 +3196986 +1597691 +1447856 +9922734 +6167225 +247732 +11405938 +3824777 +2770132 +4465760 +5080170 +7402940 +9728192 +15678653 +16064404 +1406405 +8698489 +7751948 +13480809 +4722428 +5242572 +16268686 +10551973 +13588799 +6903609 +12782656 +912378 +15466934 +12263043 +14995299 +5292221 +14107342 +14820249 +6930823 +9400160 +16732689 +12751884 +14819082 +4454081 +10199321 +6162457 +3237217 +6449809 +10577703 +12620723 +10556168 +14710697 +12737307 +10069431 +13376856 +4165849 +14703525 +12082154 +7417186 +4714686 +10788424 +7768815 +13539176 +13933391 +11671455 +11634895 +14319532 +11544918 +751831 +7701053 +7088114 +2820203 +1130944 +8466946 +3193176 +13243198 +9897229 +15129234 +14328590 \ No newline at end of file diff --git a/22/main.rb b/22/main.rb new file mode 100755 index 0000000..ada9e4b --- /dev/null +++ b/22/main.rb @@ -0,0 +1,53 @@ +#!/usr/bin/env ruby + +require "debug" + +input = (ARGV.first.nil? ? DATA : ARGF) + .readlines(chomp: true) + .map(&:to_i) + +def evolve(secret) + a = ((secret * 64) ^ secret) % 16777216 + b = ((a / 32) ^ a) % 16777216 + c = ((b * 2048) ^ b) % 16777216 +end + +part_1 = input.map do |secret| + original = secret + 2000.times { secret = evolve(secret) } + + secret +end.sum + +p part_1 + +sequences = input.map do |secret| + secrets = 2000.times + .map { secret = evolve(secret) } + + prices = secrets.map { _1.digits.first } + + changes = prices + .map.with_index { |p, i| i == 0 ? 0 : p - prices[i - 1] } + + sequences = Hash.new + changes[1..].each_cons(4).with_index.each do |sequence, i| + sequences[sequence] ||= prices[i + 4] + end + + sequences +end + +unique_sequences = sequences.flat_map(&:keys).uniq + +part_2 = unique_sequences.map do |sequence| + sequences.sum { _1.fetch(sequence, 0) } +end.max + +p part_2 + +__END__ +1 +10 +100 +2024