diff --git a/2024/day22/input.txt b/2024/day22/input.txt new file mode 100644 index 0000000..86f7112 --- /dev/null +++ b/2024/day22/input.txt @@ -0,0 +1,1881 @@ +8614704 +2053486 +3765927 +1576772 +7913024 +6868578 +3292467 +5861032 +11682386 +14674550 +3746001 +16309858 +9438442 +13804807 +5201445 +16041409 +12058890 +13761228 +8531393 +13324660 +3772875 +9823448 +11597510 +13465391 +8624176 +11565491 +14089083 +9049758 +2608878 +12527833 +6049828 +9655345 +15274301 +3151858 +3007478 +3394416 +3488572 +355280 +2281217 +8170774 +2273840 +8198909 +725621 +411280 +11829453 +3720687 +10161582 +729633 +10006250 +12258169 +5539275 +2496157 +13661268 +2461724 +1403549 +3915873 +1766174 +3552743 +7857674 +15292705 +11212413 +3484267 +8902118 +5074447 +16600946 +12642812 +9758610 +2234848 +4616084 +4271363 +8467327 +9375615 +1608683 +853632 +9875709 +10725446 +3296605 +14222361 +12133217 +11035428 +6457661 +8761644 +14773484 +7978572 +14322285 +8970538 +1797204 +15292612 +963114 +4266861 +9884707 +10219928 +14849508 +14517536 +13541792 +15441242 +5801331 +6350457 +3477505 +2340138 +5272043 +10006677 +16770915 +13187768 +13629582 +10820260 +13555900 +4534099 +9260741 +14418129 +14808255 +11763578 +580275 +3258202 +15738480 +2184544 +2377690 +3254722 +11902626 +8841539 +6895448 +15573689 +10497910 +11934622 +12621715 +16242313 +8802660 +4161776 +15531714 +14496035 +1294838 +13375018 +12047969 +3179480 +7662325 +14745001 +11203263 +2268872 +16271932 +12690485 +5671124 +8151221 +9265884 +8722807 +12188971 +14263935 +6949581 +7908649 +9134098 +895986 +4954290 +9881442 +14200147 +12378865 +15937193 +9376867 +3547026 +5381600 +2194807 +7368860 +3842272 +14801010 +8352199 +2315731 +16259703 +5945219 +10000210 +9176016 +5968982 +6776692 +3743551 +2636638 +371296 +8374758 +14588700 +7173917 +7257806 +6682888 +15865884 +4081714 +4579604 +1487303 +13795937 +6251203 +13726729 +4126809 +1472853 +9131251 +9176538 +892214 +991247 +12423195 +4444008 +5381509 +6179568 +13165820 +15019747 +12991071 +11518371 +6733272 +1729019 +2142145 +8676791 +2882185 +15693468 +15493168 +1500660 +3895336 +8684846 +3618369 +1208470 +3513613 +4320326 +11922163 +1605235 +7301302 +15665988 +7671997 +8681988 +14934663 +1601201 +14925981 +13667082 +7362602 +298537 +16065039 +4081031 +13376040 +6365043 +12646901 +8268890 +12877852 +6165700 +6363338 +8579265 +14529537 +13896826 +7993145 +6980508 +4543002 +1125984 +7598913 +5555984 +11317024 +4918612 +9146492 +8905432 +5414343 +1997644 +6430174 +12344872 +14791887 +11510026 +6949721 +13429677 +9868692 +11592005 +16514116 +12036542 +7968082 +16701669 +1558836 +1590896 +14931766 +9331151 +12242706 +13510567 +1153005 +6818817 +3625643 +15374037 +8043081 +4435993 +5880275 +571769 +5504371 +5648133 +511592 +2572001 +14839107 +16333693 +4009439 +14730271 +668221 +8469210 +12454662 +5332065 +843324 +6908746 +12464323 +10027359 +13531583 +2428099 +1248547 +866464 +266894 +3817439 +3986934 +2521814 +15293341 +8493487 +16354399 +13835679 +16279014 +7763144 +1561957 +15800659 +14665592 +8465950 +6943593 +1126273 +13053644 +16619238 +14182831 +9377573 +12436051 +11191163 +5132487 +5538925 +3963943 +12142928 +5476996 +5338948 +294339 +275266 +1650569 +7094434 +14353633 +4991735 +14186771 +16738011 +3798742 +5521359 +624782 +14022647 +10811409 +5666485 +12256756 +10035759 +1419225 +4524601 +10544776 +1900933 +9380319 +15044326 +12171639 +5806425 +14644715 +3316740 +225395 +7652787 +3264142 +9317654 +7637187 +3056854 +10342544 +2009882 +6412189 +2251368 +654032 +13034997 +13099959 +1252708 +16119581 +3452379 +7675894 +15072403 +4830685 +11409691 +11344118 +9608749 +9405763 +5485733 +8118992 +1384914 +16129892 +14105539 +5377796 +6953908 +13944202 +12602789 +7865788 +11008108 +6693092 +16495898 +2996971 +14601607 +10868228 +11269989 +5171371 +2701145 +13297516 +8337971 +4775499 +3419189 +8218887 +7689683 +12896268 +16063388 +12204127 +5816132 +3237959 +5896307 +16177461 +11435325 +12482816 +547745 +13828407 +13478733 +15488566 +14246917 +9332132 +12269062 +11190115 +2733282 +14284772 +7537337 +13902469 +12748882 +6797423 +7871353 +14304971 +1868687 +11847360 +5223707 +5419456 +3430952 +16144253 +13821850 +5161253 +3051374 +8524988 +13115814 +7946007 +3227051 +16338120 +6954315 +9885486 +3466426 +2080695 +12795253 +13568872 +2048240 +16593134 +2396576 +10842206 +1780527 +15783070 +12947017 +14189345 +7919409 +4968551 +11015368 +11362688 +10254608 +12203616 +5858252 +12202231 +1421864 +8446226 +15706710 +13552290 +2235218 +9009716 +12476670 +13182160 +9112194 +10333053 +10313820 +15029882 +931763 +11224399 +1998570 +16218079 +2968553 +8792232 +13362201 +11020035 +6785273 +9399684 +10631478 +13846595 +4369567 +4645517 +16675508 +4555888 +1360142 +2704370 +12487854 +4122675 +3193903 +8381253 +6337479 +13196573 +7821366 +5228076 +9820013 +2231819 +8415262 +7089163 +1010466 +15617718 +13941799 +16513026 +14188983 +1545269 +12736811 +14191335 +6340258 +5327419 +5893419 +16735603 +14392860 +7194958 +11067152 +6042460 +593012 +12578312 +4891423 +16609724 +6448915 +16544384 +12772415 +11484118 +13106596 +1534613 +9310066 +2035258 +11904916 +15954804 +13014687 +15535910 +303182 +14495767 +5651702 +12843261 +16233435 +2855110 +5936573 +13696741 +12117074 +4045991 +6941107 +2312382 +2268902 +9302900 +15698541 +11890935 +11850987 +13020202 +5997179 +3076400 +2150609 +14742821 +6819677 +6463498 +9328891 +3646617 +10003322 +13213749 +10881454 +7556793 +12174745 +16684111 +13443947 +11264729 +3026047 +8657433 +11678698 +5506073 +4346727 +12375881 +511105 +11273678 +13079357 +5666881 +9318632 +5855645 +13361042 +13726449 +15780996 +868059 +8431928 +4330357 +1245663 +7586054 +15752852 +7866878 +9977735 +14960757 +11765409 +7501886 +4282030 +14482809 +15055504 +7816351 +8387004 +14904563 +3716830 +13928816 +14721958 +4833105 +6455984 +10381943 +4752167 +10191179 +2105074 +11594341 +10315515 +7907925 +15032780 +4509724 +10555664 +15597805 +3629445 +14807031 +5127664 +10164764 +3612648 +8961006 +10388241 +6189406 +7651283 +13085898 +8835419 +6556201 +10577268 +10589075 +5884183 +12508606 +9413158 +13906659 +3438745 +411796 +2874074 +14778583 +9758515 +14717944 +1052207 +16308783 +178586 +3443641 +10850894 +9259602 +9636767 +12015277 +3824873 +13320435 +10847248 +13509847 +4451672 +12966277 +9296585 +15462555 +7372113 +6017202 +9842027 +1301255 +2777885 +1431000 +6304960 +2326435 +10878110 +3528618 +10406583 +1571704 +2732000 +710951 +12142317 +12773143 +14673989 +14859344 +14126334 +13819233 +13044148 +8851524 +14924898 +15966858 +14379385 +10122749 +15416383 +3013008 +7535064 +1152803 +8015522 +3058615 +4044137 +7031615 +4248735 +5326594 +13462984 +5606933 +11196486 +16207814 +16226555 +7592925 +9478389 +2543475 +12809839 +13353665 +10574413 +9218437 +15893045 +1356329 +12645689 +13721679 +3735418 +14996805 +5579902 +7274440 +3568923 +654485 +3531533 +581107 +15830093 +12582705 +10715313 +9732264 +7066940 +12232241 +12577249 +6492329 +10533779 +13701051 +14737504 +6601653 +14244001 +11782660 +6536164 +2147395 +11007459 +2805228 +1416026 +10344157 +6542440 +6976222 +5814353 +5948631 +12337021 +5095190 +773617 +4309801 +11329213 +769707 +10269495 +5678187 +3123338 +10898791 +840838 +11055101 +16285038 +15651281 +1444445 +8537873 +3361525 +11827151 +6701512 +5940495 +14238680 +12618908 +9625172 +9761882 +5711940 +16159268 +4586628 +8160427 +6905457 +961118 +9145952 +9641615 +14585201 +8268210 +4944232 +8962452 +5772692 +5297969 +740676 +10039693 +11134538 +12574744 +1864842 +8768778 +12340458 +15490808 +7982239 +16616648 +13901121 +719796 +11898390 +764722 +4288527 +11558315 +3314665 +12602701 +6277184 +5999209 +11468034 +6108565 +15669442 +12504690 +5742507 +3587639 +11105892 +1327384 +10336798 +3431628 +11830869 +11435169 +7822620 +11151239 +12088878 +2211716 +14300503 +1258513 +4831645 +12365600 +8388015 +15353023 +15097628 +12029433 +7956124 +11647723 +2667539 +11496520 +2192825 +12512828 +12815657 +12715914 +12983084 +11285129 +15201390 +15755718 +6308035 +16019881 +10850355 +5861660 +15214517 +7165455 +4314741 +15409552 +3620267 +16168840 +11162809 +9419548 +3757850 +7931508 +13432623 +7871083 +5020716 +14329139 +11370236 +13621543 +12750150 +4383771 +11020876 +7354404 +8711401 +7416897 +333041 +13187185 +16295129 +1501669 +13822179 +2415863 +15592604 +3025345 +10954506 +11905836 +16125462 +2516687 +6516063 +7392052 +12360310 +11311408 +14265161 +6036691 +14951659 +6008027 +6941633 +11799475 +7442791 +2863259 +3158434 +11833481 +234353 +6976873 +10780924 +12362526 +226122 +8994012 +5405732 +10111085 +8512953 +8672423 +233381 +562589 +13466797 +6620749 +14637280 +2851363 +15840074 +3776338 +3165112 +6266355 +6950719 +4925432 +2645783 +14873195 +3830314 +4448101 +8336041 +16388756 +15607939 +5510295 +10314906 +9443066 +2565833 +7953898 +11147382 +11843784 +3494385 +5015133 +7447525 +4100993 +8893363 +10576280 +1527305 +14728026 +8888075 +1558520 +12230387 +6691857 +5344088 +11570024 +8990869 +9412589 +13682071 +2729635 +5885489 +5500092 +12056027 +13644752 +7941422 +12512119 +13517709 +13561556 +12852912 +10779570 +7339046 +10540241 +7139168 +2632692 +15261142 +7837266 +12396012 +6680753 +1464638 +5531255 +3411191 +12079844 +8620674 +5154865 +247104 +15464968 +11440671 +10755343 +1576119 +15643021 +594053 +6793381 +15252086 +1561860 +9667585 +2437543 +9314626 +6192544 +14962330 +620547 +478837 +15715599 +7821413 +1328917 +5856489 +9931332 +10302065 +14269936 +14218878 +2626120 +6086082 +11966246 +7306910 +12965648 +8908982 +9017119 +13520901 +14259685 +1884979 +3497253 +9814987 +13089805 +7276056 +13279633 +12083858 +8427570 +13509885 +584813 +16410178 +10473275 +3207394 +13931707 +6063795 +10862949 +14759751 +8227620 +12753160 +6694321 +11954772 +1660036 +9024621 +3144746 +13282286 +1213141 +16249397 +11159521 +1781308 +7331720 +12275514 +11589156 +5943225 +2613777 +16726948 +6952458 +8394505 +629382 +3000570 +2549809 +7015141 +5448651 +3645359 +4321125 +5995485 +216169 +14854380 +16233925 +4788301 +6314634 +2888377 +10204189 +415173 +1810394 +3516177 +15110174 +7575064 +4888366 +7845301 +15118226 +4307125 +13512893 +15310860 +12867491 +9253443 +10161263 +1227124 +12197386 +2008151 +16387482 +3680489 +7500598 +2581735 +846265 +10356202 +16700985 +14555230 +6891072 +7437785 +12583631 +13515155 +12849565 +2004024 +14591190 +16691041 +11362987 +9464390 +1257498 +4405402 +5679493 +2491800 +2170274 +2607853 +6950537 +4889691 +11898226 +14172332 +6228414 +10652941 +2886410 +14717664 +4777797 +12818779 +15315211 +5181597 +13160108 +1752306 +11221724 +4633008 +1272860 +11615200 +7448441 +15394985 +13546799 +2766137 +666668 +4443823 +13308172 +15878247 +6125196 +9091625 +2721275 +2132623 +10360800 +2051828 +1287960 +11155510 +8697506 +7592949 +6200584 +6031898 +9564941 +15326462 +15904207 +1236489 +11159128 +2042223 +13276098 +4077852 +12476300 +1285809 +15225719 +5045142 +15157725 +14864757 +11419185 +7478061 +14746869 +13949124 +1419987 +13779531 +6620333 +6023733 +10192053 +7628101 +10060152 +8848958 +9506539 +1543508 +12036618 +11017759 +11709844 +4443996 +6817698 +11674149 +5885628 +7693925 +9764342 +3372525 +5595887 +6271446 +16307109 +12650735 +7670864 +9902647 +9080325 +7496460 +6761318 +5834614 +8513568 +10776280 +15940619 +15320381 +11560647 +3063108 +14099712 +6539287 +13105150 +1306553 +14017210 +16307348 +1734681 +4810246 +13409163 +10771430 +15468663 +6042747 +1970742 +162455 +12081204 +9286443 +12815652 +2663003 +8596406 +7475650 +2602518 +5016098 +4244152 +2597515 +16472332 +12563364 +14203449 +13294312 +15729496 +8982272 +2363009 +6301519 +12103295 +6233806 +11642491 +15592432 +16666472 +9162104 +8839839 +1286468 +3955371 +13496920 +11594718 +566394 +8402041 +10262135 +6991911 +11124251 +14732930 +1923188 +1027972 +11318635 +11549337 +13373783 +12313666 +15705082 +7872137 +6814647 +14249726 +1358416 +11353706 +8994755 +6185776 +16733212 +11524185 +4113507 +4689526 +4759328 +10518507 +627613 +5745306 +8631298 +9523949 +2935324 +245087 +11029125 +10921282 +16511627 +9762548 +2202351 +15865984 +10588468 +8912414 +13462575 +15142643 +7108085 +10417477 +6005024 +5026327 +14669395 +13083361 +4007523 +1350758 +7543328 +10217502 +7224731 +10516067 +3163824 +4212487 +12030299 +14905658 +3072574 +14070787 +10485471 +15009589 +3575457 +12497470 +14143114 +5008696 +867074 +12387613 +6314604 +516637 +16130992 +12691428 +9144688 +12114545 +4495535 +15379844 +16690790 +9687661 +10164993 +3140255 +8280847 +2971217 +4550939 +8419545 +4628545 +4009037 +14563382 +12399065 +822430 +15608887 +8766889 +5832599 +2818756 +7635452 +12332185 +881679 +3091866 +6240603 +3765425 +3965390 +15785295 +16645636 +11188672 +11320979 +2316494 +10879877 +1080654 +5340842 +10554799 +11515505 +9377386 +16505026 +13753201 +2616702 +6833176 +5938044 +2379110 +6104780 +5738450 +11740735 +15677680 +1598878 +15973057 +5733030 +13181636 +14125053 +847155 +7708984 +9846151 +1150059 +2887694 +2842664 +13858212 +14022337 +693944 +9395028 +10549567 +5317294 +9584940 +13365022 +8396597 +12665567 +16313491 +4176180 +8066166 +757751 +4950237 +6154494 +11525026 +14015178 +1939070 +9540154 +16578174 +6783981 +1522805 +3384541 +10781687 +6590689 +6807385 +15369096 +2698879 +13375064 +6826539 +8974986 +6514208 +10940646 +224292 +12917446 +13825581 +9657190 +524206 +1854152 +5894243 +8488438 +12044568 +721606 +4947317 +9839343 +2663304 +5344126 +8828195 +5098127 +16737033 +11997578 +10876342 +15272786 +14663487 +16714773 +15338325 +1738216 +6328040 +2948281 +264874 +10432944 +5766067 +1348578 +5455749 +15209274 +605319 +8752905 +5349010 +10984203 +1549506 +8825313 +10184887 +15890725 +12049768 +16678592 +3225292 +13497126 +7441555 +3265164 +6652943 +8605931 +2876372 +2783925 +8424804 +4812697 +989855 +15244826 +13531541 +12142236 +8522225 +1091841 +10761154 +9012997 +3896810 +5433079 +3873781 +7369957 +6966289 +2664399 +2890257 +14138833 +14265690 +8408510 +4723863 +7866552 +339204 +16590444 +8332922 +11930460 +6988997 +4709751 +3275998 +10777193 +14907026 +1008151 +7982796 +3558420 +13983897 +11194490 +7644420 +7730036 +14365682 +3618719 +4644532 +4249180 +8719776 +5942197 +3258452 +11112859 +10755938 +7737439 +12336152 +4233637 +6542824 +9917339 +560688 +12214657 +15017911 +7648927 +8098495 +11940024 +6698811 +3693465 +5047991 +1225843 +9309694 +7148267 +6576074 +2032012 +6824748 +10460756 +4968808 +12320392 +14640914 +10549605 +12160311 +14280347 +2208821 +12855928 +16346017 +9520074 +2918466 +8160172 +1709303 +1568546 +5289690 +4308328 +15893588 +16548998 +10752467 +14219594 +11025075 +3245368 +3189079 +8544933 +12206536 +2488962 +6219162 +11730520 +6841064 +11581991 +11806677 +14900254 +6235604 +10617400 +1991520 +11117892 +4556141 +15375090 +2031251 +6042968 +4586579 +15090882 +3260509 +6559318 +10502396 +868471 +15027990 +16044183 +8871761 +4202668 +5847665 +13157633 +5565669 +12636186 +2119878 +16341741 +9956264 +7825740 +5161835 +8495232 +14030209 +11326296 +16550147 +1007989 +1392778 +6905306 +5409802 +14963415 +16729978 +8990279 +4749864 +16498552 +8147894 +2241255 +14455295 +13399744 +3143058 +2920023 +3636345 +2345698 +5014483 +12825189 +6225830 +4698763 +15178745 +11234376 +5384056 +11600309 +6431151 +2052075 +12699573 +3726214 +14355416 +8302027 +11421082 +16484582 +14346452 +10721382 +5665437 +6662898 +3604773 +12686503 +2437090 +2951759 +10686276 +10231255 +8883922 +3416851 +7588955 +13761249 +13525580 +7662877 +11416506 +7596378 +14262468 +10848363 +7795005 +16112841 +9287066 +14188923 +9339217 +7149325 +7195319 +13420703 +9577269 +2745167 +16727661 +3507647 +5234403 +7768352 +6336576 +15027756 +4521840 +16515753 +14439727 +14903540 +13299717 +8689818 +6575257 +13866323 +14699598 +3101328 +7060935 +15719426 +9047293 +10179606 +14278294 +9591918 +941390 +11732772 +5392791 +1679427 +16197248 +11154974 +15485030 +6684446 +16286210 +16638660 +14786998 +6229973 +4770214 +7620168 +2428143 +5861739 +8068660 +13081314 +9448180 +1218923 +9709544 +152011 +2875371 +10052963 +12923086 +13400867 +3877002 +6838006 +14820989 +8999351 +9595289 +13003575 +4630188 +15799252 +9004559 +14091236 +9832447 +5058165 +10148395 +3428731 +4906470 +10744326 +11584665 +5104981 +6242988 +10082753 +4715705 +6008945 +8402370 +9716046 +9177740 +5026803 +4162849 +1716679 +3861744 +9199892 +159438 +11782285 +2378007 +12469469 +5360362 +8735124 +2956859 +14591434 +10090075 +14873778 +7081430 +16550997 +766408 +2854016 +1916570 +1769572 +3145699 +14718425 +3304088 +2269836 +6356986 +15055810 +11614968 +923239 +11699833 +14455996 +15769795 +4173900 +13794177 +14024407 +11363868 +4889140 +14415844 +9123807 +10023251 +8787683 +10408345 +10954987 +11865876 +13956375 +16015997 +11112798 +374256 +10929143 +8281439 +3141357 +2617143 +9790408 +5998189 +12541908 +5864215 +16740277 +3480557 +988030 +3484563 +13589608 +1057380 +4132409 +4282068 +4817163 +13831129 +2525021 +15851757 +16673430 +8469356 +5214258 +7613183 +7242055 +1348963 +796304 +10640678 +10564490 +784112 +5347757 +14935435 +5268962 +5138484 +463837 +148522 +6883809 +255374 +7742031 +5973203 +14386375 +11565840 +13417938 +977461 +6905361 +1332441 +16074367 +5237087 +13616351 +428367 +15880703 +5515429 +6843935 +9659810 +1337751 +5714481 +821799 +15960446 +14601365 +7265814 +8248465 +15416295 +8060440 +8094718 +15792688 +731132 +4779015 +3745276 +9456706 +11969786 +10390095 +8482654 +14058301 +14831613 +5708272 +12656522 +705545 +2557968 +5529949 +2567534 +13372896 +12991679 +381909 +16504582 +5599954 +7167164 +5380609 +1793496 +7401039 +11693150 +13846520 +13668454 +5468718 +6109830 +3345952 +10147008 +9930827 +4660496 +10793964 +1396057 +16276195 +2087984 +4136816 +5257885 +11970020 +4701494 +6265871 +13366397 +12248205 +16591042 +9805606 +4850538 +376541 +7792147 +1191058 +16251664 +3497694 +7896071 +4491312 +12842543 +2087936 +5118091 +6487631 +974265 +12949631 +7208835 diff --git a/2024/day22/input.txt.h b/2024/day22/input.txt.h new file mode 100644 index 0000000..f9055c7 --- /dev/null +++ b/2024/day22/input.txt.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern uint32_t _binary_2024_day22_input_txt_start __asm("_binary_2024_day22_input_txt_start"); +extern uint32_t _binary_2024_day22_input_txt_end __asm("_binary_2024_day22_input_txt_end"); +extern uint32_t _binary_2024_day22_input_txt_size __asm("_binary_2024_day22_input_txt_size"); + +#ifdef __cplusplus +} +#endif diff --git a/2024/day22/sample1.txt b/2024/day22/sample1.txt new file mode 100644 index 0000000..07b41ba --- /dev/null +++ b/2024/day22/sample1.txt @@ -0,0 +1,4 @@ +1 +10 +100 +2024 diff --git a/2024/day22/sample1.txt.h b/2024/day22/sample1.txt.h new file mode 100644 index 0000000..01c2007 --- /dev/null +++ b/2024/day22/sample1.txt.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern uint32_t _binary_2024_day22_sample1_txt_start __asm("_binary_2024_day22_sample1_txt_start"); +extern uint32_t _binary_2024_day22_sample1_txt_end __asm("_binary_2024_day22_sample1_txt_end"); +extern uint32_t _binary_2024_day22_sample1_txt_size __asm("_binary_2024_day22_sample1_txt_size"); + +#ifdef __cplusplus +} +#endif diff --git a/2024/day22/solution.c b/2024/day22/solution.c new file mode 100644 index 0000000..4f93e07 --- /dev/null +++ b/2024/day22/solution.c @@ -0,0 +1,57 @@ +#include + +#include "parse.h" +#include "printf.h" + +static inline unsigned int mix(unsigned int a, unsigned int b) +{ + return (a ^ b) % 16777216; +} + +static int random(int n) +{ + n = mix(n, n * 64); + n = mix(n, n / 32); + n = mix(n, n * 2048); + return n; +} + +static int random_n(int n, int m) +{ + for (int i = 0; i < m; i++) { + n = random(n); + } + + return n; +} + +static int parse_input(const char * input, int length, int * ns) +{ + const char * end = input + length; + int i = 0; + while (input < end) { + input = parse_base10(input, &ns[i]); + input = parse_skip(input, '\n'); + i++; + } + return i; +} + +int64_t _2024_day22_part1(const char * input, int length) +{ + int ns[2048]; + + int ns_length = parse_input(input, length, ns); + + int64_t sum = 0; + for (int i = 0; i < ns_length; i++) { + sum += (int64_t)random_n(ns[i], 2000); + } + + return sum; +} + +int64_t _2024_day22_part2(const char * input, int length) +{ + return -1; +} diff --git a/input_dreamcast.inc b/input_dreamcast.inc index 576984a..4733022 100644 --- a/input_dreamcast.inc +++ b/input_dreamcast.inc @@ -50,6 +50,8 @@ #include "2024/day18/input.txt.h" #include "2024/day19/sample1.txt.h" #include "2024/day19/input.txt.h" +#include "2024/day22/sample1.txt.h" +#include "2024/day22/input.txt.h" static struct start_size sample[][2] = { { @@ -196,6 +198,12 @@ static struct start_size sample[][2] = { { ( char *)&_binary_2024_day19_sample1_txt_start, (uint32_t)&_binary_2024_day19_sample1_txt_size }, }, + { + { ( char *)&_binary_2024_day22_sample1_txt_start, + (uint32_t)&_binary_2024_day22_sample1_txt_size }, + { ( char *)&_binary_2024_day22_sample1_txt_start, + (uint32_t)&_binary_2024_day22_sample1_txt_size }, + }, }; static struct start_size input[] = { @@ -247,4 +255,6 @@ static struct start_size input[] = { (uint32_t)&_binary_2024_day18_input_txt_size }, { ( char *)&_binary_2024_day19_input_txt_start, (uint32_t)&_binary_2024_day19_input_txt_size }, + { ( char *)&_binary_2024_day22_input_txt_start, + (uint32_t)&_binary_2024_day22_input_txt_size }, }; diff --git a/runner.c b/runner.c index ad7d6a0..a656229 100644 --- a/runner.c +++ b/runner.c @@ -38,7 +38,7 @@ bool runner_tick(struct runner_state * runner_state) int year = solution[ix].year; int day = solution[ix].day; - if (year != 2024 || day != 19) { + if (year != 2024 || day != 22) { return false; } diff --git a/runner.inc b/runner.inc index 4f4557e..7ac1d04 100644 --- a/runner.inc +++ b/runner.inc @@ -52,6 +52,8 @@ int64_t _2024_day18_part1(const char * input, int length); int64_t _2024_day18_part2(const char * input, int length); int64_t _2024_day19_part1(const char * input, int length); int64_t _2024_day19_part2(const char * input, int length); +int64_t _2024_day22_part1(const char * input, int length); +int64_t _2024_day22_part2(const char * input, int length); struct day_funcs solution[] = { { @@ -174,4 +176,9 @@ struct day_funcs solution[] = { {_2024_day19_part1, _2024_day19_part2}, NULL, }, + { + 2024, 22, + {_2024_day22_part1, _2024_day22_part2}, + NULL, + }, }; diff --git a/solutions.mk b/solutions.mk index 1750bb3..3ed6412 100644 --- a/solutions.mk +++ b/solutions.mk @@ -76,4 +76,7 @@ DAY_OBJ = \ 2024/day18/solution.o \ 2024/day19/sample1.txt.o \ 2024/day19/input.txt.o \ - 2024/day19/solution.o + 2024/day19/solution.o \ + 2024/day22/sample1.txt.o \ + 2024/day22/input.txt.o \ + 2024/day22/solution.o