diff --git a/day_22/example.txt b/day_22/example.txt new file mode 100644 index 0000000..322c9db --- /dev/null +++ b/day_22/example.txt @@ -0,0 +1,4 @@ +1 +10 +100 +2024 \ No newline at end of file diff --git a/day_22/example2.txt b/day_22/example2.txt new file mode 100644 index 0000000..cfb1988 --- /dev/null +++ b/day_22/example2.txt @@ -0,0 +1,4 @@ +1 +2 +3 +2024 \ No newline at end of file diff --git a/day_22/input.txt b/day_22/input.txt new file mode 100644 index 0000000..db97fff --- /dev/null +++ b/day_22/input.txt @@ -0,0 +1,2452 @@ +16326620 +2477938 +13518351 +3120316 +12135046 +6515414 +13640833 +9193219 +15552807 +6341694 +7308929 +14660562 +2756664 +9933257 +2620954 +15956314 +9981563 +7192819 +10818593 +8531448 +5835318 +7966645 +14270066 +15599364 +6769568 +4492735 +4678185 +5646048 +11890508 +825879 +3090971 +10082019 +12463514 +10552431 +11227494 +7760590 +3188157 +11779147 +4861181 +7864839 +12196502 +5852067 +12763534 +9684023 +3206560 +6502719 +4180013 +9496723 +597826 +6056262 +5742474 +14155437 +6067268 +14078641 +13956226 +12980886 +13921470 +4007749 +6901537 +3326409 +14592402 +7877550 +1393690 +7397485 +8616380 +10303196 +5579272 +5534849 +3674036 +1066358 +8362128 +13595562 +14452974 +5054588 +10375630 +13276817 +9039081 +12676983 +13090592 +11587363 +13155927 +12378024 +1615272 +6187876 +5711588 +12430470 +10891129 +14414366 +1901731 +3476405 +5673106 +13528882 +16096899 +7862537 +8357223 +9676855 +16223011 +4661219 +5121980 +12901545 +11625034 +12511023 +7969070 +6810883 +5741689 +3200686 +4052179 +5080815 +6815100 +10756092 +10245557 +3020795 +12514728 +2792908 +269065 +14514494 +11168027 +14827830 +11310925 +11438791 +14851222 +1960388 +6105450 +5450487 +15659982 +9036280 +8223061 +16601442 +14384275 +16621952 +9259124 +9086053 +15840484 +10850570 +9471074 +16582967 +16434971 +11074521 +6321256 +12299789 +11652712 +16734639 +338494 +12876207 +12271190 +4717168 +9021792 +10162633 +8380831 +7128336 +15329387 +364116 +2434688 +3813079 +15698321 +9638534 +7252155 +11429878 +7030121 +7985143 +2269900 +15640682 +8526279 +4492519 +1288254 +12965374 +3582087 +12673031 +10598893 +5950148 +14046095 +6008991 +15423939 +4738287 +2541411 +10382976 +271818 +7560769 +671752 +10809296 +16650671 +8098910 +2559980 +13887655 +5204366 +13593971 +14103008 +14982957 +2175108 +2975571 +13701400 +5383156 +16216234 +7173121 +6260847 +10604356 +3469394 +7227157 +9596934 +3894875 +5845209 +10159306 +7612792 +8987808 +2641410 +1888201 +7434964 +13509227 +16085205 +7954122 +15569529 +8708645 +12463602 +9474323 +2594264 +13624145 +11267278 +8939939 +460319 +14808677 +7006895 +13698658 +8190848 +5018197 +3316028 +10699831 +3403205 +2927168 +3669036 +7902228 +8311442 +1553616 +1817651 +1962307 +15207043 +7244954 +9065812 +12347426 +8391181 +6444850 +5897421 +14204771 +14582986 +12346480 +14644563 +5293687 +8967517 +1441565 +8609732 +16239465 +10112260 +10637342 +15137134 +3252903 +4890407 +6747174 +9269218 +1142145 +4690746 +1820185 +6339531 +3240494 +5575780 +6097984 +8620122 +16614133 +810808 +6482165 +14957315 +11918308 +15854862 +7224937 +12476070 +1660950 +7308839 +10391031 +6235610 +2314958 +11272974 +8356761 +8356110 +14448423 +9133608 +15233801 +3569143 +6276092 +3220405 +14222216 +6325869 +5100222 +4629463 +13200976 +7308280 +5327016 +1758070 +8663122 +402256 +13149050 +395587 +8773440 +14216907 +4867882 +12908309 +10832260 +9388047 +10412690 +14408020 +16078444 +1052556 +3184394 +3932443 +2606246 +13992698 +8293389 +7929355 +13321960 +9896675 +11212231 +187826 +14569155 +2197811 +10667301 +11504566 +3907962 +10948649 +10265482 +8610497 +15826947 +2179160 +14591153 +15251061 +1013632 +1402424 +1489002 +10257761 +15855584 +3701394 +10792211 +5557025 +602298 +13550914 +3976308 +13238674 +8199682 +11464231 +12847235 +2713610 +4816086 +14793865 +13723164 +6650944 +12491086 +5462324 +15419954 +1230208 +3274507 +4760149 +10185801 +5337973 +6026294 +1931666 +13883432 +3695032 +13397884 +1465347 +7951012 +9210855 +9857746 +15986855 +11088720 +4445935 +6814669 +6908811 +14426201 +1177241 +9479381 +5112349 +7738519 +2885214 +5721495 +4556635 +3320560 +9028822 +10597084 +5596204 +4507537 +9115113 +6314782 +16203991 +15460468 +8653884 +9063481 +12586901 +3427463 +12780049 +6562822 +716140 +3470733 +14137362 +5007279 +12526810 +16293220 +2930979 +2115941 +10757508 +9303477 +3920041 +16224058 +7902186 +2486888 +2807831 +15027680 +5618751 +8064322 +1301761 +10863721 +9255611 +333067 +1652009 +3121221 +10424901 +12222048 +15453806 +749658 +9217805 +3387647 +8873884 +11866186 +3741079 +13003705 +2859388 +15773660 +14454497 +12657855 +8941481 +11533018 +729012 +2354400 +13929162 +14635472 +10906303 +4887698 +6194458 +5855398 +16134893 +5896775 +12395033 +12260165 +7955573 +9041006 +2745981 +9627477 +3397455 +13320148 +9537874 +3869290 +16122969 +13852338 +14698114 +451352 +8193769 +794313 +13109421 +3655384 +9285305 +3038989 +3418219 +6632431 +14235882 +1446202 +13501648 +12284738 +6953612 +645785 +11542551 +15765352 +9415246 +10566297 +4099845 +12859937 +1995270 +5304192 +16612765 +8183088 +15958682 +11287217 +7412569 +4281425 +2540831 +15697954 +11825149 +5450290 +5661283 +9261465 +3810263 +13663815 +6086082 +1470244 +14360017 +8037271 +11421975 +3050709 +1616792 +2233814 +10181787 +2519896 +235149 +11628667 +888529 +7540573 +14069742 +8116250 +5721419 +13671397 +5362239 +6016657 +10219163 +8097703 +1679705 +6757525 +11474932 +11832989 +16464208 +6263701 +281852 +2220134 +15530381 +11501570 +9559517 +11934706 +16671035 +10363594 +5637677 +1098276 +5762882 +4470516 +13231660 +10839402 +2215617 +3474266 +3808973 +14570869 +2892804 +10270149 +9160558 +11814156 +12820876 +3510746 +16429429 +13520601 +10089419 +5832934 +13922796 +621991 +3936448 +16041160 +3498752 +3376895 +5884295 +12373535 +4597381 +16305509 +15700860 +4237640 +5670647 +1878949 +3835757 +9872568 +6929683 +10239384 +14513083 +16128748 +15199452 +8892074 +12823860 +13983803 +4220164 +13564959 +10116512 +13780703 +9178835 +3742345 +5534212 +13164206 +12862015 +6335591 +6439062 +14469160 +13273453 +5745904 +754518 +10369277 +9564142 +13070171 +6523736 +3840105 +11101175 +3375503 +14124404 +1485180 +4196944 +10937154 +13987651 +10202580 +7061555 +12366037 +13946339 +16398886 +550950 +7146985 +4025094 +8711345 +7342023 +15044555 +1645429 +16546200 +5809119 +8488211 +9560088 +528433 +2727241 +9877423 +3689255 +16370515 +6880287 +15284874 +387583 +5069802 +2520643 +13935994 +12137642 +11496800 +9923248 +9704143 +6033883 +10437819 +14406404 +9968400 +12055730 +16712397 +6101134 +6610632 +248883 +16174442 +6588577 +14644523 +2684642 +12081183 +14028057 +11432541 +5436037 +7082188 +9765126 +16114371 +4721786 +13052987 +8920589 +16081775 +10132875 +15818936 +1520736 +2085904 +15517846 +5836253 +11713892 +12025367 +1042622 +294557 +12152532 +9572575 +10434097 +3592991 +13978038 +8400020 +13056771 +10534908 +2471121 +6467417 +9160610 +1299993 +3603755 +12841694 +11121680 +2387612 +3082199 +12492278 +13703902 +1767226 +1212090 +13283130 +2904439 +221628 +9022749 +2202805 +12441903 +4221771 +16478371 +7246542 +10174935 +7252759 +5367518 +1661787 +300192 +5345469 +3940078 +11187854 +13086769 +4276218 +12538045 +13958105 +4264155 +11496774 +6334440 +12571265 +10556639 +3130439 +15613713 +16544127 +9953459 +16452180 +4300879 +1568440 +11586849 +11537061 +13377648 +1515317 +8170774 +11185264 +8014911 +4908786 +2186692 +4291245 +8253542 +10399843 +4904361 +11392780 +134527 +7424843 +4741339 +16145252 +5917090 +14840235 +12674746 +14431190 +15966028 +3639793 +11559428 +7798215 +4429187 +12871724 +16292829 +13027856 +12918585 +7102273 +13779010 +5959864 +9975379 +16256881 +14963158 +16087052 +375365 +7424822 +12734412 +2082078 +3430686 +11337666 +2483741 +6444604 +10296512 +4865183 +8452597 +7370358 +15031150 +2607098 +7015861 +1413369 +1014555 +3589124 +9772155 +8407471 +11362518 +11206545 +6170761 +8805256 +3879235 +6484386 +2784618 +11526553 +7394207 +15728391 +10322459 +3859555 +12225946 +10650478 +14978014 +7300520 +6364029 +7063133 +2739120 +9152595 +4547641 +3160460 +6078923 +10675566 +4969627 +16605892 +3205056 +6694763 +9207426 +1378599 +1048101 +5677182 +147685 +237105 +1759714 +14144629 +4383414 +4683530 +9249408 +11241494 +11767014 +2223363 +5069300 +1449164 +3819158 +7382266 +9249420 +5188955 +10211610 +2778978 +2172086 +7052350 +8701880 +429612 +7571324 +10968160 +8222732 +15869323 +3452816 +4257281 +5651369 +11243722 +666820 +2679269 +10936604 +5279661 +5136592 +14377274 +12652911 +13939704 +15183673 +14837497 +14333779 +5446534 +13162761 +1817914 +1299868 +2104118 +7187207 +7990111 +2523917 +6654831 +9713114 +12515035 +4125044 +4835739 +14186612 +2176251 +425193 +4525055 +11633105 +2600496 +2372952 +8796365 +11115254 +1935385 +7968724 +8423151 +3915956 +10313969 +12264962 +8542500 +1739160 +11217357 +7149444 +16395129 +14824155 +6874057 +515005 +12014048 +1891100 +11111237 +12179525 +13338052 +1148385 +14985730 +8686114 +9554406 +3093481 +12159578 +8170620 +952486 +12825704 +12927134 +4816525 +7381736 +13342517 +14283034 +11330477 +5809748 +9720358 +9140084 +5278416 +13623914 +5894245 +9653164 +1977956 +2194991 +4517119 +14547020 +8218958 +12715400 +15650093 +15157585 +11772393 +12238696 +10422115 +4293012 +14200599 +6041080 +8279129 +4139724 +7773708 +8825233 +8584104 +15572909 +16668702 +16676895 +6457551 +4603392 +5097193 +10620378 +4641706 +7312750 +5890343 +3365819 +11262897 +11605006 +10757130 +10214683 +15584088 +8268247 +12597897 +3357180 +521266 +5635268 +16696753 +12265562 +16568451 +6768263 +5088865 +10628481 +6448898 +12541859 +6164662 +15008509 +16375189 +16234501 +11455566 +8376869 +4315873 +15779914 +13041870 +10088268 +3770484 +7075428 +2946139 +16452614 +14273353 +4712850 +12603542 +3565429 +13339222 +7119434 +7959076 +16438963 +16235954 +15169579 +6391364 +8105661 +811188 +9328625 +16634081 +12900071 +15749474 +5540606 +12608336 +5988362 +8221466 +565027 +12404846 +13814477 +13964634 +13118758 +664826 +1386607 +9069857 +8328383 +16149221 +14353954 +7701305 +3930827 +15557384 +2278890 +14509874 +1863647 +15323633 +14018871 +11264444 +10223530 +8989075 +12893184 +15692906 +12892693 +8116846 +3978033 +16131248 +15309718 +9447999 +11155804 +13268810 +11859937 +5911671 +12267895 +4269037 +6876864 +11374790 +14836521 +12733041 +824286 +4601212 +6791102 +6403651 +14957835 +4990497 +5809222 +8549926 +1582262 +7369079 +11570583 +14377194 +10147143 +8125746 +15775759 +8218337 +7052141 +8595432 +9818096 +15949658 +11622027 +13427540 +14807505 +9741464 +10587398 +13207720 +1140344 +6212373 +11774860 +12467869 +16235443 +8408582 +14950427 +2210868 +3264074 +7052895 +11518257 +3400506 +4813089 +5424813 +16133215 +12382866 +5012682 +12595288 +14080824 +13154491 +5870202 +4596177 +7491512 +10978140 +4665133 +6790272 +9860909 +2869163 +11524391 +14114838 +6824402 +12280093 +6642826 +3623695 +1633172 +8550236 +12905668 +1970461 +6374620 +5556631 +15362533 +6718260 +1400436 +221992 +7299978 +1791423 +16045930 +6042634 +8864037 +6591392 +10374188 +1457699 +4346279 +15702827 +14663942 +5572122 +12623191 +14594415 +5612748 +2014084 +13497514 +9613998 +7829635 +1347442 +10010675 +5517523 +623554 +14573993 +5571001 +13509967 +15677597 +5387204 +1660487 +5385877 +6468397 +9669901 +4245173 +7065097 +11345133 +15499827 +14094527 +2172121 +10258844 +7518235 +13084663 +4514011 +1922755 +11616468 +6155565 +5716257 +10501759 +14572576 +1478110 +5345378 +5476077 +12462682 +13976887 +8738068 +3182380 +13332308 +10784452 +12287813 +12033790 +3621768 +13210030 +741120 +14908327 +15246144 +16157602 +4527662 +7934485 +11289990 +7163362 +12749456 +14221328 +857705 +4755193 +7058045 +8016578 +15245755 +9345447 +5803443 +14482678 +14560158 +10782510 +1338756 +11866361 +334653 +8133120 +9046329 +13893219 +5613746 +12414744 +9369470 +11878601 +7526779 +15280588 +182292 +13909736 +8986142 +12525778 +5614848 +16324529 +11546432 +8629619 +14539717 +2630002 +10610758 +12576911 +15706396 +9348172 +5314711 +14732777 +7024614 +16083521 +2742994 +11105943 +991732 +1638717 +14199250 +7962891 +2388570 +15908028 +11523573 +330005 +16636162 +14793224 +9392416 +9574064 +8450321 +11227517 +599277 +12095465 +5952445 +4505021 +7332859 +6488930 +12628457 +8877397 +5674166 +11806241 +15985901 +13119785 +15530216 +5034792 +4889755 +12398493 +3846443 +4621907 +12655197 +2332543 +11863486 +9408596 +1315391 +9399195 +14648973 +4724852 +13663778 +14622214 +9970169 +15793074 +15843669 +4009544 +4826295 +6087008 +1279561 +3038444 +402509 +8959250 +9824470 +376643 +4845803 +783811 +2128143 +13472944 +14752254 +4842652 +6525000 +7092547 +12849797 +1121158 +15390573 +8213828 +6737454 +464580 +8289877 +11842499 +7206530 +1244785 +14023477 +10916196 +10763947 +4116065 +11987667 +3089738 +15336739 +12305970 +4997486 +4482617 +11891553 +8638923 +3149006 +8534795 +9122969 +6878566 +12971327 +2053325 +3355927 +4155751 +2078847 +11448369 +15213321 +11682536 +13744920 +8867935 +6854516 +4827032 +4146354 +11807904 +11325903 +11507706 +6281043 +12376608 +143891 +3302254 +189077 +4546673 +6781781 +2131841 +9082644 +15034481 +3685271 +16175389 +16283256 +16641799 +14175322 +9006079 +13430172 +8031506 +7700857 +11768964 +7459681 +13486583 +6129931 +2614133 +6759371 +7713655 +3894946 +16108498 +9961226 +1104272 +1562048 +7838169 +11064079 +7333283 +8190570 +9888154 +4052789 +16727649 +6617797 +8338506 +13209729 +379835 +3764506 +5306197 +9835736 +13505648 +11438595 +1444023 +12718175 +9441218 +14323345 +13789873 +3620126 +6712962 +478434 +1095444 +12703151 +5469338 +3889957 +14047650 +14259121 +10370359 +3297355 +13398751 +12827958 +9454795 +5546583 +6429340 +8099159 +1246021 +11977762 +5915917 +13885072 +410411 +11055745 +10641379 +10675533 +4756898 +2798340 +7514133 +11491736 +7142619 +1989646 +12070493 +13757295 +3585001 +8509127 +11274568 +8040932 +6832578 +8052325 +4452821 +6923411 +6619840 +9141618 +6534166 +7689609 +3907066 +4167702 +13879829 +7166505 +2613139 +9605669 +7015801 +11851761 +4977735 +4384618 +3648969 +2562448 +6791790 +3894467 +1515309 +2639080 +3395363 +13348859 +1061267 +10475285 +8728633 +2230960 +15481816 +5356472 +8758118 +1995102 +7971645 +11611184 +10632498 +4637334 +3866340 +9190779 +2037022 +2081418 +3324534 +6460382 +8735971 +7300216 +12129305 +12797284 +15160473 +13917462 +4612615 +2550697 +15030885 +11077367 +13569222 +744769 +9887542 +8170205 +7933415 +10802003 +10166595 +13992491 +2298238 +12217324 +11949317 +11599930 +6009888 +8472732 +9714874 +11716571 +14186814 +3667691 +13150659 +13522016 +8310766 +13864999 +16695470 +1960070 +8927232 +13040629 +15383863 +13721858 +6084611 +15212531 +4754719 +6923272 +9547915 +8675998 +10312848 +5872079 +4538975 +1168233 +13527650 +9364541 +13155984 +12472805 +13947825 +812018 +1937828 +5190774 +7076339 +8417153 +4638672 +13365471 +8293143 +9657641 +13302104 +16193715 +12498215 +9076833 +10439795 +11814198 +14529617 +9984393 +15788028 +6173971 +6131855 +12631907 +3852343 +12844481 +2342040 +9635485 +15808354 +302611 +11036749 +8739641 +16039855 +11600627 +8790681 +2546152 +6153527 +14970343 +16389942 +16165694 +4034094 +9282117 +877055 +11278450 +9439011 +14286248 +6293501 +12183448 +7729816 +8525182 +14544060 +285816 +10891119 +3162613 +12070217 +12521952 +13857470 +15466993 +10788782 +3409375 +16754853 +2027265 +10132194 +16525475 +14120560 +4609923 +1557914 +8288639 +3264515 +16386973 +9861093 +13381534 +2061560 +14987944 +2789657 +8846054 +9529408 +8752674 +14855981 +7042582 +11843872 +9965604 +14744446 +12010419 +11730824 +16613831 +10199246 +8639509 +14162298 +12270768 +13708344 +13484826 +9270546 +6030934 +13509870 +15947523 +14781451 +7992930 +12841415 +7579583 +9587792 +3293127 +11234743 +16647517 +2274829 +10236148 +14117587 +1211753 +13946129 +11271851 +16303049 +15728893 +10256885 +5855674 +10208091 +11812809 +323978 +4558328 +14136798 +14048953 +15490906 +7197566 +6152105 +9915094 +4052153 +11773478 +8856062 +4491722 +530949 +14233080 +14873593 +2590952 +12891385 +16582930 +9141252 +4847809 +4140726 +8902698 +4873581 +11511343 +2338894 +6536634 +1893067 +12343681 +12594658 +4274250 +9213536 +10741910 +8266048 +6637106 +2486972 +9775356 +10229258 +5844879 +10147220 +5673660 +15856825 +490986 +9884200 +11725608 +10000605 +10361729 +7392596 +6123542 +2454225 +16322980 +15380753 +10872570 +5699534 +3301921 +13571339 +5328862 +9422328 +6338094 +16704472 +1731013 +10849859 +2130322 +11472239 +7130075 +16125284 +6121047 +6937985 +6890722 +9320736 +12613515 +5932210 +12304307 +13826350 +13501446 +7183319 +7944171 +4428983 +2302026 +8521178 +14699736 +14536725 +2079767 +10130777 +6351226 +1868785 +16246850 +4756416 +2436774 +10178626 +4358093 +14411286 +9826233 +12229809 +15521599 +5412300 +8616411 +5578254 +10996344 +8214113 +5667236 +12382025 +6592330 +9171441 +10201597 +1664285 +2211134 +3662747 +11594073 +10692618 +3384560 +2274548 +15013581 +1831379 +6905464 +15446240 +3891029 +3359656 +2839104 +9846680 +7574367 +5659260 +6454713 +570095 +10606065 +3143850 +11841834 +9483433 +8458233 +6148382 +12869852 +14419967 +9935878 +2593143 +4380045 +2840959 +8429392 +2943068 +7467572 +9746925 +4291854 +16530504 +12003992 +835582 +15415106 +1308504 +6597441 +5744249 +2282650 +1298326 +9818841 +10282662 +1633446 +1432063 +11594482 +6649570 +14363270 +2468673 +1652117 +15990958 +7684435 +11701418 +15124974 +13823410 +5096633 +7976967 +1767355 +15093206 +2646772 +9802628 +10736357 +6643461 +11328213 +9146510 +3385901 +13520597 +10875082 +9519007 +2246740 +13165844 +16041903 +2398370 +1536656 +4110607 +1574388 +3519773 +1692881 +3002446 +9352175 +12660937 +15654755 +12243341 +8183130 +8066921 +5482055 +10153941 +7980211 +4345330 +2356128 +1854666 +5925853 +3240410 +14747683 +2530461 +6412426 +15697488 +10371485 +13989471 +6276319 +6476983 +1414136 +3337992 +14503089 +9838112 +10070119 +14629144 +14288064 +6860809 +15270786 +8795198 +14820319 +10209407 +8385113 +4105607 +1692789 +3585824 +14455453 +15570449 +13776777 +1157624 +8269605 +8571539 +10969291 +3377464 +12366613 +6878658 +15195116 +4174849 +1912593 +13900057 +6477690 +3276082 +6133719 +12597093 +11833033 +8104455 +1900701 +16130349 +9249688 +1261507 +13619331 +7711028 +4057120 +395834 +13221207 +343289 +12958359 +4322571 +1692107 +9621420 +14816211 +2338253 +14568975 +3519190 +8573538 +8208384 +1825453 +14462112 +9738885 +2571716 +399918 +1637799 +14766258 +5239699 +16067064 +5674295 +16658319 +10064656 +2150762 +1458164 +1518398 +3162885 +13888284 +10672120 +5413228 +11518481 +7711381 +16018412 +5621729 +8849484 +11314370 +5689808 +16292224 +191295 +15699384 +6905786 +4076359 +12265729 +6702889 +7380556 +1767293 +11858964 +13347662 +4135768 +14728276 +15451064 +5192633 +11488475 +16090209 +8127726 +1965500 +16599635 +3713475 +5022001 +14682846 +7565919 +6752336 +3609103 +13573598 +3383709 +8738613 +14280279 +5329038 +199643 +7314996 +10735468 +15642319 +8062698 +6819390 +13645161 +9096076 +16708752 +10092408 +4077682 +4157630 +13769914 +10446723 +3755588 +13522639 +12693316 +2470339 +4279922 +6931952 +4170624 +5105570 +446266 +5476382 +16052251 +4581378 +16243159 +6889677 +1582601 +6152925 +8583517 +15979085 +12661163 +12138407 +8967141 +158992 +11967654 +948802 +1068204 +4062494 +2403768 +10420853 +13871121 +10162678 +5052447 +179283 +16019983 +12601409 +13455180 +1221815 +10794425 +1812113 +13441800 +2792160 +10173073 +1577587 +2728327 +6428479 +14443606 +13032713 +14093694 +13205279 +7437494 +9453867 +8477672 +13485055 +5420511 +12616962 +7023824 +5754023 +12536434 +547041 +9239135 +9030567 +15502465 +16765145 +16154159 +8362851 +15817616 +2554210 +10800380 +8251933 +13292122 +6374672 +2859235 +10049571 +694800 +13098287 +1251440 +11437863 +6970218 +11789442 +5104161 +16175834 +10780497 +1957473 +12467791 +5984298 +6009693 +8800178 +12233206 +821551 +7561860 +10409749 +7827770 +15595346 +9835099 +12146930 +3948144 +1160060 +16185928 +16086733 +11024090 +11691018 +4353424 +14248583 +9105272 +246227 +3482858 +6183386 +2942692 +10797082 +12517780 +10569640 +6488955 +15830565 +3902495 +3658543 +5272579 +4938814 +13291102 +15055987 +12333660 +7311403 +10742455 +584878 +11671779 +6710951 +13321712 +14474410 +13574611 +10147627 +10394673 +4466021 +16253238 +6413610 +12773479 +6229102 +8530862 +11040051 +10334098 +14641332 +11056125 +16319633 +15315357 +11041199 +10796040 +286443 +11401339 +15244502 +10478036 +2096595 +10884613 +15487122 +5622541 +756375 +2329304 +16448211 +12470181 +4968865 +7263727 +13336714 +5004099 +6377564 +9678629 +13313357 +6132597 +9665048 +3614695 +13067097 +11959029 +1029498 +2731689 +10790700 +698027 +8983038 +1680456 +10683075 +8129731 +5333891 +12572828 +2172570 +14560909 +9920605 +5961162 +9311514 +6328548 +13276209 +13554328 +1977433 +8345930 +15562462 +5479449 +201843 +10767915 +15872505 +13150287 +7332580 +6187868 +2885817 +6948673 +3018680 +1675092 +16504055 +7020523 +9938011 +9119365 +15499172 +2620412 +14286923 +8793772 +4201296 +9542140 +4755895 +10965312 +2925452 +4950690 +13666956 +9854870 +730012 +2241912 +7520576 +146150 +11856255 +15657957 +12983007 +625414 +2140036 +1446295 +1496516 +1496668 +7810461 +872443 +1985675 +1911158 +10771495 +612633 +656261 +15135375 +4963191 +988781 +13792032 +10078813 +1299802 +6767560 +9546593 +10171794 +14096293 +14024238 +3537563 +12447428 +15806581 +16411829 +11126829 +14077091 +11533568 +2598705 +3284502 +10813933 +6767285 +12369160 +7630267 +3621088 +5533526 +6567962 +5124136 +8163505 +6876880 +10468583 +8817808 +15502858 +13411573 +11150412 +11361226 +15394191 +5348588 +10116425 +6492352 +7435784 +11851742 +6088677 +13524970 +10380544 +12883831 +4996917 +10962407 +9181579 +1953559 +11475179 +742255 +13527837 +7096081 +7216707 +4468168 +12786585 +6496216 +4220498 +4520685 +16711959 +12775204 +12670439 +4074118 +6947647 +5228034 +6555379 +10790078 +14190247 +6726705 +3897937 +7143660 +16395342 +15319742 +12432447 +10279877 +3629279 +8764557 +16428913 +14273238 +10904920 +6025105 +9999811 +167052 +1041800 +15332237 +2214376 +6092058 +153286 +13378511 +11041837 +8090628 +12849026 +13557460 +7624565 +6674440 +15334474 +12396998 +3175438 +2218649 +14224967 +666829 +14052776 +15588581 +10409868 +6803570 +14422502 +10009056 +12351489 +8350456 +11046754 +14448248 +12980286 +13936167 +7135949 +12613268 +9816927 +11258405 +7281409 +4027910 +1733508 +1742852 +13444668 +8082458 +9372572 +15760948 +12879011 +3439058 +13840872 +10604937 +7495496 +15053402 +1328851 +14675578 +16130421 +10376598 +12998824 +15976240 +9790684 +16581138 +14625821 +3208036 +11434606 +14444773 +5525684 +5461604 +7234102 +5711726 +9682079 +16504185 +13500014 +7723783 +16001819 +9983152 +11383359 +7388701 +10495982 +2271570 +15170853 +14133046 +4796482 +6604685 +3844601 +14376354 +1452545 +15334310 +12653998 +12339147 +12780699 +1265039 +12140458 +4954127 +13522450 +1411079 +16397651 +5022278 +4506437 +4587896 +7669228 +7928065 +15982491 +2419817 +4318294 +8624570 +13151301 +13979359 +16722770 +12109305 +9375724 +5894930 +6549565 +286867 +7172534 +12242921 +6035664 +15379691 +3628134 +2434060 +5211267 +13583919 +10865846 +2841317 +8643212 +8186152 +8783595 +13751998 +3175442 +5984336 +7655515 +8316444 +15009867 +2208365 +219018 +6091700 +15456139 +9335769 +14380670 +10934213 +13958173 +15336785 +10933247 +10288717 +13022632 +7648213 +7983018 +13350762 +15175552 +7995338 +1859328 +15783251 +2763974 +9032009 +9272562 +9569695 +770205 +16721922 +14606067 +4645156 +9569758 +12290501 +1697799 +14368358 +4811462 +196423 +7008532 +13376911 +2145020 +9676342 +16489295 +4438562 +8132344 +13778493 +5063572 +2856173 +7523465 +1265393 +2443601 \ No newline at end of file diff --git a/day_22/solve_1.ts b/day_22/solve_1.ts new file mode 100644 index 0000000..7eac6b8 --- /dev/null +++ b/day_22/solve_1.ts @@ -0,0 +1,33 @@ +export function mix(a: bigint, b: bigint): bigint { + return a ^ b; +} + +export function prune(a: bigint): bigint { +// return a % 16777216n; // 2^24 + return a & 0xFFFFFFn; +} + +export function generate(secret: bigint): bigint { + let r = secret; + r = mix(r, r << 6n); // multiply by 64 + r = prune(r); + r = mix(r, r >> 5n); // shift right 5 + r = prune(r); + r = mix(r, r << 11n); + r = prune(r); + return r; +} + +export function advance(secret: bigint, n: number): bigint { + let r = secret; + for (let i = 0; i < n; i++) { + r = generate(r); + } + return r; +} + +if (import.meta.main) { + const initialNumbers = (await Deno.readTextFile("input.txt")).replaceAll("\r","").split("\n").map(x => BigInt(parseInt(x))); + const sum = initialNumbers.map(x => (advance(x, 2000))).reduce((a, b) => a + b, 0n); + console.log(sum); +} \ No newline at end of file diff --git a/day_22/solve_2.ts b/day_22/solve_2.ts new file mode 100644 index 0000000..c950f66 --- /dev/null +++ b/day_22/solve_2.ts @@ -0,0 +1,75 @@ +import { generate } from "./solve_1.ts"; +/// 2000 개 이전 값에서 가장 많은 바나나를 얻을 수 있는 패턴 한개 찾기. +/// 초기 4개 값은 버려짐. + +export type Pattern = [number, number, number, number]; + +export function patternToKey(p: Pattern): string { + return p.join(","); +} + +function getPatternMap( + secret: bigint, + n: number +): Map { + let r = secret; + const patternMap = new Map(); + let p = [Infinity, Infinity, Infinity, Number(r) % 10]; + for (let i = 0; i < n; i++) { + r = generate(r); + const newValue = Number(r) % 10; + const diff = [ + (p[1] - p[0] ), + (p[2] - p[1] ), + (p[3] - p[2] ), + (newValue - p[3] ), + ] as Pattern; + // if NaN or Infinity, skip + if (diff.some(x => !Number.isFinite(x))) { + p = [p[1], p[2], p[3], newValue]; + continue; + } + const key = patternToKey(diff); + if (!patternMap.has(key)) { + patternMap.set(patternToKey(diff), newValue); + } + p = [p[1], p[2], p[3], newValue]; + } + return patternMap; +} + + + +if (import.meta.main) { + const initialNumbers = (await Deno.readTextFile("input.txt")).replaceAll("\r","").split("\n").map(x => BigInt(parseInt(x))); + const resultMap = new Map(); + const mapArr = initialNumbers.map(x => { + const map = getPatternMap(x, 2000); + return map; + }); + mapArr.forEach(map => { + map.forEach((v, k) => { + const x = resultMap.get(k) ?? 0; + resultMap.set(k, x + v); + }); + }); + const reversedMap = new Map(); + resultMap.forEach((v, k) => { + const x = reversedMap.get(v) ?? []; + x.push(k); + reversedMap.set(v,x) + }); + + const keys = [...reversedMap.keys()]; + keys.sort((a,b)=> b-a); + const maximum = keys[0]; + console.log("max:", maximum); + const p = reversedMap.get(maximum)!; + const pk = p[0] + console.log("pattern:", p); + // mapArr.forEach(mp => { + // const p = mp.get(pk); + // console.log(p); + // }) + +} \ No newline at end of file