diff options
37 files changed, 4797 insertions, 0 deletions
diff --git a/advent-of-code/2023/.gitignore b/advent-of-code/2023/.gitignore new file mode 100644 index 0000000..5e92c04 --- /dev/null +++ b/advent-of-code/2023/.gitignore @@ -0,0 +1,2 @@ +part1 +part2 diff --git a/advent-of-code/2023/01/Makefile b/advent-of-code/2023/01/Makefile new file mode 100644 index 0000000..44480b6 --- /dev/null +++ b/advent-of-code/2023/01/Makefile @@ -0,0 +1,14 @@ +all: run + +run: part1 part2 + ./part1 + ./part2 + +part1: part1.c + gcc -g -I../lib/ ../lib/*.c part1.c -o part1 + +part2: part2.c + gcc -g -I../lib/ ../lib/*.c part2.c -o part2 + +clean: + rm part1 part2 diff --git a/advent-of-code/2023/01/input b/advent-of-code/2023/01/input new file mode 100644 index 0000000..df09d64 --- /dev/null +++ b/advent-of-code/2023/01/input @@ -0,0 +1,1000 @@ +six1mpffbnbnnlxthree +4eight3one92 +9nine2xnhvjtjlzj48 +jxrbrt4jmnmlonesznvbjrsn +nsvkljgpfn77pvfour5j +fourlkgmnnzncht75 +shqmhnlbjjvskone6two78 +qjgcxccgthree85five +eight7sbdbgqgcfive3two +eight878nckqdt3pgzc +pkdrhksqdhrvhg5 +nine7four7one2 +9fives +fplzzhthreethree7sqnsmrljgsmnpktfkhzdpqfkone +hqrcls33sevensevennine +four4m +seven331fivekfrqbd +ninechvkpthreefive8tlmfclr +8954bxsqntndjmonenx5 +nine7km +seven588sevenxffivethreehkrczrlm +3cmjzjmhone +jfgr2fourtflvttr +qpplcgvklzztqjkbbnfiveftcqmlrqnd824 +ttsgz9 +9eightthreeonezrninetwo +pbccq6onefoureightbkvgvtm3 +9tworrchzdzfthreefgksrzjpdq +chcjdxbninejtwo1nineszf2one +ronecfcdlsqgfvlxj217 +three4onex1 +8nrhcn3zgsgn3239 +3tczzbrvdm6tphb32 +85threecnqsscqklhsix +5foureightnine57nshjbgrv +1fourpcgljhlx5 +v632eightnnjrjl +zlpfive6xthreeczrknclqdtfiveseven +6ninekbdmjqrktwo2 +threetwofourlqjnmnine767 +8two5mbs3eightthreethreelvhcgrd +zntoneightfour1lcbzfhm4msneight7 +7eight5eightone +8rpbfqb44 +rfninelkclkflsjsrb3 +jzxlngk1 +5zsnxfdt82qmszx +75threetcvbmhplqmhrcztsghctvsvrhkftwo +grtwosnjvrpx76 +69two1tdsgbgbprs7 +vrsrmdngjpn2nine +onesix44vgdtwo +phtfxkmbfbm61one4pxnvnvld6 +hfsmptwo6dtlnfnmtmrpgmr +jgrbttcmfkkbrdeight846dzgdjxd3 +jdsfprdmhpvzqbgjdgdvkhmtqzxgm8flhxfive +qj36gfj +3twonine +bszc6bvfkfjbbh +4sevenfive4one +fourhxkhxtvtblsevenonekgnpnjqq46ctvmzkqvxdl +6989hvr4258 +seveneightfivegbzczonerqkdvsfour6 +326sevenoneeightfour +41five8one3 +zrtnkqtqfive91bxfctxnk +t226n6xnrdeight5 +one5onetlzbbxchgfhzgx +five5seven8 +1pnvdbvl2zrjpbkbpthree +tlctwone39zfdqtnjshzjrqkcdnjnszrdfive +snklklhpcclkrtkn2eight15three8 +7threeplhsfsevenbgbbnineftvjbnvxpsm +5dtxxthtphbnc +six7four +djsvntknhnqv2qrvnrz +twosevenbzvfzpbonenine5 +1tq2eightseven3sixvjvnkqq4 +z55 +4mthgcrfbcvphfmglvcjsl8pctb +6jgptkgcl43bthreetjfxchtxlf5 +5zxgktvdnninenine9 +lhdfivevxrgpkpzrzjlg5mk +oneseven4seven6njmkvkpjmg +cblmbxlthtfqfk59three8 +xxcnvsfour298mqqrbcn +lbvmgdpgbd3hgmpthreefourjbdbfvvv5vfqrd4 +vsxshfhftrgpstxtj94xnxrntxnlcgtdjtqpbmh +six7fournrmdgzldndnrgrkxlbtdonemjftskhhm4 +1sixtwoseventwofivezbsdvdqncffourkknlsx +78mqspvdsb2 +teight4skkdlfcsrc38jfjtmfour2 +3pgbppzbmlbsevensix533one +hzrfpeighthjrf4kqttngxfivefivehzvxnzfk4 +18zldlpktnceight +six6lvnt6k +28sixs +348lmkg9one4 +4ninesnqqzoneltjhsjjbnp2 +rckbvndsjm99six2nine +eight5vhjvgrrthreetwo6 +2fourseven1oneights +7threeonethreex +662dvrszddqqtwoeightsixeight9 +xftcvpmkl2threecdqsix48kgfktcdn8 +3rcgdrjcnmb +4three5 +two3twotwonine7ljonezh +17mdbr9ninehhs3 +nchgkdvbm8onebhdtmgdgkqjfour +1eightpqbslptjfgninenine72 +1ghpjmc4q +245seventgftbfkbnztwoone +94gxjjlptflxsvsrxxone +seven3three +7foureight +mxgc6 +sixthree6rrdntczlrrnsnine +9three4nd1eightseven +ndeightwosnlvkv8jdllrtwo741 +threefour6bkscthreeeight +hffoneight96vqkbsgpzvn3sixtxh4ckjlm3 +vc6tnine5mfplhklmv +zoneight35ninefour1q5ssmjtf +rkblg8tzdjhrsdxbcx +kgvqtxzjr56psfour9 +6dtbh67five +qjx4two2ls +hfstd58three65twosbxll +g2twosixvlvtt +sevensix4nineonetvfcctgnj +tkjbktckztwozzstwo7jgxbxxrkzx +8gftwosjkhqxvfpqrsrseven +sevenkphl9eight91onesxjvtfdccd +lcrvslcc6bhzlcmz +bbxdjdfprnjtxhsevendzsbczc6one +one5m29 +h3one +sixtjdgzvfqpjvdthree421x7 +eightfiveeight8sbmspqltvsxsix +four8two +5sixfour94961 +9two6onenjfsnqnmfc +fivethree8six3l +1twokzqnbclbqgtbeightrtwo +7csgktwooneone +75nine8two +fourrj5tfdrlgdzrfptxvnine +four4seven5eight +6onesixtpsgqgk5seven +qpznmcmfgpfqmzvkthdseven93threersxsktrkk99 +587nine6eightseventhreeqmjv +zfssixvkhtlcmltwo7 +8bqvgfnzg +6l2eighttjtgrj1knrtjqrpjd +lmjbs6ninethreeeight58 +1ktxhfzkgrfmtthree +xtmfsxsdfgfivethreefour9fnjcmbdz +vlhlhzsevenonelhql285xccp +3172bndlm4sevenpnz +6sbzqfftqnfourhktmxxqkthreepzkjvfxxfour +sevenfoursix544nineqr +9eightsevensevenqrxjzmmfjnd +ceightwogntfttkkkdpsq3 +gpmtpbchjdpgmkone8sixmhm53 +ndfz9twoonelprmtwoslvvp3 +njrtr14sevenninevmnbone +1q +seven1eight +svstnvxdbmseven9pbfrsgvlhd398 +3ninefivelbcxcfcc +9njgmxpeightpqgj +three6636bbqrtxprjb4onetkkgxxmtv +7ssrrsfourfournine +4one1eightzgcpkgbpgmsevenninetwonetk +threelpmgdpmmsevenxkphrddr5two9 +plpzz4 +91fiveg +fournnjzsnrqzbdggldr9 +llnsix5sevenfive45threeone +xxnftztcbzrptthreervfiveseven9sevenlnxhzvk +glceightwo4eightnineeight9fpbp +six6eightfour1fjlmmqlqszvkbspshcvnjlxfvmm +6sevenfourmnv1qcf2khfjclcsx +fivebsvvnhgcp6jdqrcfreightwohfh +9eight5onerjvcdct5 +jb81onefournine35tftlzn +59sevenpcfninevtrrrhmeight +hkphm7five +8ttb +eight9five85pxv +72threepsixgrvfourgbbgbgprtxmhlz +1pgdjtmkntbjfckgq +9brqcqvqgzgpgtvbtktxkxjnine4 +26fourtwo8 +six3tncnc6pbjkbkgninenssjbgqdpeight +sixrjtfbdlrv5rdmpbqfxfxrccs +kmbcgt81seven9jsnvdtwo1 +9sixseven49hzxlf +jmcssix7onesix +pzttczmzhgtgtvvlhpkv5jnjqnxkhceightfivepnfn +1955xv +sixthree247nine1 +jfdgxhkfour1eight1six2 +threefrdlbmnqrreight4psfonegggjj +391eightfour54nine +95five6 +dqvseven8five +3onetwo1fivexppqsltgtwosfb4 +6fivetwo +5eight4j +7l +7khdvfks5threesix2 +46fivethreezfszfkxctworjgtwoghrtpz +threetwokjdljphg5onefoursevensevenjnc +rddxs722cg +pkpsgblkvsevennstsqvh3twofivekkhzzhqxjjsbvvvvnine +fivethree77one +63twonine727 +sglzpbvhccdvdnzdsixthreem6fivesix +ldmtseven7nkhsqkklmzltxvmkrq1 +59kfncssdeight6three7 +zhltwonejbmfvmsix43 +73twoninesevensix3 +five4three5eightsixgvfour +twovsrjkxtjj5gmbvfiveqmqscfqpsix +sixzdbfgtzk8zhthreecdvvqjbvrcphvhqmlxmfive +nrppflfnine7nd9tfseven +3nrclsix +dveightfive1 +3qrdtsfmktwo +ppeightwo4one3 +159pfsbninezgbpvqggfbfxcqzb9 +lrhzqtjrdxrfpbskrseven5qqrnsh +nine51twothree12 +2six5fivehs +45sixtwothreeone45 +kjkfggmzqxrjl4 +four5five +srtgklg3fjb92seven56mrk +eightzlmsmnthreetwofour324 +fivefiveninepvfsxponextzdmft4 +vneightwonine7ntgxbzfouronetwofzzgkkhtx3nine +ndcvzhxbrqmfjcjpzffourfive4gzkxzzlsqn1fjdb +2799ph +6nine77twoznzbjnjhkqljmsmnj +bkzttcjdmpdclpzmpxj67tfour +6btjcjxsevenfcgbjjsxhmlklvzv +four9vpfpknine +onesrjxsfncglvkzs5tpr +qgf782lqzvqztbqjqrqdnfpkthree +seven8f3four +sevenpkksntfdlqxvqjfgfourztpbglbhmhlfftmxtp54 +6fourseven4eight +9lfcjnfournine +four8fiveseven7threecz +rfnveight9threetwo5three +tml98ckph +z4krthreeeightfour3 +six3fhsixxdpmszsbeighthlgd4 +9hbnqkhsndvsevencrl1six5hzg8 +6two5three5 +qplckfdsgd2fivefourfivefsix +ninebfour26fivetwonem +hmbkjkdtnfnzs6 +325lpxntm +lxtsevenfqpc7jvvtbppczsrmfour +threepfpnbkvq59fgmsrglvcfivenhb +5cmq8vxdn2nine +zpzvknntdf1threefour2zdh +five399kgztnine +nmddfssix3sevendrbt +seven7fivebr5xc +177two +3four38six6 +eight9four +49llmpmzkfgsevenrrbdzk4 +four23ceightxxthtplmk +qmjjvkfd34qkkd3 +foursevenrgjxsvlkz7173kr +three82fivermfnqgcfourtbtnpjfnk +744mpdkhr87 +75qfzxshzphsnineone8 +two6five +fourbhgndsgmceight3 +2one186 +833xjbcqdgmeightfive +pfgt93bkzrzbthnssevenczvkfklkbpgnjt +dlsix8seven5 +4two4 +qtblgfgms6lsctgslddgpnx1cxrmbnjconeslscbqvljpfive +mllxhpd5 +kfvjhcz9seven16 +eight36 +633793 +phqeightwomd27eightqkcltdfourx +2fiveonednjb6ninepznvnhrbvdsdnine +8eightfhjdzzhmct74three +vxps976 +threethreebbninefive9 +6xdttgthree9rpg +fivedfbkffgldktbt6fiveqlxcznqxlgltc9 +4ltnlkdmthree7gcbqnskeightseven +onefournsjgbcn34fouronexjxd +169326srhszxcrn1 +5meight6dfive +kztjjnknine2eight87nineskqjpvn6 +seven3four96 +8four5kkgmppkt +52six8fourvtdrcj7five +9tgbcxcvggv4ninettxjrjv +ninepdmghhq5sixtwo +fivexvfdone14 +foursevenfourfqjqthreefour4qcvqglr +four9sixtwo48 +pzvrgmbvngtvcmmgthreepvb7sevenfvhxchplsfsdcltwo +gkrnmzzrd3 +nine2qzgltqninelrnlrjzn923kkpmpm +7tts7qmbthree4539 +sevenone9ghdb8 +jvcc18fourninetwoqvkg7three +four4onenine +19vbsdkslnn6sevenktkqmcp4 +n6 +7psthfqcfd +99nineeight861 +1four3eightbkfnrdcqdqdmkgfzbbn6 +27nlcslnseven5hdvsix8 +9nbzzjjsvtwoxg3seven3nine +7sixnhldjcjfsgvpxrsnxtcblpgvcvjrmkhzx +2726nsdtb1 +2five3six5three3mhnclq +sevenfivetwo1fivekpxrpjkgktwo +7one4tnkqfvqlmjrzlqflnrsf +nvlkqzjt2nineseven28 +ltqschggjgrrxbtfz3onesevencpzbffbvzhpgzmlmxxbqjrtxc +518sixeightwop +cctwonetfmvjx78 +2jvrvcsevenlglmgblbfive +7seven1fivevlbhbsk +48one4cn6 +3one6 +nine4jrlbhnpsixvkrcqvzsjj7 +5twochgfgdsevennbmzmxfcrqfeight7qqkhqlrpdf +71mxlhzstppmffour1vrtd +82xdqfourkgbmzninefive9 +ddcxpmzfljmfrqz3 +five5kcdcxpl3four6 +4lsfzhbc8 +ninec5jnccxhzdtmtcdjhdrvktgtjjlbnsn +29mqjflc +9nine3 +79sevencnj44x3 +4fivenine4three +1lv +fourfour8 +78xrszkgvptd +htmhxvsmppgxthreethreeeighttwo9 +nntjqhnprfdknfs43ngmk4five3 +gqncsix2rxxkjdschstwodknkninefivebfgq +eighteightqg777579 +5ftkjlz7 +qfqsix7 +three79kk5vnd4gvvpjb +dsbxmgs2frm7eight +2kvlnkrbxxm2seventwosix11 +nvneightwo8 +5seveneightxvspone +fiveqhls26498 +1snrdfgkc +425jqfpteighttwofive +8rsxmqsftrccbfour +7lb82vxzfk4sevenfive5 +sevenhstzcvvtnjninehhtlnkrldx8pjsxkrlcjdfivezkqdfour +8six3dmr6shcm +6573fjkfndqrksixnine8six +twombmxvbcnine1mzhltonefdlp9 +sevenqzvbpsslz5rone +8fdllsixonetglrngmdnvbsvjgflzonetwoseven +8nine6eighthlkj2 +5rpx52 +xseven69bbj1 +qrthree8hkgcsqlrcf5 +jhfrvzb5thgmbtcg +nntfour97vgknr +ltwone4hsrctbkfsz9jsfbhkm1seven +mgxnbgst84sevenfivetwo +gzdrfhqfcfdhxthree6sxxnmntpkz +3ninepkzhfq1 +fouroneone7 +8threetwo56bpjjps +4dvnttthkpgpdmcldvfour8two +2k +twomvx81fournbts47kkzggffpp +19seven +xcbhbdlrdfthreejxjsngllfkfive6pll +52nine8xffndctr1one +dvqh7eightdnlmntwofour8 +5rfsvhh21vmcxrftwo1 +rxfddhhxzlnlfvrk3eightzzhpthree +92twofhzeight +djxldch5rxkpzxtcn2smb +2nineninetmhkstmpcprcj5 +brtronetwothree65 +4four6one +7npgvjpr +sxvvbhvqcrftwo4fourrtjdnmk6 +gv3twofoureight3qlhtjbzbqt9six +rlbrgkrsz818six3 +fourcnsbr3rnzcggxqblhqjonesevensevensix +threenine5eightbx +klqrlnvgseven22vdrlvbseven +jzcnxdonenineseven4fivefourfour +4dxjsvlcvslqtmqpcfbbkqhfournine3 +3vtjzclgklnszrv2sixddkcqgbxptrdhnlntrnr +one388qzqhmpzqlqtwo5four +sixnine441sgd9blsvbpnhpsds +732twothree +sevenqrvrvttnld9fqvvpgpnine39 +threetwofour28 +twofiveksvbnzfmzcbvqrnhsntstbrhf3 +fjgcdtfn3 +xgccx584six +2xsevensixtwo4six +xpheightnzdjgkrdmrjcnfprzvnine6cbtmsseven +nine1fivebgqtvsc8 +dznrlhtfivethree43 +sixthreerlmtvs7kkvtcx42rgpnljbsp +4frckxvvrd +eight4ldhkggpg +z57sevenxpfgntjnphcntj3bv +nthvgtxcck39vkpf7 +64vzmzlvgeightonefive1tlvfggflj +fivejrjqzsfxgpdfbvcf58three1two +nine5five +ssphtp472xjfvlvzdl9oneightg +nine5xltblt9six +six28eightts5cckgvtnzmdgftxnine +tvhxmfeight7 +zdnkjgcs43two9 +q35bvblmmqhmnine5zeightwoj +gfkpfbn4 +fivefiveone8 +xnsddskzsb6xmfvkhbb54 +nhsjx51ckpbntz +7kzxsgtnk5sixjlzlcsfqsxkxmvgnvthree6seven +fiveseven37 +fourfqxkjct554 +rsseven8zdz8xrxpnxv9rkqcnjcpgt1 +jsixeightsevenrjpcqmdz5threeqfqgfqv +1threesix76tv4twonetgv +twonzhmrjlgvtvcj6 +kxnpphq94three +zone4 +5kp4eight87 +93eight9seven +9zpz7zqxb1ssgkvtbzhrv8 +sixvtdvvxmz2qcvrsnxcmtcszsnrnq84one +ninerggcxmlfqcpjhpjjtlvs5nine1seventtcmvrfr +five24 +vpkf7onetwofive +8twosevensix1 +53fivethreetgzcmzsm3fivefive +twokpjnmsc77 +twofive53mfjjxq2 +5four6fb4four3twocn +fivemvbgtsix55nine +five65rntfvpxpppkznlfour8 +nine42cjtwo +eighttwothree9247twoeightwoxsq +sixlktcgr17six +kpbtwo57fmhdmzmqbt +442dkpxgnine6qbzf +8fourkmzjzltwo +ztgsrqkone78 +dxzsnnsnj1mkctsix4qqbxscdfm9xvngln +four993kql7eightfour7 +pdrtdxmpmm39qkppdjlttdn +ptpvc9mvlhfjkrthree9onesevenfourqbvzhdmc +dddkfcxrkfkphnhmjbrvmzqeightfourtwopzrmh8 +38tt7psevenvgssvhfbzrhllbh +nine7fournine6sixgfcrrmnppj +fivezdmtj1 +ninesix5eight +6eight6two2threetwoneg +ninenineseven4 +5tpcvlsqqgv3fb8fsbtfivexbzdx +sixzxfxjmtm24one9422 +sqbqtjgdr3eightnbjhzmbt +fiveone2nine9 +8three4c3fdxnm81 +seventwovnine4eightmlzhtkfour4 +mfkf42 +7threetwosix5 +1qqgb74eight +ttrrsrsrqjtwo2sevenseven8twofour +onefivefour14hzdvdvvbrz9eight +bkqplctgnine28bptqbpfhgs +1zlhfourlqtljgxztjtseven +64two +gkfsvbgsone8three1ch +mmjqbmrk494qfbhgl9tdhsldsjvjgbq +kdnldkpfqlqsfivelndmxtbdfc5 +9lgtxsc +xzrjpshsslqvbcthreetsixlql3khxbn +three99tcg8nineone +4jfive8thdhvbl8dkr +619fivecthgp8bcfszxrm +onetjjsmm8dtpkm +two62zlkgsevenhqdp3 +8zfgtfnxvjjxgptxkpkdb1gkndcsbgvzxgqg1oneightq +7vnkhnssixkhrklsdbb96 +3sixsix454four +htfxkcvbcbdpmlr42 +5dspnxhkrvtmthreeseven68xnxbcb +fourxmjlnngjv4dcqninebbfprffgzs +three523eight +fnxfctsix1 +6jx6cqbjqmzmz596nine +1three2eight1five +8twoprjjfsthreepqxmhc838 +vlpdsntkqpxqdjzggtjfk8five8dthree +four8nineptrbrtlninecdseven1 +tfvbjctfive49 +four9fivecsqfs +fivefiveggrbf8vcdftdpzhc68fiveggr +sfvhspbgtj2 +seven1two7bvdsq4seven4fmbfs +1hrcsbmcvcthree11 +98two +rnvmdvhrthree6 +3ksnfzfkrlx86dqjlftjdmtjrbfrsgf +twolsxrkone428 +four6eightwokqz +five2sixnine1fourhdhms +six26 +5seventhreedjsgshhtmlmpjk +14shpdfxxxzrfseveneightf +vprv9two6 +nine3xqkpcdqfourfive +dtjsf923fourjdjzzsmxjh +2fivexdvlgrngjbrqdvzx +6f +five191htbfdg2eight +qmfblcvxfzph8two +ppdkvczsthreexhvfslpncbpqrqkz3k +896 +nrzpqk3fivesldclpcbfmdtbbhpxonethreeeightwor +7cnn871 +sevenfgnc58lllvzfmnfqsshvjhqpgvx +6hfrhvklvpp +onekcrcpsjtsndskmbtvmcd1seven +6twoeight5vmdgvhhjsqfourjkns6 +zlgseven3sevenbfgzgpbmhlbtx6fqpb +7pone828 +vc7cjzjc94 +pmmzhthree36twofour4 +q5onesqltxfourkxx8 +fivedsvbdtqkrzssix2six +sevenone2four4pmn +fivesseven47lndonesevenvfdvkp +vfxzlzvt7 +hcqf179 +6eight3 +hmftwone37dzbmone +qonehzfj4 +eightonesix7 +6pfournine +onefivehdt88five +three2eighttwosix971 +xxtffpnkd6mxsjmhbgp2four +foursixmxrsmvhrx97 +dqkc9njlxh +nine2fivexjvsmthree +2597frctprbrsix7nbcnktxpdz +6vvtlzd29ftgmjbjjpscbvkcmfzpcj +bpmnr2kpdsxseven +twofoursix7seveneight +trcfdlp5qnxmdeightqmzd +seventwo7blpfqnsqjrbgzxvzxfourdtstcrv +z54five +llrjhdptlrzzjngrqvksbrmhttwoqfmlntj8 +fhthpcrrthreethree7fourfour2 +sixfzgnfour81threepdpsix +3ddxksjkcxltxgr5one7eight +6tskvfz +1twobsdnmmvzz4three +15ljtrqkh7xmqbmbn +22threenine2fkpzshztdhmdcxdz2 +9seven12six +9ninethreesbqcjqvx +133bphdqcsdlbgmhjqkhdnvtgvfive +1ninezkvjfmmttvldxq +fourxqjxmjvb7 +foureightthree4 +6one8 +two2twothreervhzqnl +3ninesixsixtwo7sixeightone +nineninenine6ps3fourmhkspqqz +bklcqxggmp9ktzvmlvmmeight18 +1onesix2eightnd89szcklv +pttqvhsdxp28htkfttpnfourseven +5eight9xjgzrxqskttjhcb8ghlxjhfourht +eight2l714 +9xcqnbfive6fivethree32 +zgmbvjtwoone4 +rvxfrdhqq4sbsnlrslh +ninethree9two +6sevenmdvsdqxt3vnzdgninejkdjmzngckfcdh9 +jskmdkhhn443onefjdrhqn +2cnkvbd +seven5rh6eightmcpkvcdrcfivexntt +eight1gqtnkdmvsglvkone87 +four8six +67ninecvqcpxpfqphx +3schxdptgtgfjdbsffxg8xmhxvmrnvfive +mlxqgftbrkvgkczkone65two7 +jzrttfghtqonezjpbxds3fiveninevppqqqc +4sevenjqbnpjlhj +4573one +eightclqsjjjss6 +one5sr3klmrccnrhd8 +jczvxzbvvctxdzmcg3sixtwotfvkcl9jqffdh +cjtslmnine8six +rrzktthree3two6eight +sgeightone23five6ninekstjcksnst +6nhkdjm2fouronehrnd73 +two56six +6six2xmczcgbpj3 +fivevdhnpjxcgrmc963 +6746rrplshznckgxrksgczqthree55 +onehxkrhhkczt2pxsfvlgthree +9threelgbzzjxzfsjrmvnvcsqffour +nine7gfivefoureightsix1 +3seventwoseventcbsixllmhlmjbtqtfpfrjqbghd +1eightzdskcnhbm +rlccvmpnzfoursix9 +nine2xbmfourfourzncxtjgkn1 +1264cfmm +smntmjr53sevenmjghvnvhgrhxq6 +7szrqhlmjkfqspnvseven +29krc +hpj37eightgfzsl95gdcdbtsxqh +xcv736 +eight3fourhtb43 +threethree967rlpk4nine +seven2931nhxpkppdv445 +3eight5hvlxjspmsdfivedrfsmvzr +zgvvcpthree83twofcvqnine +seventwo2bgxcnbmzone +threesix5tfthree862 +8brzvkxz +713srdjqdnbbrvxhn4 +3t7fourtwoeightmjqqjbknp8 +btltwonefour2rjmfmlsbmdfp +8sixthree1 +fourthree3sixhphctrfiveonesix +eight11fivesix +ppltwonepcmjdmtc2sixjpqnvpczbmtplqcsz +pfn2 +pfvqrm54mhvzmqmgtwoneckj +rpsevendfv2onethree +46hrhrkkpp74threesix +fsrr8 +7twofourfourcpcbfourfivenine +onethreefive71rfhmtlzb72hzhl +t71three6hdrnfour +llmdhfeight9 +lgzxltwo3twoktxdltzqv +sixhlmbbzlqflq4mlsevenmsdsfqsqvnine +3lpsltdnine +three1sixfour2 +3sixgcdf1 +four21 +84foursixclbmxpctn1bjsl +brsxfkdp4xzvggqbqtxsx6threethree +vccz3threetwoone59 +sixjmpdtc1 +tjshpfbvmllqfiveeightfzvdjsczqxg2 +twolvzsmjjseven8 +2vnbbrtzts9mxzsllltone99jvsxkc6 +nine3qninesix +8qdthreetch +two1ktnbjxqsjsixonepljgnmrgnb +one2one81tsvpvj85spn +31 +one2ninelzpone4 +twofourthreejgdbthree7three5two +2316fslp5 +threettcdspbsix3three2mpkxzspltr +5sevenblffmddx5xmqcbdrxvhmqtwo +1threethreejxplkj +plqqpf3fhsgjclhg4sr +fourone1fivefive1fourpdkjszpcsd +8lhthrsptzbgzllzkrhpqdbkfivedrrtk +1ninefive2threevbflj +4sixfiveeighttwo3threefive +qvcxfrjgm6threetwoeighttwoneg +2bhfpjnxbttwottrvdmpssgjjvqjhkdskmxjqone +18czsfmq +58dlqninerqt4pdjzktspssixlgdxrddt +3sevenrcsqtmfrhk694 +93ninevttdgh +2dxsmtnnqseventwo +onenrdfhqg3six +jfjeightwobstfsln8dvvdmgdhgxx1one7nine +fndrpmkpbtqgk7six8nhfpnv4hfvcjnjh +3hxtvzbhqbhkrtqmphfivej2 +seven818 +czgrscnine3 +3pltt62three5seven +2mvmpqrgdm5 +six52three1sixthreeeight9 +onecbshrmsrpjlkkrrnine7mvx +five34 +sixjlfsixone9nnzhkvldeightfourpbf +four47nine7 +three462fivefour6 +nsixonefivefive6twochreight +9twofourppg9three +lcpggjmppmnkktfvszbl7qmxqrseven +ztwotwothreekdftqtqmpeightznhnine7 +bptgpcxxknsgxbznnxzhnzx59rvsj +8ntnpqdlkfctckk7qbcfiveone +1cvhlrj5five22vrpphp1 +m9bbpngzzrsix +hbflvlnzln9xhfdsfqqxvnzdpzeight +22sixfive1fourbpncphnnkrlzxz +three8fivecnvgtnpmfkzggttcjonerxq +qrfksfzjvseven6xqsmdr3two3svdjjb +48xxtqpnxthmjbzldrv +gblqlbb9rzfnr +onehc78sixsevenonepfchbfmgzp +lptwonefiveb1131 +lzcbfourh9qvtsggsthreejnjjnmtf +1shljseven +1gdghnzhqlseveneightsixsevenmblqvjpxd8twonejm +mzfgmtndztwo3xlvxdcsseven +59hvnjvjgxxtljdsgrjjpzcmxgninenineone +fivetwothreemdjcsevenkcljqpktwo9 +toneightonelb4threetmldjmvjlfrnmkeightctjxdqhrcjczcr +six4jnlftktspjthree23seven1xfbrkh +fourtwo7fourqzmcrseven4 +clrgvbgcbb1twonekgr +9one9hbdmnzldksix +three161vfrdvbh7seventwo +28rxckppjhxn139sevensixmd +sevenfive5twobdxhzseventlf +xm48781four +tdsqpmcfdjvqtzt56nzlbdrm +fglpgdqonemsdljnq1 +5foursvgbnthn +eight14dcvcvgrlkm +nine8kxjvjskbvcdmmbsgcxpheighttwofour +knsplfsix6cqkhsevenlkknhdnvl3 +eight47fnhssqvdt9vzkr8 +dcjx1rzxfk3seven1twovzcsddtckg8 +1onecqxcszfqrcvm5lvpb42four +sqclpndjgf7 +kbxbhrgxsfbljnlbd1lflxpcm298 +nine1one +nineseven1one +9stlxptznqgcbjvdgt5ninesevenlkxsix +xlhl2nine5 +jqpx1gbxrtdv3 +981six +f795bkkjmmddhvm +2ninexblcgmhxxceightwop +twoxkmb9fvmvljzjd +3pgdsc2onestzh +zpmmdf912three +9fivedvn +five23five3 +sixonexxgxdqjsfmeighteight2three +4eightxbss4twotwo +six8mcbl5shdgpglbdrn +4sixthree7sevensevennine +7pknqttzlxfive4 +nineeighttwotwodbdjonethree3hp +3972oneeight7 +tbsqftsbnhbgljmjmk12pmpfplhqb8x +sevenfivesdrsevenfourfive5qfvqsxeight +lxvfv366one3tvlcbfhone +4vqlcfnineghvkfm +qdhfqqeightone3595one8eightwov +rfsdbjkk48xxeight +3fiverbspbvtpg3ninempxcrkfour +37ninehnpdmdqcgvjfour9 +164two +twoonetwoknlffnine4two +eightthree9zhtntdsf5mfsklckp +zrznzfxpmqfive4ppjkjninetwo6seven +9tnztckdmqdmcthreejgxrlhmninermztwo +qoneightsixfoureighttwo2kjlpsf +fournine315fiveone3 +hcrmlngq73eight39four5 +kqtmfsdfxhvhnsxmmbtbk7sixsixfive1xnb +three7eightnine +sixfivetwoeight14eighttszxffvhmrn +7ctxfoursjqnghg5sixtwo +one4b8 +123five8six +two6seven7dplzhncqx +four7ninedqfplv7threenineseven +sixdqjcllsgj28sixsbgcxbdkeightb +415kmxtvpdthree +ninectmc3two +fivefiveseven2two4 +mvsg44fourrxsmdcxpbzslzdhbgqlxeight5 +bxtwoneone7bxxmeight7rp19 +sv2chpqrztht8eightfour8nine4 +dxlgdfqvkdgvdxlcxkht9 +sixeight6ffivethreesix +qjmprhcxdgvrrqdmlzbbpkns8nine +ninedltfrzpq8 +8rjqseven +273phmpjmf26clqgmckqrh +6dqbgzgqbgrhqqmmnjpmvsdbjxkgs +fvpvclz4msmtzdffplbhkpt311ss +zrvhlnhfxnzthree7 +oneonezclqbxxd6ninesixthreefour2 +q7vrltqqtkd9zmxdtcsrtwo +vpxl9zldgphfjk3hz4 +clpllv8cmpgdvbfmp +7xxdlnfmseven475one +6cfgvvzbk863sixzlvv +25vxrseven +5eight4qbztpc3hbzvvpxscgcn5 +eight7bqqtbdqmnine16rh5 +threempjzsmbtj2 +nineseven76kdbff8 +93twoeightwoff +6threefiveone9 +nmmzcpgnjnpzr6threeptconeonetwo +fivethreetwozmrcg5six6 +onesevengrcvnhdlfive5seven +fourfourvpm2lsixfive +2four2three +seven88 +mcxsggtwo1eight5threezqvk21 +tjfmcvsbvcqch774two5 +two51vgfzfszrrcqnggr +threemqkxvthree2 +2jftwothreeseven68 +rhjszm7brmnclrhxsrck +drhxztpvfp9eightxxsdsphrsix13 +6pldmbdxhgrqxd7 +sixxlstqkx9bltfnktdrkeight +vzhpgmtmk5five885jvdxkvmb +fivetnldpkbnqrptone94four +3zqtwo8 +zshvvcjtvbmjpqgljfivebrcsl2six +ninecv2dlhgzteight2 +dhlfdgbgheightqdzk1two5zbggf +eight2t7 +4nqbjfxtklzfour3 +8qrdzcphsvndbszdnbcndfszrhmvzcszzsgshml2zgbgjx +nineqttcd4five4gfjlgktkdlrmctv7 +nine4xfgmfvgg +3mtmhkcsixbbpvzgnklmdxvkrninezlnrds +txsmflhl7qqlcbn47 +six4kvvfour88cfmzds +3sgfourbphmcvxfqqzgfthgnhf6 +3fqgdnqtwoeightlzplmjlptzkfour +9fivenj9sixgtmghntstjp +794jljzxngthreeknjkv9 +513five +ssix8three1twofivegk +ninethreeeight4vfqbgbxf5 +sgxldeight9 +six189 +vdcsbmmcvbfqtgqgfoureight6gdsznd6 +p6 +58ckjgkrstcgtfm3seven +367 +shlnlp9sixvvbctrkqd75fournine +mqltnzcrqmljgmseven3bqqhhjncnmtwotklrtxgbcn +8fdgshseveneightthree1fourkp +8sevendsmpshkthreetwoztwo1qtpdxr +mfive97xs +xdfourmvtxt3twofivenhtznksix +one56ncxzxdfv +sevenklqngxp27jmjpbdsskz +43zlpqsjz51twogdmszvl7 +4v35q +mtwo98xxhxqshv1 +fivethreelcnhjcsr4tnbg +65r +mhfxxgdbthreesix3rdpfksvpxqbjssqmksxbkqxk1 +mnthlsxffourfour6threezcqeightwosk +qjgr1 +fourone7eightqhsrxpjxftwo3 +gd7qlsjvps +one5rsevenonenine +eight95kzddddkmjfbhjtmgpccxqqfbszstxqlplmtbpthree +sixbddthree58 +xfoneight8sevenone3 +fqdhrvone92nine +ffhtwonesmcmlddsix15nineqgkgbgvnj +pdnmmlxzk3814 +trsmkshtfeightnine5 +hjqdjh65twoqrqcxseven97 +66twoxdlmlqrhk7three +m841 +lk4 +591vqcqrdzsddl6 +jgvmbdflph5frnxkkdplseven +fivebmjmlcs75seveneight +fivefour9bcslbnr9fourtwotnzqshcvoneightnz +sevenxbqngpxmpqnxbdmxhsdkkdbb2 +vxqeightwokkdsdcgq7fgjlbcnhlzgjxtcntx +7five4nine7twocbjsctoneeight +fourfour5mqdqfbnineqvksvbtnfive +67four4qrbddqcthree +28vxtbdcvqxrlrqm +2nine4mltwospmqm6three +fmzgbtkbckmtk15seventwoone +5bjnc +two9one5eighttsptkjflxfvzvp +qcnlfjfpdgh8onestone +6kjbqqczjktsixk1p4gzjrcvc +crdhznlrrc8qmrgpvlrd3573 +five55twofiveqhxmlnlscs6 +onegrcxflkqb6fourtwochltwokpnxtxmzfive +five6qcbjmffzktsmhzzdtnqkc +919eight +pboneightseven9rppzrmdrcfive75three +gdjtsgbjzkgxbnzk9qpgblmqsmssvqzcpmffneight +vbfrxninetwofive123 +foureightseven9two +53931sevenlcsxmlzthreelnsjtcm +dphhkqnptwot2sk4 +94fourpvfrtgrms +four2gxnc8x +nine9mkfljgc +eightmxj83sfr1 +9qlldctxqttonejtsxhdzjf2nrpmvpgeightnine +1threebjgpnsmltszbjmbvpctvljjzvbjb +cgszmdlcssix56jphvdsbh5 +ljjlmxgtkrqpldbllmjsctfv1sevendgnx477 +94mlgfrfive3rlbv4nine +12tr3kcbtjxfxrsevendjrzgfqb7 +7tlsvjfive3 +fourbgksix9lnine636 +rpvftxcnone2 +bjgtmdrgrrrpxndlmvmgl829428 +hfjjkjg1seveneightflkhhmmd +3one273 +nkkxzlrkgfonesevenfour7twompjpqdsvpp +qctwofive7flqqkmsqplbb7eight4 +9bkshzspgz19vhmsseven +17eightthree4bq +1three3 +rdrxmvddjrdvmczg8fourxgskh4fourddcm +eight85nineone6onehxfcqhdbb7 +5seven8threemvjsmmgmone2 +7five7gfnnfbs4fourfive +47vkfndgnlv16four +1mxdnp147ftrzv8 +1svlfzctbrbjprkmpz4xtbccfxhnvfqmhzt68 +fourqsgxnxthreeeighttwo2seven1nine +57sixsix2sevenvkxrsevencmmgv +5jlkfmtwoseventhreeoneightbsr +zpsevenfouronexftsphg731 +15twosix774 +bbpthreeonenpkknbxn2kdqbrbr +dc7mqnzhmtdfr18 +fivefivethree75two7three +lbqvxmgfivenine3ninefive1 +sgpnsmdqb5seven8eight +hclzmmbt3gthnf +lpxtfzvs6twosevenfour1dxrdnkfive +onektc4three +337 +nflntqzlcfourgbgkcldrvbx8five53 +8nkmkssgmlgmxhvpdgjseven +nine78twohnthree9 +9ninesixgtjqbksix392 +sevenonegfmlxzzrm35nt +xmmrcjtspfive8sixsixt1 +tpbdxblvfqblcqndseventhree22 +2shhzch +fourtwo5ssdmsn51eight +9rvxckfrrvsix +tgfcgdm1qsx3four2eightcctqd1 +kxqfltbrfhpkbsmtthreethreeone3 +zrxprsixfiveone8bvbdmxjzbmthree +fpqjfcpheight4twofive5kpcnntbnnq4tcfbkqh +bhjkzdmmrfivetsxlhthreeddchsix5 +5tck83cseven9nine +two2three +6oneighthlf +572hcvfdbgt9twoonechngccmqc +74eightrvtconebgjbpnqlslcs +nbmntwolntd1zvzplfzthree11seven +kpzfgpxdonesix2fourninefourfour +fbdqzbmjnkmqcgeight5five +425six14two46 +jhctmxconelfkgmprnfourseven8twofkjvlvnjgd +twonrpvnnmvkh2threejzcpz diff --git a/advent-of-code/2023/01/part1.c b/advent-of-code/2023/01/part1.c new file mode 100644 index 0000000..3aace2a --- /dev/null +++ b/advent-of-code/2023/01/part1.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include <ctype.h> +#include <string.h> + +#include "str.h" + + +int main() { + FILE* fp = fopen("./input", "r"); + int sum = 0; + while (1) { + char *line = str_strip(fgetline(fp)); + if (line == NULL || strlen(line) == 0) { + break; + } + int d1 = -1, d2 = -1; + while (*line != '\0') { + if (isdigit(*line)) { + if (d1 == -1) d1 = *line - '0'; + d2 = *line - '0'; + } + line++; + } + if (d2 == -1) d2 = d1; + sum += d1 * 10 + d2; + } + printf("%d\n", sum); + return 0; +} + diff --git a/advent-of-code/2023/01/part2.c b/advent-of-code/2023/01/part2.c new file mode 100644 index 0000000..13aba12 --- /dev/null +++ b/advent-of-code/2023/01/part2.c @@ -0,0 +1,63 @@ +#include <stdio.h> +#include <ctype.h> +#include <string.h> +#include <assert.h> + +#include "str.h" + +char *numbers[] = { + "zero", + "one", + "two", + "three", + "four", + "five", + "six", + "seven", + "eight", + "nine" +}; + +int find_number(const char *line) { + int matched = 0; + if (isdigit(*line)) return *line - '0'; + for (int i = 0; i < 10; i++) { + matched = 1; + const char *p1 = numbers[i], *p2 = line; + while (*p1 != '\0' && *p2 != '\0') { + if (*p1 != *p2) { + matched = 0; + break; + } + p1++; + p2++; + } + if (matched && *p1 == '\0') return i; + } + return -1; +} + +int main() { + FILE* fp = fopen("./input", "r"); + int sum = 0; + while (1) { + char *line = str_strip(fgetline(fp)); + if (line == NULL || strlen(line) == 0) { + break; + } + int d1 = -1, d2 = -1; + while (*line != '\0') { + int num = -1; + if ((num = find_number(line)) >= 0) { + if (d1 == -1) d1 = num; + d2 = num; + } + line++; + } + if (d2 == -1) d2 = d1; + sum += d1 * 10 + d2; + } + printf("%d\n", sum); + return 0; +} + diff --git a/advent-of-code/2023/02/Makefile b/advent-of-code/2023/02/Makefile new file mode 100644 index 0000000..44480b6 --- /dev/null +++ b/advent-of-code/2023/02/Makefile @@ -0,0 +1,14 @@ +all: run + +run: part1 part2 + ./part1 + ./part2 + +part1: part1.c + gcc -g -I../lib/ ../lib/*.c part1.c -o part1 + +part2: part2.c + gcc -g -I../lib/ ../lib/*.c part2.c -o part2 + +clean: + rm part1 part2 diff --git a/advent-of-code/2023/02/input b/advent-of-code/2023/02/input new file mode 100644 index 0000000..f3864e6 --- /dev/null +++ b/advent-of-code/2023/02/input @@ -0,0 +1,100 @@ +Game 1: 1 red, 3 blue, 11 green; 1 blue, 5 red; 3 blue, 5 green, 13 red; 6 red, 1 blue, 4 green; 16 red, 12 green +Game 2: 3 red, 13 blue, 5 green; 14 green, 14 blue; 9 blue, 10 green, 3 red; 2 green, 5 blue; 11 green, 3 blue, 3 red; 16 blue, 2 red, 9 green +Game 3: 17 blue, 5 red; 3 red, 11 green, 17 blue; 1 red, 6 blue, 9 green; 3 blue, 11 green, 1 red; 3 green, 10 red, 11 blue; 12 red, 3 green, 15 blue +Game 4: 14 green, 14 red, 1 blue; 15 red, 13 green, 1 blue; 6 green, 15 red; 7 green +Game 5: 3 green, 1 blue, 3 red; 6 red, 2 green, 2 blue; 12 red, 3 green, 1 blue; 2 green, 9 red; 1 blue; 2 blue, 10 red +Game 6: 5 blue, 5 green; 4 blue, 1 red, 10 green; 16 green, 1 red, 6 blue; 1 red, 1 blue, 13 green; 1 red, 5 blue, 7 green; 14 green, 17 blue +Game 7: 1 green, 8 blue, 4 red; 1 green, 4 blue, 4 red; 6 blue, 4 red, 4 green; 1 red, 8 green +Game 8: 2 red, 5 blue, 1 green; 1 blue, 4 red, 8 green; 6 blue, 12 green, 6 red; 3 blue, 5 red; 8 red, 2 blue, 13 green; 5 green, 4 red, 3 blue +Game 9: 11 red; 1 green, 2 red, 2 blue; 1 blue, 2 green, 9 red; 4 red, 2 green, 2 blue; 1 blue, 2 green; 1 blue, 9 red, 2 green +Game 10: 9 red, 4 green; 1 blue, 3 red, 7 green; 3 green, 1 red, 1 blue; 7 green, 4 red, 1 blue; 1 blue, 5 green, 10 red; 1 red, 5 green +Game 11: 2 blue, 4 red, 3 green; 1 blue, 7 red; 4 green, 7 red, 1 blue; 3 blue, 6 green, 4 red; 3 red, 1 green, 3 blue +Game 12: 1 green, 6 red, 5 blue; 3 green, 2 red, 4 blue; 3 green, 1 red, 3 blue +Game 13: 6 green, 1 red, 9 blue; 11 red, 4 blue, 12 green; 6 green, 9 red, 19 blue; 2 green, 6 blue; 10 green, 1 red, 16 blue; 4 green, 14 blue +Game 14: 7 blue, 2 red; 1 green, 2 red, 19 blue; 12 blue, 6 green, 11 red +Game 15: 4 red, 4 green, 7 blue; 15 blue, 1 green, 8 red; 2 red, 10 green, 11 blue; 5 red, 4 blue, 6 green; 9 red, 8 blue, 3 green; 9 blue, 9 red +Game 16: 7 red, 2 blue, 19 green; 6 blue, 9 green; 8 green, 6 red, 19 blue; 11 green, 7 red, 1 blue; 9 blue, 3 red, 17 green +Game 17: 3 blue, 4 green, 5 red; 2 red, 4 green, 11 blue; 6 blue, 13 green; 3 blue, 12 green, 7 red +Game 18: 9 red, 6 blue, 7 green; 3 green, 3 blue, 5 red; 18 red, 6 blue, 4 green; 3 green, 10 red, 8 blue +Game 19: 3 red, 6 green; 1 red, 5 green, 4 blue; 3 red, 14 blue +Game 20: 2 green, 2 blue, 4 red; 14 red, 6 blue, 5 green; 1 blue, 5 red, 3 green; 10 red, 6 green, 6 blue +Game 21: 10 blue, 12 green, 3 red; 1 green, 14 red; 5 blue, 7 green; 12 blue, 1 red, 13 green; 7 red, 4 green +Game 22: 2 red, 1 blue; 1 red, 2 blue; 1 red, 1 green, 3 blue; 3 blue; 1 red; 1 green, 2 red +Game 23: 4 blue, 4 green, 1 red; 3 blue, 1 red, 6 green; 1 red, 1 blue +Game 24: 5 blue, 15 green, 13 red; 20 green, 13 blue, 6 red; 5 blue, 11 red, 16 green; 6 red, 5 blue, 13 green; 12 blue, 13 green, 3 red +Game 25: 10 blue, 17 red; 12 red, 16 blue, 3 green; 4 green, 12 blue, 10 red; 8 blue, 3 green, 10 red; 5 green, 2 red, 12 blue +Game 26: 11 red, 9 blue; 3 blue, 3 red, 3 green; 10 blue, 3 green, 4 red; 1 green, 4 blue, 9 red; 5 green, 1 red, 7 blue; 1 red, 3 blue, 3 green +Game 27: 1 green, 12 red, 4 blue; 5 red, 2 green, 1 blue; 3 green, 6 blue, 10 red; 1 green, 4 red, 3 blue +Game 28: 6 blue; 2 green; 2 green, 8 blue, 1 red; 2 green, 2 blue; 6 blue, 8 green; 9 green, 5 blue +Game 29: 1 green, 9 blue, 9 red; 13 green, 4 red, 9 blue; 3 green, 8 blue, 15 red; 15 green, 18 blue, 3 red; 16 green, 10 red; 16 green, 12 blue, 16 red +Game 30: 14 blue, 4 green, 1 red; 7 red, 14 blue; 2 blue, 4 red, 1 green +Game 31: 2 red, 14 green, 3 blue; 3 blue, 3 green, 4 red; 8 blue, 4 red, 1 green; 8 green, 3 blue; 10 blue, 1 red, 11 green; 13 green, 2 red, 3 blue +Game 32: 8 blue, 16 red; 2 green, 8 blue, 16 red; 16 blue, 4 green, 17 red; 2 red, 5 green, 4 blue +Game 33: 2 red, 2 green, 1 blue; 5 red, 1 blue; 8 green, 14 red +Game 34: 4 red, 4 green; 9 green; 1 blue, 16 green; 1 blue, 5 red, 9 green; 2 red, 15 green, 1 blue +Game 35: 1 green, 5 red; 1 green, 15 red, 13 blue; 2 red, 13 blue, 17 green; 9 blue, 3 red, 11 green; 7 green, 8 blue, 14 red +Game 36: 19 green; 3 green, 1 blue, 1 red; 1 green, 8 blue; 13 green, 5 red, 5 blue +Game 37: 12 red, 7 green, 3 blue; 12 blue, 10 red, 9 green; 17 green, 8 red, 13 blue; 9 blue, 9 green, 8 red; 4 red, 13 green, 13 blue; 15 green, 12 red, 14 blue +Game 38: 5 blue, 1 green, 20 red; 1 green, 13 red, 18 blue; 17 blue, 9 red, 10 green; 4 blue, 4 red, 12 green; 12 blue, 12 red, 6 green; 12 green, 13 red, 2 blue +Game 39: 7 blue, 6 red, 2 green; 6 blue, 1 red; 7 blue, 1 red +Game 40: 1 blue, 3 red; 15 blue, 1 green; 1 green, 16 red, 2 blue +Game 41: 2 blue, 4 green; 8 green, 3 red; 2 blue, 9 red, 4 green; 4 red, 3 blue, 10 green; 5 green, 3 blue, 2 red +Game 42: 7 green, 2 blue, 1 red; 8 green, 4 red; 5 blue, 1 red, 3 green +Game 43: 3 red, 1 blue; 1 blue, 2 green, 2 red; 1 red, 2 blue; 3 blue +Game 44: 3 green, 14 blue, 1 red; 16 blue, 5 red, 11 green; 12 green, 1 blue; 13 blue, 1 red; 5 blue, 2 red, 6 green; 3 blue, 5 red, 11 green +Game 45: 7 blue, 1 red; 1 red, 3 blue; 3 green, 14 blue, 1 red; 4 blue, 3 green, 1 red; 15 blue, 1 red, 3 green +Game 46: 15 red, 4 blue; 15 red, 11 blue, 3 green; 14 red, 2 green, 2 blue; 14 red, 8 blue, 3 green; 4 red, 1 blue +Game 47: 4 green, 2 blue, 3 red; 8 red, 2 green, 18 blue; 1 green, 17 blue, 1 red +Game 48: 2 green, 4 red, 2 blue; 15 blue, 16 red, 5 green; 14 blue, 2 green, 10 red; 3 green, 13 red, 6 blue; 8 green, 4 red, 12 blue; 15 red, 3 green, 9 blue +Game 49: 1 green, 6 red, 7 blue; 1 blue, 9 green, 9 red; 4 green, 8 red; 9 blue, 1 red, 14 green; 2 blue, 9 red +Game 50: 3 red, 10 blue, 14 green; 2 red, 9 blue, 7 green; 4 blue, 12 green; 1 red, 4 green, 5 blue +Game 51: 2 green, 6 blue; 1 green, 10 blue, 1 red; 3 blue, 2 green +Game 52: 1 green, 4 red, 1 blue; 3 red, 5 green, 4 blue; 1 blue, 3 red, 5 green; 1 red, 1 green, 1 blue; 12 green, 2 red, 4 blue; 10 blue, 7 green, 1 red +Game 53: 12 red, 1 blue; 8 red, 11 blue, 11 green; 8 red, 6 blue, 13 green; 11 blue, 11 red, 16 green; 6 red, 9 green, 4 blue +Game 54: 2 red, 8 blue, 15 green; 4 green, 3 blue, 6 red; 12 green, 13 blue, 4 red +Game 55: 1 green, 16 blue, 4 red; 3 red, 1 blue, 1 green; 12 red, 16 blue; 3 red +Game 56: 4 green; 1 red, 4 green; 2 red, 3 blue, 7 green; 2 red, 3 blue, 15 green +Game 57: 17 green; 1 green, 9 blue; 1 red, 1 green, 9 blue +Game 58: 3 green, 8 red, 7 blue; 4 green, 9 blue, 2 red; 1 red, 2 green, 11 blue; 8 blue, 4 green +Game 59: 6 green, 1 red; 4 blue, 6 green; 4 green, 5 blue +Game 60: 3 green, 5 blue, 1 red; 7 green, 5 blue, 16 red; 14 red, 1 green, 1 blue; 7 green, 2 blue; 13 red, 5 green, 5 blue +Game 61: 1 green, 2 blue, 2 red; 2 green; 6 red, 1 blue, 1 green +Game 62: 5 red, 8 blue, 1 green; 1 red, 1 blue; 2 green, 8 blue +Game 63: 2 red, 2 blue, 2 green; 9 blue, 7 green; 1 green, 4 blue; 18 green, 3 blue +Game 64: 13 green, 1 blue, 6 red; 13 green, 15 red, 8 blue; 5 green, 14 red, 4 blue; 2 green, 8 blue, 12 red; 1 blue, 5 red, 13 green; 7 blue, 8 green, 2 red +Game 65: 7 blue, 12 red, 6 green; 11 red, 8 green, 8 blue; 9 red, 7 green, 7 blue; 14 red, 2 blue, 17 green +Game 66: 2 green, 5 red; 7 red, 14 blue; 19 blue, 2 green; 7 blue, 4 green, 6 red +Game 67: 4 green, 17 red, 7 blue; 4 blue, 6 green; 7 green, 7 red, 12 blue; 2 red, 14 blue +Game 68: 1 red, 11 green, 4 blue; 17 blue, 1 red, 10 green; 3 red, 7 green, 1 blue; 7 green, 3 red, 6 blue; 2 red, 3 green; 2 green, 2 red, 4 blue +Game 69: 5 blue, 4 red; 3 red, 11 green, 1 blue; 6 green, 2 blue; 10 green, 4 red, 5 blue; 2 red, 11 green +Game 70: 16 red, 7 blue, 1 green; 14 red, 1 blue, 4 green; 4 red, 4 green; 7 blue, 5 red, 2 green +Game 71: 14 red, 2 blue, 13 green; 7 green, 5 red, 2 blue; 3 blue, 9 green, 11 red; 10 red, 4 blue, 1 green +Game 72: 1 green, 2 red, 6 blue; 4 green, 4 red, 9 blue; 6 green, 8 blue, 1 red; 5 red, 4 green, 9 blue; 15 blue, 2 green, 7 red; 10 blue, 2 green, 10 red +Game 73: 7 green, 6 red, 7 blue; 6 blue, 5 red, 8 green; 5 blue, 5 red +Game 74: 11 red, 1 blue; 2 green, 4 blue, 1 red; 1 green, 2 blue, 11 red; 9 red, 5 blue; 15 red, 10 blue; 9 red, 3 blue +Game 75: 1 blue, 6 red, 9 green; 5 red, 1 blue, 8 green; 2 green, 2 red, 1 blue; 7 red, 1 green; 3 green, 6 red, 2 blue; 1 green, 1 red +Game 76: 16 red, 3 blue, 9 green; 4 blue, 4 green; 5 blue, 1 green, 10 red; 6 blue, 13 red; 1 blue, 2 green, 8 red +Game 77: 4 red, 4 blue; 5 blue, 5 red; 6 red, 3 green +Game 78: 11 green, 1 red; 1 blue, 18 green, 1 red; 6 green, 5 red, 2 blue; 6 red, 1 blue, 15 green; 5 green, 5 red +Game 79: 2 red, 3 green, 13 blue; 7 blue, 5 green; 4 blue, 2 red, 6 green; 6 green, 15 blue +Game 80: 9 green, 2 blue, 1 red; 8 green, 1 red; 1 blue, 7 green; 2 green, 1 blue; 3 green; 5 green, 1 red, 2 blue +Game 81: 2 blue, 8 green, 1 red; 3 green, 1 blue; 6 blue, 1 green; 3 blue, 3 green, 1 red; 2 green, 8 blue; 1 red, 8 blue, 2 green +Game 82: 5 blue, 4 red, 1 green; 9 red, 12 green, 8 blue; 9 red, 6 green, 15 blue; 8 blue, 10 red, 6 green +Game 83: 2 green, 7 blue, 4 red; 2 blue, 11 red, 9 green; 7 red, 7 green, 6 blue; 12 blue, 4 red, 11 green; 11 green, 7 blue; 7 green, 5 red, 2 blue +Game 84: 9 red, 1 blue, 7 green; 5 red, 5 green; 4 green, 4 blue; 4 green, 5 red +Game 85: 5 green, 13 red, 11 blue; 5 blue, 19 green, 15 red; 17 red, 3 green, 8 blue; 13 green, 10 red; 3 green, 17 red, 11 blue +Game 86: 1 green, 11 blue; 11 blue, 1 green, 8 red; 6 blue, 4 red; 4 blue, 17 red; 1 green, 15 red +Game 87: 3 green, 8 red, 6 blue; 6 red, 13 green, 1 blue; 4 blue, 8 red, 8 green +Game 88: 5 green, 5 blue; 3 green, 10 blue, 2 red; 6 blue, 7 red, 1 green; 5 green, 3 red, 11 blue; 8 red, 4 green, 6 blue +Game 89: 5 green, 10 blue, 12 red; 1 green, 13 red, 8 blue; 4 red, 11 green, 12 blue +Game 90: 4 green, 3 red, 11 blue; 1 green, 12 red, 12 blue; 9 blue, 5 red, 1 green; 2 green, 12 blue, 12 red +Game 91: 5 red, 8 blue, 1 green; 5 green, 3 blue; 9 blue, 7 green, 5 red; 1 green, 3 blue, 6 red; 9 blue, 11 green, 4 red; 2 green, 4 red, 10 blue +Game 92: 11 blue, 1 red, 6 green; 10 blue, 2 red; 4 red, 6 green, 19 blue +Game 93: 1 green, 3 blue, 3 red; 3 red; 5 blue, 3 red; 1 green, 4 red +Game 94: 9 red, 4 blue, 4 green; 1 blue, 6 red, 15 green; 10 red, 5 blue, 1 green; 2 blue, 4 green, 8 red +Game 95: 13 blue, 4 green, 3 red; 15 green, 3 red, 2 blue; 16 green, 8 blue, 2 red +Game 96: 15 blue, 7 green, 3 red; 5 red, 7 green, 17 blue; 6 red, 12 blue; 5 green, 10 blue, 4 red +Game 97: 5 red, 2 green; 8 red; 1 blue, 7 green, 2 red; 7 red, 15 green +Game 98: 6 green, 1 blue, 1 red; 3 green, 3 red; 1 blue, 13 green, 4 red +Game 99: 16 red, 5 blue, 9 green; 2 green, 7 blue, 2 red; 10 blue, 3 green; 9 red, 8 blue, 13 green; 16 green, 13 red, 10 blue +Game 100: 16 blue, 12 red, 3 green; 2 green, 7 blue; 5 blue, 4 green; 10 blue, 6 red, 6 green; 5 red, 12 blue, 2 green; 9 red, 12 blue, 11 green diff --git a/advent-of-code/2023/02/part1.c b/advent-of-code/2023/02/part1.c new file mode 100644 index 0000000..194bf2f --- /dev/null +++ b/advent-of-code/2023/02/part1.c @@ -0,0 +1,75 @@ +#include <stdio.h> +#include <assert.h> +#include <string.h> +#include <stdlib.h> + +#include "str.h" +#include "vec.h" + +typedef struct { + int r,g,b; +} set_t; + +typedef struct { + int length; + set_t sets[64]; +} game_t; + +game_t games[100]; + +void parse_set(const char *str, set_t *set) { + void* strs = str_split(str, ','); + set->r = 0; + set->g = 0; + set->b = 0; + for (int i = 0; i < vec_size(strs); i++) { + char *str = vec_get(strs, i); + void* infos = str_split(str, ' '); + if (strcmp(vec_get(infos, 1), "red") == 0) { + set->r = strtol(vec_get(infos, 0), NULL, 10); + } else if (strcmp(vec_get(infos, 1), "blue") == 0) { + set->b = strtol(vec_get(infos, 0), NULL, 10); + } else if (strcmp(vec_get(infos, 1), "green") == 0) { + set->g = strtol(vec_get(infos, 0), NULL, 10); + } + } +} + +void parse_game(const char *line, game_t *game) { + void *strs = str_split(line, ':'); + void *sets_str = str_split(vec_get(strs, 1), ';'); + for (int i = 0; i < vec_size(sets_str); i++) { + set_t s; + parse_set(str_strip(vec_get(sets_str, i)), &s); + game->sets[i] = s; + } + game->length = vec_size(sets_str); +} + +int is_possible(game_t *game) { + for (int i = 0; i < game->length; i++) { + if (game->sets[i].r <= 12 + && game->sets[i].g <= 13 + && game->sets[i].b <= 14) { + continue; + } + return 0; + } + return 1; +} + +int main() { + FILE *fp = fopen("./input", "r"); + int sum = 0; + for (int i = 0; i < 100; i++) { + char *line = fgetline(fp); + parse_game(line, &games[i]); + } + for (int i = 0; i < 100; i++) { + if (is_possible(&games[i])) { + sum += i + 1; + } + } + printf("%d\n", sum); + return 0; +} diff --git a/advent-of-code/2023/02/part2.c b/advent-of-code/2023/02/part2.c new file mode 100644 index 0000000..697a431 --- /dev/null +++ b/advent-of-code/2023/02/part2.c @@ -0,0 +1,73 @@ +#include <stdio.h> +#include <assert.h> +#include <string.h> +#include <stdlib.h> + +#include "str.h" +#include "vec.h" + +typedef struct { + int r,g,b; +} set_t; + +typedef struct { + int length; + set_t sets[64]; +} game_t; + +game_t games[100]; + +void parse_set(const char *str, set_t *set) { + void* strs = str_split(str, ','); + set->r = 0; + set->g = 0; + set->b = 0; + for (int i = 0; i < vec_size(strs); i++) { + char *str = vec_get(strs, i); + void* infos = str_split(str, ' '); + if (strcmp(vec_get(infos, 1), "red") == 0) { + set->r = strtol(vec_get(infos, 0), NULL, 10); + } else if (strcmp(vec_get(infos, 1), "blue") == 0) { + set->b = strtol(vec_get(infos, 0), NULL, 10); + } else if (strcmp(vec_get(infos, 1), "green") == 0) { + set->g = strtol(vec_get(infos, 0), NULL, 10); + } + } +} + +void parse_game(const char *line, game_t *game) { + void *strs = str_split(line, ':'); + void *sets_str = str_split(vec_get(strs, 1), ';'); + for (int i = 0; i < vec_size(sets_str); i++) { + set_t s; + parse_set(str_strip(vec_get(sets_str, i)), &s); + game->sets[i] = s; + } + game->length = vec_size(sets_str); +} + +int power(game_t *game) { + int maxr = 0; + int maxg = 0; + int maxb = 0; + for (int i = 0; i < game->length; i++) { + if (game->sets[i].r > maxr) maxr = game->sets[i].r; + if (game->sets[i].g > maxg) maxg = game->sets[i].g; + if (game->sets[i].b > maxb) maxb = game->sets[i].b; + } + return maxr * maxg * maxb; +} + +int main() { + FILE *fp = fopen("./input", "r"); + int sum = 0; + for (int i = 0; i < 100; i++) { + char *line = fgetline(fp); + parse_game(line, &games[i]); + } + for (int i = 0; i < 100; i++) { + sum += power(&games[i]); + } + printf("%d\n", sum); + return 0; +} diff --git a/advent-of-code/2023/03/Makefile b/advent-of-code/2023/03/Makefile new file mode 100644 index 0000000..44480b6 --- /dev/null +++ b/advent-of-code/2023/03/Makefile @@ -0,0 +1,14 @@ +all: run + +run: part1 part2 + ./part1 + ./part2 + +part1: part1.c + gcc -g -I../lib/ ../lib/*.c part1.c -o part1 + +part2: part2.c + gcc -g -I../lib/ ../lib/*.c part2.c -o part2 + +clean: + rm part1 part2 diff --git a/advent-of-code/2023/03/input b/advent-of-code/2023/03/input new file mode 100644 index 0000000..28e848f --- /dev/null +++ b/advent-of-code/2023/03/input @@ -0,0 +1,140 @@ +..975..95..................717..........................................747................................................622.............. +................/47...........@....701...610.........252.660*.............*..236.....323..........108........653............................ +.......69............313..............$...$...*....@.........640........81.....*................................*332..92.................... +........................*...210.............767...912...367.......505.......817..................*.........478.........=....223.....568..... +..76...968............108...@.....556.....................=..........*...............412..313...575......../...........................*107. +............773/..891............*....................744.....805...14................../..../................320&.567..#................... +.962..708............&........399....146.....385.................*..........825.......................................-..655....485...-..... +...*.........+..........................*76...+..................242....997..*......185..........207.390..870...883............*.......337.. +....929...299....................*.................249........-...........*.373.....*.............*.....*.*....*.............549............ +................196.745.996...364..............409...-.926.....273.....580.........31...........545..547...862......810..................... +................*.......*..............900+....*..........*........586.........936...................................*.........673.......... +.../..........864.683.215....*......%.........702..166..46..........&....341..........694..496.......528.%...........839...105..*...887..... +....506...617.....*........51.807....942..424...............................*..........@..+............@.84...................*......=...... +...........@....594.........................*..........*675...........345..52...$..................-..............899.........804.$......... +.362*366.................487+.48&.......600..180....845........................535...18...........397.#908....432*........229......346...... +.................*................835....................578......*502...............*..416.............................................391. +....610&...514...501......./........*....*71.........../.......674......925...............*.869.....966........393................/.687.*... +............*...............786...248.104........92.633.....%..............*104...&466..138..@.........*.525...+......974......339..=...260. +....372/.889..............................55.406........134..250.=228..609...........................69...............*..................... +...........................................*........976...*...........=.......357...........................191.....150..................... +...-...........595.634.........*396......592..594......*......411.856...760....../..................201.....#...709................168...... +.936..236.........*....@....436.....100....../......35...../.....*........*....................917%............*.....................*..#63. +.......*..............542..........................*........689.........26....667.&...................738....831..$.............513.53...... +........10.....529........*250..........162.......390...........................*..70.............................701..........*............ +..355.........&........394......301@..........542..............................142..........%..............%..........*.....507............. +.....*.........................................*.....%..283.....*.........997&.......@670....402..........808......308.459.......712...152.. +..291......246.@....+986.....336/.......976...468.264...*....739.187.............................................................*.....*.... +........../....46...................186.$..............674............................227......-............975...............436.......492. +.491........................810.......*........................772*.........742........%....198.....*702.......*.596=....64.......=......... +...................706......=......415..................=.199......235......*...47........................72.607...................443...... +.214..............*.....771.............302...........230..+..............810.....*219.606........912.....................=................. +......277......320.............937.....*.....+....632...........&374..............................*....................898.....642%......... +.........#....................*.......716....229./.........................$................934...233...............98............../....... +.....*........-659..457.........964...................659....786....619.666........277...@.....*......930*460..618...........910..265....... +..845.877.343......................*537.../120.......*.......*.....*.................&...175..631.............=.................#........... +............*....................+................@...35.949..34.381......273...880......................451........326..................... +............876..880......827..733.......645.......38......*.........402.....+..........902....459.775........837.....*.185.......813....... +........578................/............*...............622..18.........*234..............+....%..........448.......935....#.............350 +..........*...468.....546................588....146=.........*..142.795..............*424................../.....................=.......... +........245............@...746.......362..................970......*..............593...............487.......+.............709..593........ +...990......&415..............*381......*.....................435.......214..908..................*....*.....351.....876.25....*............ +......*............293*.....%...........271.............135......*......=........540............177....604...........&.....-.46..........166 +...609.....................910.................@........$.......321..........141....+.45.....................750......................98.... +.......#....779........944.....653...........797...........788.................*......+....164.724....475&...+.............-.471......&..... +..794...487....&..81...........*...................@............666@.....*981.937.............*.....%..........888....+...81................ +.....*...........+......694.............748...104..859..............................675.434.......290.............*..352........353=..$..... +...619.977.........859..#....235....230*......*..............429........335....-.......*......631.......=.......27...................192.... +.......*............=...........&.........121..680.195.959......*417.....*..938.............../..........739..#..............194.750........ +....309...439.............14...............*..........*...............723.........163..748...........853.....885.........175*........487.... +.............*707..-626..........464.....382................356...........868#....*...*.....13......*............450............#.....*..... +........216......................*...619......$..270........*.....892............25.494.841*.....971.............*............157.+...119... +...#40...../............343..559.425.......536........718....739...#.......284...............726.....985..136...597.621.173.......203....... +................383............/......................*...................@....348............*.....*.......*........./...*...811.......*158 +...=..............$......@....................776.829.85...&........541.......*....*...&....700......341.995.....73......114....*....267.... +.700.203....591.*.....924..........$217.......@.....*.......590....*.........812.579....517.......................*.............730......... +......#......*...586.........312..................806............435...259...........................573........453.282*132.243............. +..........224.................#.......468@............-...%.............*..............453...................$.....................-........ +....................................................227.673....881......828..&.....632*...................589.....................284..-.... +.....680.........871....17+................117.................*.............506..................#...410...................616.........519. +........*..386................78*762.........@........28..557.655.......359........-............124..#......&..........843./................ +......724...*..584.....552............................*...&.................209..857...633-..............602...932......*........132&....... +..........41../.........*..........................#..427.............=370....*................................*...353...902...........529.. +.....................150.......868.......370....549.........779...................284...........431.....3.....889.............189..103.=.... +.......530..355..........442...*............*63............+.......852.....935.....*..............%.....*..................@....*.-......... +..........*...*...976.....*...500....@...........572...........940....*990..*....627.790.................460..904..601-..821..930....699.... +..........643.824.......248........358...4.........&..301.........&........538.........*.%436....565..........*......................../.... +.768..$.....................186..........*...178........*.......................*.&520..............%........782..........497.-......*...... +......762..828*...972......*..............3.*.......................@....../..836...............278..............666......*...927.413.185... +....&..........40.......86.122..........&....450....................1....202............42...51....*..............*.....215................. +.353.................94*.................995.....655.....520...828....*...........612..........&.119...........486...............713........ +.........................255........................*.......+.....-..463..........*........235........836....................668............ +...................................................286........338........=.393....398........*....199./............631..........*631........ +................64%....704...928.........470...125............*....708.15...*.............193.......*........641....*......687.............. +........$..............*...................&.....*..........582......*....652.@358..643..........125.....458........168....$.......$194..... +........293.........305......417...............117....................612............*......262.............*903............................ +.....$...................615*..........581.........335...139..505.419.............656.........+.......506................710.....956........ +776..110.....+............................-........#..........*....*...447......*......................*...*.....938.366*.......#....376.... +..........366............844....305..761......780......560........236........725.272.....450.............67.126.....................*....... +.................669$.......$.......=............*220./.....+665........495................*.@103....992....................&........600.... +.......*......................812/.........................................$............940...........+...................146...975......... +....410.650.282.....*...............696.833....957...............996...*......772.287...................921..935................%.....$..... +............*....413.921...713....................%.....769.........@.390.216..#.....@..........................=...........*.......46...... +.....798.136..............%....150.....236..............*......31...........*..........@.64..17......616..........901......344.............. +..............................-........*.....402......873.......*......692...592....390...*.............*277................................ +......539.....799.../.....272....%.@....694.#.............667...318.......=...............762.......71%.......-153......................531. +..........556*......573.......465...916...................*..........602.........................=.......145...........................*.... +........................451.............../....%.....625.401.........*........428-.....493......479.427....$.........60......951......281... +..947+....36....270....*............517....521..258.*............108..812.............*................*........................*372........ +...........*....*....957.823...290.....*.............415..........*...............908..730..........589......+.............................. +857.........843............*........794......................677..27........................121...........670.........548.837*....&.....664. +......175..........-.....=........................422.......*..................226-..344.......*...................2....%..........474...... +...................283..190..@...........458........*.162@.666.517....202...............*..@...545.%.........705.............*.............. +...............*............296.466.....#.........................*..*.....852..208...999.475......256..........=....642..188.386........... +............504.888..................52....416......394...349.....53.953...*......*...........@521.........213........*..................... +......225...............272*32........*.....*..........*...%..............728.........827.513..........287*.........924..388%.........&..... +..453...*..................................71.....*..437.......501...869.......928....%...#....................%225.............734@..157... +....*..400...........810=.300@...13.15.537.....997........./......*.....*.........+.........407.758...674............604....500............. +..970..........409...............*...*...*................159...788....338..............636*...../....#.......#895....*......./............. +..................................52.....872........+...........................-........................524.........297............314..... +...........=...469.....408.............&.........641......364%.780...526.........540.865....742............*..............549..505...*...... +........404.......*...-....58..%....577...............655......*.............613......*.............343..779./854............*....*...567... +...103............284......./...999....................=.....640.....284..............566.982..........$...........476...478.793..556....... +......*.....436........916.................941.............@.........&...........284.........*183.........857.953........................... +...............*.404=.....*910..703@...20......266......815.....201.....54.332...........................@......*...........95.............. +.............898........................*........*..........13.....*806...*.......280.........................905........63*................ +........&.........642..271.627..920.+....534...96..780......@....=...........246../......99........................................../...... +....$....518.......@......*......*..323..............-............477....*4...*...........*....979......810.................366....697...... +.....439........................364.........161..594.....647..................802.........234..............*17......125..82....*............ +................187....667....................*..#.......*.......*................604..................946.............*....414............. +....585...218.....*...*.............-....536.396........950...200......296*935...*..........#...382..........883......182.......326....*.... +.....+......-...557.349...........217............................./105..........527..387....394...*...........#..430*.....501.......393.190. +.......*474.............16....................675.....999..............362..............*..........576...................*.................. +....449.....+.296*468.....................607....*...........-..#.................619....177...............31...........194..198..187....... +.........156......................330.......+..332...631...936...477................*...........658..........%..845..........*.............. +....*262.........$......362......*.....429=..............................*324....296...........+.......161.....*....57.....309.............. +.403............492..97.@.....695..696......$.840..&.................21.....................@.........*.......178...+....$.............364.. +......178..692*.....%.....82..........=...176.......456.....517........+...238.704.......682......266.................&..222..........*..... +......*........993........*....931*...........445..............*.................=...........@...*.......448.......251................222... +.......824............467..232.......664..299*.......322*512..850..............@..........585....259........$..................&............ +...458.....572.................379....*........123.....................-........298..................-................336...908....*........ +....&......*....&..732...701/....*....440.....$...........739..636.....65..../.......%151.............823.455............&..........119..... +........550....391..%.............259....................#....*............834............232.179............*.........4...795.784.......... +.............%...............729...............568.............936...............952........*..*..............726..........*.........-...... +...627.....87....@...........-...........6.....%...106.......................458*.....281..811..282..500..............=....833....214..780.. +..............320................665..............*........584.........................*............................343...............*..... +..................997....84.590.....*795.90*487.842..%431....*.......233..692....259....391.113*........*338............./..391............. +.....62.....#689.*.........*.................................444.......*...*......*.............445..861...........498/.857..*.....505*..... +......*...........436.869.....634@..663...599..901*678.100..........666....301..493.986....174.............838*492..........454........313.. +.....362.....983....../................+..*.............=.............................*....*.......259.............+....464.........27...... +...%........................580....68.....45.........................................21..768...267....*.+....661..879..@....&......$........ +.643....545......./435.....*.........+.............................823....919.......................20..102.*..............267.690.....55... +.........*...............557....247.......653....584.5*....430....*........../...529+...........856..........305.254..212.............*..... +........945...528................/...775..+............204...-.537....$..528................276*...................%....*....863......612... +....572.......*.........614.........+................................810...............842........438.....26...&.....%.........*............ +.......*....201.@......*....671..$........................../.............................*...832*.......*....214.899..........795.421+..... +994..797.........684.390....*....452../..................989..728............685....23+.856...........498.............443................... +.....................................424.......%...............@.......228.....+..............+.......................$..................... +.....2...812.517.........602*967.........262....953...*.....*....67...*...........+......1.431.....721.....402%..&.......*.....504.......... +.............*....%..................963*...........96...287.255.*...548.........534....*.............*..........896..531.789.=.......855... +...........579....595...........8................................781...............................547...................................... diff --git a/advent-of-code/2023/03/part1.c b/advent-of-code/2023/03/part1.c new file mode 100644 index 0000000..4ae9ef9 --- /dev/null +++ b/advent-of-code/2023/03/part1.c @@ -0,0 +1,130 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <ctype.h> +#include <assert.h> + +#include "vec.h" +#include "str.h" + +void* read_input() { + FILE* fp = fopen("./input", "r"); + void *vec = new_vec(); + while(1) { + char *line = fgetline(fp); + if (line == NULL) break; + char *stripped = str_strip(line); + if (strlen(stripped) == 0) break; + vec_push_back(vec, stripped); + } + return vec; +} + +typedef struct { + int line; + int column; + int value; + int length; +} num_t; + +void *parse_nums(void *schema) { + void *nums = new_vec(); + int j = 0; + const int IN_NUM = 0, IDLE = 1; + int state = IDLE; + for (int i = 0; i < vec_size(schema); i++) { + char *line = vec_get(schema, i); + int line_len = strlen(line); + int value = 0; + int length = 0; + state = IDLE; + j = 0; + while (1) { + char c = '.'; + if (j < line_len) c = line[j]; + if (state == IDLE) { + if (isdigit(c)) { + state = IN_NUM; + continue; + } else { + j++; + if (j >= line_len) break; + continue; + } + } else if (state == IN_NUM) { + if (isdigit(c)) { + value = value * 10 + (c - '0'); + length++; + j++; + continue; + } else { + num_t *n = malloc(sizeof(num_t)); + *n = (num_t){ + .line = i, + .column = j - length, + .value = value, + .length = length + }; + vec_push_back(nums, n); + value = 0; + length = 0; + state = IDLE; + if (j >= line_len) break; + continue; + } + } + } + } + return nums; +} + +int is_symbol(char c) { + if (c >= '0' && c <= '9') return 0; + if (c == '.') return 0; + return 1; +} + +int is_a_part(void *schema, num_t *num) { + int line_len = vec_size(schema); + int col_len = strlen(vec_get(schema, 0)); + for (int i = num->column - 1; i < num->column + num->length + 1; i++) { + if (num->line - 1 < 0) continue; + if (i < 0 || i >= col_len) continue; + if (is_symbol(((char*)vec_get(schema, num->line - 1))[i])) { + return 1; + } + } + for (int i = num->column - 1; i < num->column + num->length + 1; i++) { + if (num->line + 1 >= line_len) continue; + if (i < 0 || i >= col_len) continue; + if (is_symbol(((char*)vec_get(schema, num->line + 1))[i])) { + return 1; + } + } + if (num->column - 1 >= 0) { + if (is_symbol(((char*)vec_get(schema, num->line))[num->column - 1])) { + return 1; + } + } + if (num->column + num->length < col_len) { + char *line = vec_get(schema, num->line); + if (is_symbol(line[num->column + num->length])) { + return 1; + } + } + return 0; +} + +int main() { + void *schema = read_input(); + void *nums = parse_nums(schema); + int sum = 0; + for (int i = 0; i < vec_size(nums); i++) { + num_t *num = vec_get(nums, i); + if (is_a_part(schema, num)) { + sum += num->value; + } + } + printf("%d\n", sum); + return 0; +} diff --git a/advent-of-code/2023/03/part2.c b/advent-of-code/2023/03/part2.c new file mode 100644 index 0000000..a5ab825 --- /dev/null +++ b/advent-of-code/2023/03/part2.c @@ -0,0 +1,149 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <ctype.h> +#include <assert.h> + +#include "vec.h" +#include "str.h" +#include "map.h" + +void* read_input() { + FILE* fp = fopen("./input", "r"); + void *vec = new_vec(); + while(1) { + char *line = fgetline(fp); + if (line == NULL) break; + char *stripped = str_strip(line); + if (strlen(stripped) == 0) break; + vec_push_back(vec, stripped); + } + return vec; +} + +typedef struct { + int line; + int column; + int value; + int length; +} num_t; + +char *compose_key(int x, int y) { + void* ss = new_ss(); + ss_add(ss, "%d,%d", x, y); + return ss_cstr(ss); +} + +void *parse_nums(void *schema) { + void *nums = new_vec(); + int j = 0; + const int IN_NUM = 0, IDLE = 1; + int state = IDLE; + for (int i = 0; i < vec_size(schema); i++) { + char *line = vec_get(schema, i); + int line_len = strlen(line); + int value = 0; + int length = 0; + state = IDLE; + j = 0; + while (1) { + char c = '.'; + if (j < line_len) c = line[j]; + if (state == IDLE) { + if (isdigit(c)) { + state = IN_NUM; + continue; + } else { + j++; + if (j >= line_len) break; + continue; + } + } else if (state == IN_NUM) { + if (isdigit(c)) { + value = value * 10 + (c - '0'); + length++; + j++; + continue; + } else { + num_t *n = malloc(sizeof(num_t)); + *n = (num_t){ + .line = i, + .column = j - length, + .value = value, + .length = length + }; + vec_push_back(nums, n); + value = 0; + length = 0; + state = IDLE; + if (j >= line_len) break; + continue; + } + } + } + } + return nums; +} + +char char_at(void *schema, int line, int column) { + char *buf = vec_get(schema, line); + return buf[column]; +} + +void mark_asterisks(void *asterisks, num_t *num, int x, int y) { + const char *key = compose_key(x, y); + void *num_list = dict_get(asterisks, key); + if (num_list == NULL) { + num_list = new_vec(); + dict_set(asterisks, key, num_list); + } + vec_push_back(num_list, num); +} + +void find_asterisks(void *schema, void *asterisks, num_t *num) { + int line_len = vec_size(schema); + int col_len = strlen(vec_get(schema, 0)); + for (int i = num->column - 1; i < num->column + num->length + 1; i++) { + if (num->line - 1 < 0) continue; + if (i < 0 || i >= col_len) continue; + char c = char_at(schema, num->line - 1, i); + if (c == '*') mark_asterisks(asterisks, num, num->line - 1, i); + } + for (int i = num->column - 1; i < num->column + num->length + 1; i++) { + if (num->line + 1 >= line_len) continue; + if (i < 0 || i >= col_len) continue; + char c = char_at(schema, num->line + 1, i); + if (c == '*') mark_asterisks(asterisks, num, num->line + 1, i); + } + if (num->column - 1 >= 0) { + char c = char_at(schema, num->line, num->column - 1); + if (c == '*') mark_asterisks(asterisks, num, num->line, num->column - 1); + } + if (num->column + num->length < col_len) { + char c = char_at(schema, num->line, num->column + num->length); + if (c == '*') mark_asterisks(asterisks, num, num->line, num->column + num->length); + } +} + +int main() { + void *schema = read_input(); + void *nums = parse_nums(schema); + int sum = 0; + void *asterisks = new_dict(); + for (int i = 0; i < vec_size(nums); i++) { + num_t *num = vec_get(nums, i); + find_asterisks(schema, asterisks, num); + } + for (void *iter = dict_begin(asterisks); + iter != NULL; + iter = dict_next(asterisks, iter)) { + void *list = dict_iter_value(iter); + if (vec_size(list) == 2) { + num_t* n1 = vec_get(list, 0); + num_t* n2 = vec_get(list, 1); + sum += n1->value * n2->value; + } + } + printf("%d\n", sum); + return 0; +} diff --git a/advent-of-code/2023/04/Makefile b/advent-of-code/2023/04/Makefile new file mode 100644 index 0000000..122af1e --- /dev/null +++ b/advent-of-code/2023/04/Makefile @@ -0,0 +1,14 @@ +all: run + +run: part1 part2 + ./part1 + ./part2 + +part1: part1.c + gcc -g -lm -I../lib/ ../lib/*.c part1.c -o part1 + +part2: part2.c + gcc -g -lm -I../lib/ ../lib/*.c part2.c -o part2 + +clean: + rm part1 part2 diff --git a/advent-of-code/2023/04/input b/advent-of-code/2023/04/input new file mode 100644 index 0000000..ab0c373 --- /dev/null +++ b/advent-of-code/2023/04/input @@ -0,0 +1,197 @@ +Card 1: 24 76 32 40 51 61 89 6 30 60 | 30 69 24 86 6 8 92 61 51 88 63 67 32 62 15 49 22 77 40 27 89 60 76 58 79 +Card 2: 97 3 51 52 79 8 89 76 10 59 | 59 48 52 76 97 16 92 81 62 25 89 51 54 3 79 18 94 78 8 32 99 66 10 70 38 +Card 3: 8 67 56 82 96 2 21 47 41 38 | 6 83 17 36 8 21 82 27 68 67 7 38 56 42 66 3 47 87 41 71 88 96 2 98 72 +Card 4: 41 83 77 61 91 13 84 63 81 79 | 29 28 85 84 19 83 37 55 7 97 8 11 12 50 72 42 48 92 30 2 27 18 38 89 59 +Card 5: 31 96 75 87 56 8 79 80 49 89 | 32 75 80 56 77 48 59 89 6 67 87 33 14 44 50 49 28 82 79 40 9 31 99 8 96 +Card 6: 32 94 17 27 59 63 7 87 68 53 | 2 37 31 69 17 7 75 53 87 26 51 96 19 63 59 68 34 56 35 30 93 79 89 61 71 +Card 7: 19 40 50 67 3 2 79 33 14 98 | 51 30 70 72 2 20 35 50 94 37 40 74 14 91 33 98 67 92 3 59 79 19 97 75 31 +Card 8: 67 12 63 96 61 48 95 40 73 46 | 67 12 40 63 15 46 33 16 43 92 78 74 95 73 4 53 14 9 90 94 72 13 96 54 61 +Card 9: 47 23 84 63 95 98 26 90 99 64 | 98 95 4 47 1 23 26 11 74 84 36 82 63 60 53 44 6 59 64 99 17 42 90 85 19 +Card 10: 70 82 46 43 38 21 2 98 33 64 | 93 3 64 21 96 80 32 70 79 58 34 42 2 19 39 61 46 31 88 43 87 54 67 69 9 +Card 11: 44 79 34 75 85 94 2 81 55 66 | 55 85 6 58 72 51 37 44 29 79 39 66 49 48 75 15 83 81 2 24 94 99 34 59 33 +Card 12: 74 34 8 69 16 83 80 97 22 29 | 96 97 5 87 50 84 94 19 93 52 40 46 15 7 41 37 98 12 16 56 65 95 27 90 54 +Card 13: 2 56 8 43 13 72 33 11 36 29 | 57 40 14 35 18 65 78 87 58 84 51 2 43 61 37 66 30 10 39 60 64 54 48 9 15 +Card 14: 43 84 95 53 44 69 9 94 5 17 | 65 74 88 75 81 10 62 83 33 51 76 26 89 94 80 17 56 42 21 6 87 1 46 95 9 +Card 15: 57 7 28 1 5 11 81 43 69 34 | 52 49 8 91 34 2 29 74 94 81 77 58 11 83 96 43 40 55 89 27 10 30 7 57 28 +Card 16: 6 14 70 53 54 52 26 72 59 42 | 37 52 60 53 86 49 91 33 4 77 64 51 23 85 89 10 42 8 29 66 61 74 99 26 87 +Card 17: 10 86 55 81 40 23 25 67 93 59 | 68 62 15 32 54 85 99 5 10 2 56 38 64 11 55 84 50 67 34 12 52 59 76 1 36 +Card 18: 32 90 99 60 31 54 58 78 88 61 | 63 93 58 47 80 60 46 88 21 48 83 31 35 64 23 24 55 91 1 73 45 20 29 77 66 +Card 19: 80 1 28 63 37 42 24 81 99 94 | 15 10 33 88 28 2 16 62 81 72 42 67 49 38 65 95 63 61 24 52 11 6 26 39 70 +Card 20: 44 26 16 4 55 63 33 36 82 86 | 70 3 46 58 41 95 96 73 15 13 99 69 91 75 87 57 92 65 51 38 53 80 14 52 48 +Card 21: 48 36 78 7 17 2 61 54 49 11 | 56 41 84 37 45 62 40 18 35 33 43 57 80 9 32 13 25 46 61 58 55 48 30 11 74 +Card 22: 83 30 3 9 31 13 82 81 15 74 | 64 47 66 39 14 17 10 79 84 62 27 81 73 96 43 42 36 40 70 80 90 41 50 55 16 +Card 23: 84 6 52 97 89 48 62 20 15 53 | 41 66 12 56 86 61 45 38 1 51 31 92 14 96 16 37 67 98 64 57 77 10 73 39 80 +Card 24: 90 8 46 94 95 43 31 74 80 66 | 49 91 47 1 37 48 72 45 29 26 76 58 44 97 20 70 55 77 13 86 19 87 59 4 34 +Card 25: 80 52 16 86 65 84 31 36 49 59 | 95 72 65 80 52 97 59 9 81 2 96 36 86 31 16 8 48 6 50 66 84 49 78 18 56 +Card 26: 32 56 87 82 62 97 42 22 61 83 | 85 29 58 59 48 20 69 50 98 46 60 25 40 52 73 28 66 63 1 6 74 12 88 37 64 +Card 27: 46 65 51 32 83 91 67 52 43 71 | 98 83 43 46 36 71 38 14 30 26 5 47 3 85 61 51 4 91 35 28 67 48 60 52 74 +Card 28: 26 60 29 89 24 28 95 92 78 97 | 39 95 41 34 16 25 62 60 53 97 24 92 77 78 29 68 35 86 71 58 89 12 28 9 11 +Card 29: 66 6 93 49 51 2 48 96 62 89 | 2 17 62 39 6 51 93 18 95 54 72 1 97 66 84 96 60 89 90 69 13 48 49 36 16 +Card 30: 53 95 92 75 76 56 48 87 79 15 | 1 4 97 3 6 79 11 76 88 7 56 75 48 95 60 94 59 36 46 86 70 69 91 2 73 +Card 31: 80 63 37 67 35 98 97 72 87 52 | 67 77 58 66 54 19 87 75 76 51 29 80 53 26 24 49 88 91 52 72 86 81 4 39 37 +Card 32: 67 23 77 16 4 31 24 13 76 86 | 16 6 69 31 51 4 28 83 1 89 79 24 46 38 99 77 43 50 19 87 90 73 85 56 70 +Card 33: 38 41 64 25 96 99 68 58 92 40 | 84 59 5 94 49 6 2 40 73 96 38 23 43 91 47 88 24 17 9 25 35 52 13 92 64 +Card 34: 24 52 69 59 55 8 43 15 45 92 | 56 47 84 62 4 81 88 92 54 96 52 89 42 46 49 33 69 10 51 12 5 82 85 65 20 +Card 35: 19 82 84 29 58 44 65 87 26 32 | 95 63 13 56 77 3 57 17 32 20 81 2 82 76 48 39 71 93 84 8 15 88 89 74 11 +Card 36: 41 13 70 23 65 66 47 75 24 98 | 17 94 89 42 47 9 55 54 48 57 71 69 63 33 35 97 90 20 43 24 18 6 76 82 29 +Card 37: 23 39 77 90 56 47 2 82 66 72 | 2 61 16 48 65 62 77 5 49 35 72 93 22 83 18 3 38 1 14 31 99 54 52 8 13 +Card 38: 99 18 59 51 94 52 44 71 30 7 | 95 31 1 58 94 8 28 18 50 81 59 26 57 82 67 30 17 86 87 79 37 23 10 83 3 +Card 39: 98 3 38 42 18 71 66 80 39 79 | 51 88 43 25 90 27 9 35 29 4 21 10 79 13 54 42 11 61 36 30 24 15 6 65 26 +Card 40: 6 27 58 3 67 72 45 12 63 61 | 36 39 75 2 78 95 64 22 41 93 54 91 50 11 55 74 17 56 92 88 87 89 85 6 40 +Card 41: 37 76 61 43 25 29 89 11 35 93 | 27 30 81 38 62 4 33 92 71 77 6 22 75 76 97 67 70 13 65 96 15 17 36 56 78 +Card 42: 42 7 79 61 98 92 2 95 14 44 | 62 88 67 48 82 59 27 34 6 39 25 97 87 81 37 50 65 10 41 56 12 32 68 30 38 +Card 43: 12 9 34 93 71 99 95 86 87 40 | 6 24 93 79 85 25 90 72 71 13 66 86 9 8 12 50 57 30 39 59 29 34 26 17 51 +Card 44: 24 96 61 97 83 98 10 1 29 81 | 74 43 92 5 1 56 15 60 83 96 50 72 81 98 29 52 49 24 97 90 95 10 84 12 61 +Card 45: 12 29 82 5 83 92 86 51 98 32 | 61 14 28 80 48 55 17 5 19 12 62 27 51 18 86 91 49 58 11 65 13 79 68 98 36 +Card 46: 67 47 77 25 15 64 90 76 16 88 | 64 86 26 25 77 78 56 84 87 76 15 88 36 90 93 96 8 13 67 47 10 16 42 27 6 +Card 47: 97 25 76 83 35 90 53 16 34 18 | 5 26 77 53 36 90 43 61 94 89 41 99 93 92 56 2 10 29 1 47 55 38 66 13 15 +Card 48: 3 75 52 55 41 86 9 54 26 98 | 93 30 12 72 36 62 79 25 61 90 31 87 59 88 27 56 99 6 5 11 58 80 78 77 43 +Card 49: 34 44 25 93 74 5 15 37 14 30 | 8 15 89 36 38 60 9 48 93 74 96 20 44 67 30 97 5 70 86 80 31 25 14 51 66 +Card 50: 93 78 49 98 76 74 58 7 60 46 | 44 15 1 78 67 28 13 36 46 64 49 98 56 12 97 60 18 55 91 32 89 94 99 66 76 +Card 51: 36 78 35 85 27 17 18 42 75 92 | 63 5 62 52 65 71 28 3 15 97 22 99 23 44 16 10 88 4 67 34 80 38 27 83 69 +Card 52: 70 74 14 71 11 83 86 18 99 77 | 26 49 98 94 35 67 31 66 46 36 73 87 10 43 92 7 25 81 62 82 55 39 64 78 4 +Card 53: 14 83 11 94 46 63 42 29 34 56 | 25 71 3 39 2 64 70 5 68 90 32 75 36 14 74 79 10 58 16 60 83 19 54 35 52 +Card 54: 35 77 49 19 41 94 36 83 73 75 | 62 17 8 13 20 98 21 31 88 6 14 30 42 53 59 61 57 22 54 27 74 66 50 58 7 +Card 55: 25 6 23 81 19 51 17 58 29 72 | 12 67 61 97 85 76 2 66 27 1 41 73 78 90 22 10 82 79 39 60 42 72 96 17 24 +Card 56: 23 13 16 27 17 15 9 66 89 93 | 48 67 53 22 96 33 5 25 94 24 43 68 49 77 63 42 73 97 86 83 56 62 36 31 76 +Card 57: 36 67 99 41 58 76 8 72 70 35 | 62 47 69 27 9 48 34 83 50 7 98 78 94 93 15 52 25 84 4 80 24 10 40 91 11 +Card 58: 14 6 7 21 88 32 54 42 56 33 | 55 62 54 7 14 21 88 25 11 80 58 5 93 12 23 86 6 42 33 96 67 61 49 56 32 +Card 59: 61 60 16 27 13 15 17 49 3 19 | 49 94 17 19 15 1 18 37 4 77 55 12 8 13 9 89 64 60 69 22 16 43 27 3 61 +Card 60: 14 95 23 48 96 36 16 77 13 17 | 24 77 53 16 11 36 52 13 26 23 85 50 14 83 96 71 41 48 45 81 95 44 31 17 21 +Card 61: 72 13 69 70 52 8 16 76 3 65 | 27 96 13 37 49 79 70 57 23 86 9 18 65 21 1 72 85 22 16 68 31 24 81 73 55 +Card 62: 28 94 10 97 71 42 89 53 27 75 | 28 97 12 89 2 54 21 42 48 43 91 82 63 10 71 90 38 3 75 27 46 53 94 66 77 +Card 63: 1 36 27 90 97 33 87 9 89 44 | 12 30 97 7 33 5 39 47 14 16 28 83 74 3 38 80 99 20 69 27 85 72 31 18 2 +Card 64: 59 52 91 93 90 38 36 9 98 3 | 98 90 52 92 78 36 87 75 9 76 59 39 53 63 86 29 5 64 3 32 93 80 65 38 91 +Card 65: 78 61 30 58 32 23 1 28 37 39 | 5 35 32 37 1 20 21 70 30 61 93 34 76 40 58 89 27 26 36 28 39 71 78 56 23 +Card 66: 88 68 34 6 60 23 14 94 91 33 | 11 31 50 58 14 33 80 82 99 79 87 40 75 93 88 24 23 6 94 91 63 34 39 38 16 +Card 67: 93 88 20 45 69 97 54 80 43 79 | 2 34 18 85 60 63 30 28 90 77 80 65 41 37 69 94 1 71 59 38 40 50 73 96 64 +Card 68: 20 7 49 18 56 86 8 43 35 42 | 95 86 35 93 94 6 18 84 42 3 20 14 5 54 17 41 88 82 71 24 87 27 43 16 53 +Card 69: 69 46 23 15 97 36 34 24 4 31 | 34 43 6 36 46 4 69 17 97 79 96 67 54 64 23 89 45 76 60 15 2 31 94 24 70 +Card 70: 88 55 97 13 26 68 28 25 92 39 | 55 54 80 5 40 39 84 13 60 14 70 90 92 27 26 31 62 91 23 59 28 97 68 88 25 +Card 71: 76 78 20 57 1 26 42 50 92 65 | 5 88 16 65 92 17 97 42 74 50 71 76 46 57 26 47 25 9 90 77 78 56 98 20 1 +Card 72: 1 49 13 29 14 84 38 73 2 80 | 28 13 92 86 65 89 87 50 98 25 10 30 52 33 40 44 75 21 88 57 5 8 34 70 91 +Card 73: 60 30 20 5 76 59 58 77 44 24 | 43 18 77 24 44 76 41 51 53 4 59 5 84 46 45 35 82 1 78 65 58 95 86 30 73 +Card 74: 32 92 95 62 46 1 12 53 31 6 | 59 35 65 91 39 40 72 61 45 60 98 51 6 66 43 81 89 47 75 19 85 16 69 96 25 +Card 75: 9 2 82 57 36 17 91 11 54 5 | 7 97 11 27 2 36 98 88 45 44 80 34 17 39 31 57 77 73 47 68 62 78 61 91 67 +Card 76: 79 36 67 27 35 90 14 1 43 31 | 26 96 48 32 28 11 87 45 81 71 58 5 86 57 34 78 91 12 51 56 40 84 9 64 39 +Card 77: 82 36 42 46 40 13 76 51 49 34 | 84 88 68 76 11 56 66 17 96 7 72 31 65 13 97 90 9 39 23 93 28 46 78 44 34 +Card 78: 91 20 12 28 84 50 14 94 93 86 | 97 72 58 82 87 67 12 71 50 61 9 35 29 55 39 92 54 7 24 18 41 38 22 49 51 +Card 79: 31 6 69 83 94 47 34 33 23 21 | 11 10 61 35 59 90 7 12 54 45 92 52 19 4 64 24 50 71 73 30 65 36 39 79 15 +Card 80: 70 39 43 66 31 90 27 88 78 97 | 5 76 31 21 80 11 71 53 15 79 55 93 3 64 14 1 96 41 8 4 44 73 91 77 45 +Card 81: 46 69 21 40 35 16 74 50 17 86 | 45 96 48 15 11 20 73 1 59 38 98 55 4 39 24 44 85 13 63 94 92 68 37 10 78 +Card 82: 20 42 3 4 71 63 38 83 51 41 | 66 70 34 61 89 96 91 15 62 87 43 23 28 55 67 82 1 53 35 60 16 29 56 95 54 +Card 83: 78 1 65 82 90 45 55 67 37 15 | 50 40 46 79 1 80 86 94 85 53 84 13 90 17 16 32 21 19 7 58 44 77 57 81 74 +Card 84: 59 82 8 99 1 24 16 48 51 6 | 8 3 22 35 36 58 97 55 73 95 51 48 70 57 84 69 40 66 13 78 5 63 94 49 18 +Card 85: 76 83 7 37 28 79 44 39 92 18 | 65 97 61 68 92 40 80 95 29 91 81 6 62 73 44 21 4 17 28 48 36 37 19 25 42 +Card 86: 72 77 6 23 42 93 19 87 45 56 | 78 21 18 86 73 2 22 9 98 65 87 89 40 7 69 71 79 37 67 20 74 10 34 15 28 +Card 87: 92 72 98 30 24 74 86 52 69 87 | 94 15 60 6 3 5 4 69 33 74 49 51 72 41 76 10 52 67 86 35 34 22 98 92 66 +Card 88: 48 96 2 25 95 28 37 94 45 30 | 38 39 56 22 71 21 18 87 46 14 79 77 43 72 10 89 34 57 58 92 31 5 91 54 66 +Card 89: 63 31 84 20 99 21 30 67 60 38 | 50 29 21 5 1 8 9 14 76 16 24 17 33 42 99 62 96 39 83 32 44 51 23 88 63 +Card 90: 90 96 82 28 20 8 79 94 84 17 | 74 45 12 55 24 94 28 35 4 7 79 57 82 63 84 73 20 10 96 89 69 90 22 16 17 +Card 91: 99 44 27 28 15 66 61 41 54 81 | 77 50 8 26 33 28 61 81 41 15 92 2 66 36 62 43 27 11 58 30 88 65 53 57 82 +Card 92: 35 99 38 22 33 70 65 14 51 91 | 68 35 65 77 78 33 53 99 38 96 87 34 69 6 83 17 30 91 70 20 85 75 82 14 15 +Card 93: 77 42 61 83 98 28 5 34 23 88 | 88 61 20 98 13 36 68 44 5 14 52 80 55 37 25 32 96 58 77 46 28 26 21 83 75 +Card 94: 57 17 27 35 62 85 92 7 65 67 | 93 68 79 95 59 64 10 97 96 35 90 6 5 80 73 85 70 62 19 13 52 74 72 17 81 +Card 95: 38 96 40 36 44 78 28 47 70 90 | 82 47 32 78 9 84 42 62 6 37 68 7 31 97 93 22 11 58 23 63 79 35 98 36 70 +Card 96: 37 66 81 97 23 51 40 31 86 17 | 63 39 23 12 97 55 31 11 47 24 43 8 79 61 49 14 88 53 92 30 94 93 35 60 9 +Card 97: 76 97 35 85 90 70 53 54 40 91 | 22 12 33 32 56 23 59 62 6 48 67 17 65 84 94 96 9 41 68 21 10 61 91 52 51 +Card 98: 99 14 64 51 61 40 30 59 87 4 | 57 53 36 26 78 37 86 7 43 74 44 33 34 58 3 85 67 82 2 94 38 32 65 80 45 +Card 99: 69 79 90 36 45 71 94 43 50 70 | 11 67 31 25 84 57 39 89 34 78 51 68 9 35 54 70 95 29 56 83 63 47 20 58 23 +Card 100: 39 35 5 66 47 37 2 90 20 4 | 56 61 1 57 48 14 96 11 42 98 6 24 45 19 31 49 21 74 53 41 25 95 69 40 79 +Card 101: 89 50 4 33 80 44 14 92 51 28 | 11 51 95 73 80 44 50 89 93 72 33 29 23 60 59 28 54 49 14 75 92 82 7 24 78 +Card 102: 96 88 16 82 75 33 44 72 6 85 | 7 42 68 56 98 30 44 20 62 6 91 95 16 40 18 11 83 13 52 50 61 45 80 74 4 +Card 103: 37 42 77 46 8 41 30 62 90 82 | 70 90 72 8 46 9 35 45 37 41 4 93 99 81 42 14 20 57 85 83 82 30 62 43 77 +Card 104: 59 43 8 48 32 69 58 40 44 60 | 50 17 95 27 44 89 53 34 59 11 72 48 43 64 40 88 3 58 32 60 37 8 91 69 92 +Card 105: 5 63 74 79 60 89 78 95 54 6 | 97 47 24 70 22 92 63 41 67 33 84 16 62 6 52 90 57 82 74 86 46 50 5 32 78 +Card 106: 81 64 44 37 41 36 59 50 20 22 | 25 22 39 11 15 36 90 88 16 59 19 84 20 44 58 63 53 71 29 40 94 56 61 81 6 +Card 107: 69 39 95 35 82 15 84 49 74 31 | 95 76 61 38 64 58 33 28 97 23 35 78 8 5 34 43 59 65 4 26 30 87 96 50 11 +Card 108: 16 36 75 64 66 29 77 12 40 10 | 66 10 83 15 49 40 37 86 9 52 24 50 29 20 23 41 16 25 64 76 56 36 19 34 77 +Card 109: 70 41 35 15 46 74 40 77 42 93 | 82 99 30 12 49 64 70 41 56 38 5 6 87 68 80 26 39 35 63 22 27 23 74 93 46 +Card 110: 6 77 75 51 74 66 45 80 48 73 | 48 87 5 62 70 56 9 96 12 21 83 49 25 99 3 38 44 18 13 2 28 88 58 78 65 +Card 111: 78 28 72 47 41 44 90 74 68 87 | 80 95 90 26 54 48 56 29 96 67 8 98 62 59 63 53 68 5 72 12 18 41 51 14 93 +Card 112: 28 91 33 83 81 73 15 24 21 75 | 39 92 21 52 71 85 89 53 62 33 28 95 43 65 88 78 40 55 34 66 20 12 32 91 29 +Card 113: 55 40 8 1 7 35 70 65 42 41 | 12 80 19 62 48 39 87 89 96 13 16 88 54 63 9 28 73 43 86 33 26 72 35 17 1 +Card 114: 61 15 3 7 35 76 9 66 33 74 | 16 7 38 20 79 70 56 27 99 5 95 39 43 49 73 78 25 11 96 84 85 55 67 91 29 +Card 115: 87 99 8 31 43 82 67 74 76 49 | 91 77 49 41 6 45 81 34 24 72 79 1 60 59 12 10 9 22 96 5 83 70 7 93 63 +Card 116: 27 96 16 90 61 72 73 9 64 35 | 89 55 44 2 11 7 74 76 85 13 48 15 50 40 63 73 31 58 46 8 38 37 10 97 98 +Card 117: 28 83 58 84 81 23 76 41 69 46 | 73 55 87 71 3 20 43 26 7 24 23 92 97 27 88 22 11 6 45 10 38 68 65 5 82 +Card 118: 84 47 70 88 25 20 58 82 7 87 | 52 91 53 26 79 73 85 2 12 86 69 49 67 13 92 63 36 62 23 46 35 95 90 40 64 +Card 119: 12 28 10 43 44 49 38 36 7 30 | 63 84 43 30 10 44 73 98 49 66 86 82 38 36 76 60 20 28 12 3 26 74 7 79 72 +Card 120: 64 47 61 68 90 84 54 10 81 12 | 47 64 10 34 85 7 98 73 68 12 92 42 31 81 54 2 49 4 61 90 84 5 74 93 25 +Card 121: 47 50 44 35 40 60 28 80 23 99 | 15 22 16 93 60 40 88 83 34 89 46 69 57 33 3 98 5 81 28 2 44 54 87 71 4 +Card 122: 46 53 63 32 87 37 49 25 99 73 | 95 65 7 80 35 74 98 30 8 52 84 40 64 36 23 45 67 33 76 96 90 31 39 78 22 +Card 123: 92 37 35 10 89 84 85 16 3 9 | 10 28 15 60 6 21 58 95 75 84 35 99 44 59 37 9 51 91 1 61 3 92 69 85 89 +Card 124: 94 67 68 3 39 78 76 79 36 74 | 17 73 75 29 86 89 72 70 12 6 66 85 13 83 37 42 28 2 84 30 10 95 20 65 44 +Card 125: 28 64 58 33 90 97 7 98 66 16 | 7 66 46 9 86 56 16 33 47 90 65 87 15 32 31 67 64 28 49 17 25 84 97 55 57 +Card 126: 14 22 7 83 85 89 27 39 78 69 | 66 45 2 20 62 38 51 90 11 43 60 57 27 3 18 94 54 59 46 58 37 73 87 12 67 +Card 127: 14 39 77 20 29 55 94 38 88 11 | 55 38 51 87 72 4 69 27 41 68 9 94 37 29 58 59 48 20 17 39 92 19 53 14 16 +Card 128: 43 1 85 87 45 51 64 91 93 73 | 21 13 55 72 14 57 46 43 2 83 62 36 59 33 86 48 68 19 40 54 50 35 39 81 41 +Card 129: 61 90 20 1 76 79 66 18 94 99 | 92 30 20 8 73 28 38 15 13 36 79 1 64 76 33 3 26 88 18 23 93 12 58 91 37 +Card 130: 31 34 13 96 55 85 51 95 54 78 | 6 21 47 48 94 27 86 46 8 25 84 15 43 13 23 76 60 32 58 11 99 1 79 88 55 +Card 131: 71 52 74 6 43 37 73 89 9 16 | 22 24 12 11 76 40 99 87 17 78 61 63 53 75 1 77 25 58 31 23 86 20 97 49 38 +Card 132: 75 27 99 16 5 17 60 1 28 34 | 44 3 82 47 97 30 4 69 23 11 98 46 29 96 81 31 51 7 94 67 83 38 32 73 60 +Card 133: 21 46 70 93 7 66 60 51 63 35 | 4 24 17 62 61 15 9 95 72 43 67 83 6 75 88 12 8 22 40 68 54 76 20 37 32 +Card 134: 55 33 24 47 9 6 86 43 89 30 | 49 23 59 98 72 90 13 93 1 26 78 44 83 82 40 41 71 79 68 57 96 92 48 17 10 +Card 135: 18 88 45 34 65 8 92 37 98 30 | 72 34 88 65 50 30 9 64 8 13 10 36 69 3 22 18 78 35 98 97 81 83 57 92 37 +Card 136: 62 13 33 30 58 9 21 68 54 48 | 55 49 81 38 48 39 75 17 54 84 47 24 71 44 91 37 4 3 10 64 86 92 30 51 40 +Card 137: 49 8 77 76 25 88 39 17 63 22 | 56 71 8 7 17 41 76 74 77 15 88 3 97 25 48 98 64 39 55 49 33 83 63 22 2 +Card 138: 11 36 77 55 53 47 37 76 66 8 | 37 13 24 66 96 35 4 22 53 98 70 50 76 77 97 11 38 8 75 47 51 43 15 36 55 +Card 139: 61 9 64 99 47 50 6 75 45 65 | 9 99 31 10 72 66 45 75 14 47 60 2 64 6 50 65 8 52 58 61 25 38 29 90 19 +Card 140: 79 41 61 71 96 11 60 24 74 95 | 40 71 11 96 75 33 41 64 49 55 61 76 95 34 24 20 9 60 26 69 1 97 86 29 74 +Card 141: 64 44 35 96 32 78 94 53 68 97 | 9 78 40 97 56 83 48 64 95 69 35 68 59 43 17 32 4 60 53 52 98 61 96 94 44 +Card 142: 73 34 61 17 49 3 35 66 85 58 | 28 13 21 45 85 19 67 29 49 5 30 61 38 52 2 3 48 31 17 99 58 34 80 9 14 +Card 143: 99 8 50 43 75 69 88 40 13 91 | 85 43 67 24 91 62 99 38 18 16 2 34 26 82 98 6 53 37 77 33 30 42 3 31 36 +Card 144: 90 86 40 96 44 43 91 93 20 80 | 66 64 19 79 18 10 95 52 72 31 89 92 62 68 23 75 78 84 37 15 13 36 38 26 81 +Card 145: 2 92 97 59 98 96 34 41 25 72 | 10 20 43 6 42 22 92 61 73 99 21 46 41 25 34 96 63 50 59 13 91 38 79 57 72 +Card 146: 50 81 51 16 9 34 30 65 60 53 | 55 6 75 29 96 42 86 11 18 45 46 77 87 54 25 91 43 94 23 24 99 82 31 72 93 +Card 147: 84 27 17 26 33 98 36 58 5 13 | 90 65 96 28 31 10 14 95 46 94 22 16 68 50 77 73 9 42 59 64 91 19 67 63 99 +Card 148: 67 62 86 8 87 92 94 80 93 25 | 9 3 60 66 47 23 20 72 28 75 11 37 50 13 34 58 2 64 16 98 88 56 81 7 38 +Card 149: 20 93 31 26 11 42 53 37 3 84 | 22 79 34 17 42 94 32 55 33 2 13 36 80 63 14 11 59 12 98 8 50 93 20 53 84 +Card 150: 1 75 15 7 80 59 99 86 71 58 | 31 72 14 67 85 18 96 15 8 13 80 47 45 64 60 24 46 98 6 97 39 49 69 4 54 +Card 151: 56 46 61 40 86 85 74 79 94 36 | 10 9 2 32 22 43 87 40 68 20 36 94 89 86 45 27 42 71 92 59 16 6 24 81 73 +Card 152: 65 40 13 51 60 42 1 99 19 73 | 74 72 39 50 49 27 37 78 51 38 7 41 23 95 81 43 97 19 73 28 89 17 91 6 62 +Card 153: 28 76 9 48 94 45 23 32 26 21 | 4 63 33 28 36 81 98 14 50 55 3 31 1 71 62 17 70 80 46 59 51 20 38 22 12 +Card 154: 11 53 34 58 30 8 86 71 2 96 | 85 92 62 82 90 75 51 15 41 19 70 55 67 74 77 27 64 6 14 48 76 88 25 83 42 +Card 155: 19 83 27 70 46 16 57 48 18 86 | 13 4 73 2 75 36 53 69 15 21 9 10 64 95 78 61 43 71 12 99 92 56 6 42 28 +Card 156: 87 63 55 52 11 78 15 42 83 38 | 70 40 42 97 41 48 87 78 83 73 72 99 63 66 11 22 6 69 76 3 61 1 91 16 51 +Card 157: 63 87 28 40 56 50 64 73 43 51 | 16 21 7 50 44 88 35 9 32 80 51 30 95 82 5 46 76 65 37 25 29 61 26 4 56 +Card 158: 47 63 14 74 88 90 71 87 95 32 | 14 30 47 88 15 29 41 11 59 90 92 64 77 94 68 89 12 19 85 28 62 87 33 71 95 +Card 159: 21 46 50 45 92 35 73 33 25 81 | 17 38 72 94 29 6 49 7 71 21 9 80 99 39 58 25 44 45 35 57 20 33 61 50 73 +Card 160: 18 1 12 75 88 32 59 51 73 9 | 94 83 70 5 1 73 18 75 9 92 76 45 7 36 30 65 60 32 25 12 33 51 88 59 23 +Card 161: 6 15 69 39 76 73 99 84 21 32 | 82 5 64 79 92 91 2 48 6 12 45 43 80 95 33 21 55 15 66 34 73 16 58 39 54 +Card 162: 74 67 93 73 40 6 54 81 30 99 | 89 4 36 18 6 17 31 71 96 70 77 83 20 99 11 26 93 62 85 74 24 30 8 84 3 +Card 163: 74 58 30 34 37 66 28 22 88 25 | 82 47 88 36 93 81 35 20 12 79 54 24 40 68 41 51 86 30 11 65 34 1 8 69 76 +Card 164: 71 77 50 90 5 56 92 80 34 22 | 82 31 50 70 69 90 5 85 39 80 73 77 54 56 75 34 15 92 26 32 22 42 17 71 23 +Card 165: 21 41 33 75 19 88 18 40 86 64 | 35 53 99 80 86 30 63 19 50 74 4 41 8 32 21 64 75 51 27 6 23 18 90 72 40 +Card 166: 76 73 55 71 90 22 12 81 34 9 | 66 63 23 30 87 62 59 7 67 89 78 24 64 68 27 97 19 25 94 53 48 56 45 70 33 +Card 167: 98 60 45 13 8 9 66 82 41 95 | 86 19 46 44 78 23 41 83 84 13 54 12 10 5 98 22 57 21 59 80 58 1 69 82 93 +Card 168: 40 36 18 3 44 29 86 23 13 75 | 18 44 3 9 40 62 55 1 78 49 27 13 87 48 12 36 86 17 29 76 34 20 32 50 94 +Card 169: 64 4 61 79 17 20 84 37 70 99 | 73 5 90 54 55 96 60 36 28 74 64 99 68 61 4 33 29 70 27 42 8 67 15 17 34 +Card 170: 12 91 87 50 84 14 38 93 43 78 | 95 46 66 64 47 60 36 70 97 73 56 93 83 65 11 1 15 7 42 41 59 40 84 82 62 +Card 171: 3 6 81 89 27 88 46 37 69 14 | 60 31 64 61 65 25 83 43 19 20 74 75 17 92 4 53 1 91 97 16 26 22 95 50 84 +Card 172: 40 35 87 27 3 58 81 45 59 80 | 90 21 88 64 66 52 5 63 65 40 13 79 82 62 85 34 78 37 33 27 87 26 58 95 75 +Card 173: 8 45 37 66 63 7 97 42 95 28 | 56 45 24 78 82 57 83 51 18 95 5 79 59 50 30 11 19 43 88 90 49 62 17 68 22 +Card 174: 8 56 80 50 6 12 36 32 24 98 | 53 22 70 13 62 58 15 79 78 7 9 38 26 63 75 44 17 82 67 59 71 86 39 46 93 +Card 175: 43 47 46 35 94 39 67 3 2 24 | 86 23 52 91 66 45 81 75 61 80 10 17 60 16 44 57 83 62 32 37 38 12 48 93 84 +Card 176: 82 97 11 25 15 68 7 24 77 46 | 18 35 2 80 48 75 19 47 70 39 99 43 28 62 33 50 13 17 10 58 86 45 16 88 60 +Card 177: 95 59 14 68 13 22 4 75 2 70 | 64 45 12 31 99 77 59 28 91 42 21 89 67 9 90 78 37 14 46 75 52 15 22 79 96 +Card 178: 83 17 81 96 9 2 80 70 57 53 | 85 80 62 9 29 25 8 83 2 66 17 68 84 3 81 42 57 23 15 72 96 53 70 7 73 +Card 179: 48 84 29 81 88 3 10 27 21 16 | 74 21 97 28 18 81 84 6 42 76 29 89 48 83 50 3 88 73 22 10 2 55 16 27 36 +Card 180: 30 77 49 58 39 1 97 13 25 34 | 75 53 61 99 34 62 48 1 51 77 84 25 49 26 79 59 13 11 30 60 21 39 97 93 58 +Card 181: 73 52 53 23 83 74 1 87 86 54 | 23 53 54 5 11 1 55 73 74 44 46 82 34 41 60 67 31 96 35 52 86 15 18 87 83 +Card 182: 90 48 22 80 52 41 78 11 55 32 | 60 9 2 21 87 42 68 16 15 50 95 51 99 40 30 52 20 12 26 49 92 19 84 36 76 +Card 183: 33 63 2 19 24 61 10 14 37 1 | 59 20 32 69 98 55 85 36 29 71 61 68 14 2 7 88 39 16 94 92 74 45 90 38 35 +Card 184: 85 65 43 1 75 27 17 10 91 18 | 27 42 55 89 38 66 82 75 64 43 50 39 52 10 59 93 18 3 91 1 85 40 26 8 65 +Card 185: 74 7 10 70 95 76 27 50 13 36 | 70 15 58 18 13 74 4 64 50 44 54 27 56 35 87 28 76 92 85 36 66 95 90 96 78 +Card 186: 45 59 16 99 43 79 89 90 40 49 | 18 97 56 67 61 29 80 34 91 88 33 95 41 76 78 68 28 46 51 93 98 72 54 74 8 +Card 187: 87 69 84 72 92 86 13 76 40 38 | 38 8 37 71 30 49 50 21 51 39 34 90 84 16 11 10 4 63 7 42 36 77 48 85 20 +Card 188: 96 18 79 50 81 65 84 74 76 58 | 21 48 35 12 83 70 23 88 58 3 74 84 72 76 43 71 8 27 2 37 46 89 5 54 81 +Card 189: 22 90 97 45 19 70 36 23 81 2 | 6 60 40 57 41 16 91 42 58 38 92 31 15 76 35 73 11 33 24 30 32 85 18 51 93 +Card 190: 72 69 52 65 14 74 64 57 70 33 | 41 99 32 49 96 34 82 80 42 1 69 40 64 44 88 86 14 31 28 22 38 46 45 54 29 +Card 191: 86 70 76 64 97 6 56 34 87 41 | 96 81 52 89 28 16 29 90 41 32 70 68 9 88 30 5 60 92 61 49 56 50 46 37 11 +Card 192: 14 42 66 20 48 94 55 51 23 75 | 83 74 97 43 28 72 18 26 13 59 93 19 10 60 89 82 63 50 3 21 4 79 91 98 36 +Card 193: 13 33 98 37 19 86 32 15 95 96 | 56 90 5 60 24 21 46 73 29 3 58 75 77 66 41 48 82 84 10 53 43 15 18 2 89 +Card 194: 77 6 10 48 14 79 73 51 49 25 | 86 12 37 23 43 34 5 89 97 27 53 70 75 19 15 79 45 26 1 73 68 36 2 78 18 +Card 195: 94 57 24 37 46 75 73 10 29 5 | 78 25 21 48 22 46 38 76 19 17 64 32 88 99 63 12 20 41 16 7 14 54 81 97 89 +Card 196: 76 48 15 89 44 50 79 80 52 78 | 93 55 21 18 73 31 47 20 97 83 87 30 6 24 77 74 67 45 76 65 37 43 42 98 38 +Card 197: 67 21 75 10 9 6 47 88 45 70 | 91 95 58 82 52 50 87 81 78 13 64 53 57 14 55 25 36 76 19 86 56 2 16 54 1 diff --git a/advent-of-code/2023/04/part1.c b/advent-of-code/2023/04/part1.c new file mode 100644 index 0000000..4dd94ba --- /dev/null +++ b/advent-of-code/2023/04/part1.c @@ -0,0 +1,69 @@ +#include <stdio.h> +#include <stdlib.h> +#include <math.h> + +#include "vec.h" +#include "str.h" + +typedef struct { + void *win_nums; + void *nums; +} card_t; + +void *parse_input() { + FILE *fp = fopen("./input", "r"); + void *cards = new_vec(); + char *line; + while ((line = fgetline(fp)) != NULL) { + line = str_strip(line); + line = vec_get(str_split(line, ':'), 1); + line = str_strip(line); + void *splited = str_split(line, '|'); + char *win_str = str_strip(vec_get(splited, 0)); + char *num_str = str_strip(vec_get(splited, 1)); + void *winnums_str = str_split(win_str, ' '); + void *nums_str = str_split(num_str, ' '); + + card_t *card = malloc(sizeof(card_t)); + card->win_nums = new_vec(); + card->nums = new_vec(); + for (int i = 0; i < vec_size(winnums_str); i++) { + int *n = malloc(sizeof(int)); + *n = strtol(vec_get(winnums_str, i), NULL, 10); + vec_push_back(card->win_nums, n); + } + for (int i = 0; i < vec_size(nums_str); i++) { + int *n = malloc(sizeof(int)); + *n = strtol(vec_get(nums_str, i), NULL, 10); + vec_push_back(card->nums, n); + } + vec_push_back(cards, card); + } + return cards; +} + +int points(card_t *card) { + int win_count = 0; + for (int i = 0; i < vec_size(card->nums); i++) { + int num = *(int*)vec_get(card->nums, i); + for (int j = 0; j < vec_size(card->win_nums); j++) { + if (num == *(int*)vec_get(card->win_nums, j)) { + win_count++; + break; + } + } + } + if (win_count == 0) return 0; + return (int)pow(2, win_count - 1); +} + +int main() { + void *cards = parse_input(); + int sum = 0; + for (int i = 0; i < vec_size(cards); i++) { + int p = points(vec_get(cards, i)); + sum += p; + } + printf("%d\n", sum); + return 0; +} diff --git a/advent-of-code/2023/04/part2.c b/advent-of-code/2023/04/part2.c new file mode 100644 index 0000000..5e67ead --- /dev/null +++ b/advent-of-code/2023/04/part2.c @@ -0,0 +1,81 @@ +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <string.h> + +#include "vec.h" +#include "str.h" + +typedef struct { + void *win_nums; + void *nums; +} card_t; + +void *parse_input() { + FILE *fp = fopen("./input", "r"); + void *cards = new_vec(); + char *line; + while ((line = fgetline(fp)) != NULL) { + line = str_strip(line); + line = vec_get(str_split(line, ':'), 1); + line = str_strip(line); + void *splited = str_split(line, '|'); + char *win_str = str_strip(vec_get(splited, 0)); + char *num_str = str_strip(vec_get(splited, 1)); + void *winnums_str = str_split(win_str, ' '); + void *nums_str = str_split(num_str, ' '); + + card_t *card = malloc(sizeof(card_t)); + card->win_nums = new_vec(); + card->nums = new_vec(); + for (int i = 0; i < vec_size(winnums_str); i++) { + int *n = malloc(sizeof(int)); + *n = strtol(vec_get(winnums_str, i), NULL, 10); + vec_push_back(card->win_nums, n); + } + for (int i = 0; i < vec_size(nums_str); i++) { + int *n = malloc(sizeof(int)); + *n = strtol(vec_get(nums_str, i), NULL, 10); + vec_push_back(card->nums, n); + } + vec_push_back(cards, card); + } + return cards; +} + +int win_count(card_t *card) { + int win_count = 0; + for (int i = 0; i < vec_size(card->nums); i++) { + int num = *(int*)vec_get(card->nums, i); + for (int j = 0; j < vec_size(card->win_nums); j++) { + if (num == *(int*)vec_get(card->win_nums, j)) { + win_count++; + break; + } + } + } + return win_count; +} + +int process_card(int *card_cnt, void *cards, int i) { + int card_num = vec_size(cards); + int win_cnt = win_count(vec_get(cards, i)); + for (int j = i + 1; j < card_num && j < i + 1 + win_cnt; j++) { + card_cnt[j] += card_cnt[i]; + } + return card_cnt[i]; +} + +int main() { + void *cards = parse_input(); + int sum = 0; + int *card_cnt = malloc(sizeof(int) * vec_size(cards)); + for (int i = 0; i < vec_size(cards); i++) { + card_cnt[i] = 1; + } + for (int i = 0; i < vec_size(cards); i++) { + sum += process_card(card_cnt, cards, i); + } + printf("%d\n", sum); + return 0; +} diff --git a/advent-of-code/2023/05/input b/advent-of-code/2023/05/input new file mode 100644 index 0000000..2e51c69 --- /dev/null +++ b/advent-of-code/2023/05/input @@ -0,0 +1,211 @@ +seeds: 3416930225 56865175 4245248379 7142355 1808166864 294882110 863761171 233338109 4114335326 67911591 1198254212 504239157 3491380151 178996923 3965970270 15230597 2461206486 133606394 2313929258 84595688 + +seed-to-soil map: +3534435790 4123267198 50004089 +3584439879 3602712894 238659237 +2263758314 0 160870825 +2971481857 2850687195 31776688 +4173604159 3353763588 121363137 +3823099116 3003258545 350505043 +2850687195 2882463883 120794662 +1503174517 2076905328 347723811 +1850898328 195477286 412859986 +1265521310 1606247567 17062682 +3285153612 4173271287 121696009 +488201540 828927797 777319770 +453595079 160870825 34606461 +3406849621 3475126725 127586169 +1282583992 608337272 220590525 +3003258545 3841372131 281895067 +0 1623310249 453595079 + +soil-to-fertilizer map: +131427930 1185330183 180485664 +748806267 2475960003 160820884 +311913594 3858074623 436892673 +3738185633 2255483282 220476721 +909627151 2636780887 1221293736 +2848518198 1365815847 889667435 +2130920887 131427930 666553095 +2797473982 1134285967 51044216 +3958662354 797981025 336304942 + +fertilizer-to-water map: +318410581 1095359367 168721315 +1850530626 4267113166 11515024 +1868157768 2129267011 114327162 +3662276437 4191001581 22313216 +2980811924 3765310336 180818294 +3971289879 3991326516 15449292 +4217905563 2279561459 35118050 +2287003279 4213314797 47187938 +1837473204 2314679509 13057422 +1998824036 3946128630 45197886 +222462505 1264080682 95948076 +487131896 791770420 303588947 +4253023613 4068573955 41943683 +2334191217 3252696905 278223677 +3986739171 2786104784 83568826 +3495640623 3600917310 61383314 +3557023937 3662300624 15042395 +2222048360 3535962391 64954919 +2919013777 4006775808 61798147 +3660033649 4182646675 2242788 +3266573705 2327736931 229066918 +3684589653 2869673610 235425729 +3261531896 3530920582 5041809 +790720843 417781090 105163807 +895884650 0 159434487 +2044021922 2608078346 178026438 +1862045650 4184889463 6112118 +3572066332 3677343019 87967317 +1830862773 4260502735 6610431 +1338009275 159434487 258346603 +3233759255 1830862773 27772641 +1055319137 1360028758 282690138 +1982484930 4278628190 16339106 +2883046491 2243594173 35967286 +2612414894 1858635414 270631597 +4070307997 3105099339 147597566 +3161630218 4110517638 72129037 +1596355878 522944897 46363018 +0 569307915 222462505 +3920015382 2556803849 51274497 + +water-to-light map: +3185219492 1324735395 185266775 +3146586681 1249776213 38632811 +28244350 428471809 312696716 +340941066 3650819202 117391304 +458332370 963661621 286114592 +2785969088 3483794777 117695215 +1279106820 1583617352 194624401 +1473731221 3601489992 49329210 +0 2796264154 28244350 +744446962 3356330358 127464419 +2562107674 223281414 205190395 +3544929092 0 223281414 +2767298069 944990602 18671019 +2903664303 775683406 169307196 +3072971499 1510002170 73615182 +1140236238 741168525 34514881 +1242780449 1288409024 36326371 +1523060431 1778241753 949993071 +871911381 3088005501 268324857 +3370486267 2913562676 174442825 +4096117687 4180659844 114307452 +1174751119 2728234824 68029330 +4210425139 4096117687 84542157 +2473053502 2824508504 89054172 + +light-to-temperature map: +57304962 1726059676 351776583 +1567802332 965133212 510033927 +3296678005 3095070487 435408435 +2476702913 3609026358 293401880 +1363411758 0 204390574 +1017340727 204390574 346071031 +2770104793 2148583721 409359530 +994650876 1475167139 22689851 +0 550461605 20445762 +20445762 1692752937 33306739 +2144982382 2092188566 56395155 +799754929 1497856990 194895947 +53752501 961580751 3552461 +409081545 570907367 390673384 +2201377537 3902428238 275325376 +3988154754 2557943251 306812542 +3179464323 4177753614 117213682 +3732086440 3530478922 78547436 +3810633876 2864755793 177520878 +2092188566 3042276671 52793816 + +temperature-to-humidity map: +18928354 3414191527 36074961 +3774151818 3588716061 144651966 +2046448856 1384376044 7569690 +2737178317 903028814 27883660 +2981004508 930912474 349046239 +1609626976 3084565214 120015958 +2765061977 2248931514 215942531 +157942811 3887783726 359543023 +3330050747 2195105292 25002873 +2041971091 78356652 4477765 +1938796124 861459710 41569104 +1608860129 2474627144 766847 +1812604664 3795542966 74143188 +4196563819 3386335999 27024746 +1980365228 3204581172 61605863 +1136292153 82834417 94266783 +4015908448 1279958713 104417331 +2701246339 2062523244 35931978 +4223588565 3286123619 23738184 +91521115 3309861803 56668597 +1886747852 2552562071 52048272 +1729642934 0 61644451 +1791287385 1504576228 21317279 +517485834 1726582276 261020280 +2192468119 2604610343 479954871 +1413642666 1391945734 112630494 +71715516 3366530400 19805599 +3918803784 2475393991 77168080 +1546685190 3733368027 62174939 +2672422990 2220108165 28823349 +148189712 2464874045 9753099 +18097572 3413360745 830782 +0 3869686154 18097572 +3995971864 3266187035 19936584 +853426802 432206724 27759827 +2054018546 3450266488 138449573 +881186629 177101200 255105524 +778506114 1987602556 74920688 +1526273160 2098455222 20412030 +55003315 61644451 16712201 +3355053620 459966551 401493159 +4120325779 2118867252 76238040 +1230558936 1525893507 183083730 +3756546779 1708977237 17605039 + +humidity-to-location map: +166973311 827072705 21017988 +2420657564 1797988486 98294592 +3711057743 1724407580 50543704 +151140540 331672683 15832771 +2611368935 1098267426 35837870 +329110209 0 39413233 +848395356 3293184115 2008343 +850403699 1508109908 216297672 +3203490893 3278069000 15115115 +1322210923 4179894531 115072765 +3761601447 848395356 249872070 +230668724 39413233 27530262 +1437283688 2240143464 113813014 +1551096702 2957294790 77256502 +716039283 695021295 132051410 +258198986 109620920 70911223 +1314022212 2357817442 8188711 +2793895840 2474472017 281155944 +385486933 347505454 330552350 +3218606008 3561131747 206517169 +1066701371 3354107909 156810008 +4011473517 1134105296 283493779 +0 180532143 151140540 +368523442 678057804 16963491 +1223511379 1417599075 90510833 +3183517648 1988699857 19973245 +2270463718 4038012896 141881635 +1817187310 1774951284 23037202 +1963899457 2755627961 201666829 +2412345353 3295192458 8312211 +1840224512 3767648916 123674945 +187991299 66943495 42677425 +2518952156 1896283078 92416779 +1628353204 3034551292 138620276 +3075051784 2366006153 108465864 +3660454503 3303504669 50603240 +3425123177 2008673102 231470362 +3656593539 2353956478 3860964 +1766973480 3510917917 50213830 +2647206805 3891323861 146689035 +2165566286 3173171568 104897432 + diff --git a/advent-of-code/2023/05/part1.scm b/advent-of-code/2023/05/part1.scm new file mode 100755 index 0000000..5413bf0 --- /dev/null +++ b/advent-of-code/2023/05/part1.scm @@ -0,0 +1,75 @@ +#!/usr/bin/env guile +!# + +(use-modules (ice-9 rdelim)) + +(define port (open-input-file "input")) + +(define seed + (let () + (define nums-str + (string-trim + (list-ref (string-split (read-line port) #\:) 1))) + (map string->number (string-split nums-str #\space)))) + +(read-line port) + +(define (read-line-convert-eof port) + (define line (read-line port)) + (if (eof-object? line) "" line)) + +(define (read-map) + (define (loop ret) + (define line (string-trim (read-line-convert-eof port))) + (if (= 0 (string-length line)) + (reverse ret) + (loop (cons (map string->number (string-split line #\space)) + ret)))) + (read-line port) + (loop '())) + +(define s2s (read-map)) +(define s2f (read-map)) +(define f2w (read-map)) +(define w2l (read-map)) +(define l2t (read-map)) +(define t2h (read-map)) +(define h2l (read-map)) +(define maps (list s2s s2f f2w w2l l2t t2h h2l)) + + +(define (gen-mapper the-map) + (define (mapper x) + (define (loop the-map) + (if (nil? the-map) + x + (let () + (define cur-map (car the-map)) + (define target (car cur-map)) + (define start (cadr cur-map)) + (define len (caddr cur-map)) + (if (and (>= x start) + (<= x (+ start len))) + (+ target (- x start)) + (loop (cdr the-map)))))) + (loop the-map)) + mapper) + +(define mappers (map gen-mapper maps)) + + +(define (comp-func funcs) + (define procs (reverse funcs)) + (define (comp-rec arg) + (if (null? procs) + arg + (let ((proc (car procs)) + (rest (cdr procs))) + (set! procs rest) + (proc (comp-rec arg))))) + comp-rec) + +(define (find-location x) + ((comp-func mappers) x)) + +(display (apply min (map find-location seed))) diff --git a/advent-of-code/2023/05/part2.scm b/advent-of-code/2023/05/part2.scm new file mode 100755 index 0000000..87ad5e9 --- /dev/null +++ b/advent-of-code/2023/05/part2.scm @@ -0,0 +1,112 @@ +#!/usr/bin/env guile +!# + +(use-modules (ice-9 rdelim)) + +(define port (open-input-file "input")) + +(define seed + (let () + (define nums-str + (string-trim + (list-ref (string-split (read-line port) #\:) 1))) + (define (pairing l) + (define (loop ret l) + (if (null? l) + ret + (loop + (cons (cons + (car l) + (+ (car l) (cadr l))) + ret) + (cddr l)))) + (loop '() l)) + (reverse + (pairing (map string->number (string-split nums-str #\space)))))) + +(read-line port) + +(define (read-line-convert-eof port) + (define line (read-line port)) + (if (eof-object? line) "" line)) + +(define (read-map) + (define (loop ret) + (define line (string-trim (read-line-convert-eof port))) + (if (= 0 (string-length line)) + (sort (reverse ret) (lambda (x y) (< (cadr x) (cadr y)))) + (loop (cons (map string->number (string-split line #\space)) + ret)))) + (read-line port) + (loop '())) + +(define s2s (read-map)) +(define s2f (read-map)) +(define f2w (read-map)) +(define w2l (read-map)) +(define l2t (read-map)) +(define t2h (read-map)) +(define h2l (read-map)) +(define maps (list s2s s2f f2w w2l l2t t2h h2l)) + +(define (range-map mlist r) + ;; r :: Range :: (start . end) + ;; mlist :: List of (Map :: (dest, src, len)) + (define (loop result mlist r) + (define start (car r)) + (define end (cdr r)) + (if (null? mlist) + (cons r result) + (let () + (define cur-map (car mlist)) + (define map-target (car cur-map)) + (define map-start (cadr cur-map)) + (define map-end (+ map-start (caddr cur-map))) + (define offset (- map-target map-start)) + (define (pair-offset p) (cons (+ offset (car p)) (+ offset (cdr p)))) + (cond ((<= end start) + result) + ((>= start map-end) + (loop result (cdr mlist) r)) + ((>= start map-start) + (loop + (cons (pair-offset (cons start (min end map-end))) + result) + (cdr mlist) + (cons (min end map-end) end))) + ((<= end map-start) + (cons r result)) + ((< start map-start) + (loop + (cons (cons start map-start) result) + mlist + (cons map-start end))) + (else (error "unhandled cond in range-map")))))) + (reverse (loop '() mlist r))) + +(define (gen-range-mapper the-map) + (define (mapper range-list) + (apply append + (map + (lambda (range) + (range-map the-map range)) + range-list))) + mapper) + +(define mappers (map gen-range-mapper maps)) + +(define (comp-func funcs) + (define procs (reverse funcs)) + (define (comp-rec arg) + (if (null? procs) + arg + (let ((proc (car procs)) + (rest (cdr procs))) + (set! procs rest) + (proc (comp-rec arg))))) + comp-rec) + +(define (find-location x) + ((comp-func mappers) x)) + +(display (apply min (map car (find-location seed)))) diff --git a/advent-of-code/2023/LICENSE b/advent-of-code/2023/LICENSE new file mode 100644 index 0000000..20d40b6 --- /dev/null +++ b/advent-of-code/2023/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + <program> Copyright (C) <year> <name of author> + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +<http://www.gnu.org/licenses/>. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +<http://www.gnu.org/philosophy/why-not-lgpl.html>.
\ No newline at end of file diff --git a/advent-of-code/2023/README.md b/advent-of-code/2023/README.md new file mode 100644 index 0000000..7763b73 --- /dev/null +++ b/advent-of-code/2023/README.md @@ -0,0 +1,3 @@ +# Advent of Code + +My solutions of Advent of Code. diff --git a/advent-of-code/2023/lib/map.c b/advent-of-code/2023/lib/map.c new file mode 100644 index 0000000..846033e --- /dev/null +++ b/advent-of-code/2023/lib/map.c @@ -0,0 +1,90 @@ +#include "map.h" +#include "rb_tree.h" + +#include <string.h> + +typedef int (*rb_cmp_t)(void*, void*); + +void* new_map(cmp_t compare) { + rb_tree_t *tree = malloc(sizeof(rb_tree_t)); + rb_cmp_t cmp = (rb_cmp_t)compare; + *tree = (rb_tree_t){NULL, cmp, NULL}; + return tree; +} + +void map_set(void* self, void* key, void* value) { + node_entry_t *iter = rb_tree_find(self, &key); + if (iter == NULL) { + iter = malloc(sizeof(*iter)); + iter->key = key; + iter->value = value; + rb_tree_insert(self, iter); + } else { + iter->value = value; + } +} + +void* map_get(void* self, void* key) { + node_entry_t *iter = rb_tree_find(self, &key); + if (iter == NULL) return NULL; + return iter->value; +} + +void map_erase(void* self, void* key) { + rb_tree_remove(self, key); +} + +void* map_begin(void *self) { + return rb_tree_min(self); +} + +void* map_next(void *self, void *iter) { + return rb_tree_next(self, iter); +} + +void* map_iter_key(void* iter_) { + node_entry_t *iter = iter_; + return iter->key; +} + +void* map_iter_value(void* iter_) { + node_entry_t *iter = iter_; + return iter->value; +} + +static int dict_cmp(void **a, void** b) { + return strcmp(*a, *b); +} +void* new_dict() { + return new_map(dict_cmp); +} + +void dict_set(void* self, const char *key, void* value) { + map_set(self, (void*)key, value); +} + +void* dict_get(void* self, const char* key) { + return map_get(self, (void*)key); +} + +void dict_erase(void* self, const char* key) { + map_erase(self, (void*)key); +} + +void* dict_begin(void *self) { + return map_begin(self); +} + +void* dict_next(void *self, void *iter) { + return map_next(self, iter); +} + +const char* dict_iter_key(void* iter) { + return map_iter_key(iter); +} + +void* dict_iter_value(void* iter) { + return map_iter_value(iter); +} + + diff --git a/advent-of-code/2023/lib/map.h b/advent-of-code/2023/lib/map.h new file mode 100644 index 0000000..c54048c --- /dev/null +++ b/advent-of-code/2023/lib/map.h @@ -0,0 +1,33 @@ +#ifndef MAP_H_ +#define MAP_H_ + +#include "rb_tree.h" + +typedef struct { + rb_node_t node; + void *key; + void *value; +} node_entry_t; +typedef int (*cmp_t)(void** a, void** b); + +void* new_map(cmp_t compare); +void map_set(void* self, void* key, void* value); +void* map_get(void* self, void* key); +void map_erase(void* self, void* key); + +void* map_begin(void *self); +void* map_next(void *self, void *iter); +void* map_iter_key(void* iter); +void* map_iter_value(void* iter); + +void* new_dict(); +void dict_set(void* self, const char *key, void* value); +void* dict_get(void* self, const char* key); +void dict_erase(void* self, const char* key); + +void* dict_begin(void *self); +void* dict_next(void *self, void *iter); +const char* dict_iter_key(void* iter); +void* dict_iter_value(void* iter); + +#endif diff --git a/advent-of-code/2023/lib/rb_tree.c b/advent-of-code/2023/lib/rb_tree.c new file mode 100644 index 0000000..5aa7905 --- /dev/null +++ b/advent-of-code/2023/lib/rb_tree.c @@ -0,0 +1,378 @@ +// Copyright (C) 2023 Mistivia <i@mistivia.com> +// Licensed under GPLv3. See LICENSE for details. + +/* + * Copyright 2002 Niels Provos <provos@citi.umich.edu> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "rb_tree.h" + +#define RED 1 +#define BLACK 0 + +static rb_node_t *rb_tree_minmax(rb_tree_t *, int); +void *rb_tree_min(rb_tree_t *head) { return rb_tree_minmax(head, -1); } +void *rb_tree_max(rb_tree_t *head) { return rb_tree_minmax(head, 1); } + +void *rb_tree_left(void *node) { + rb_node_t *elm = node; + if (node == NULL) return NULL; + return elm->entry.rbe_left; +} +void *rb_tree_right(void *node) { + rb_node_t *elm = node; + if (node == NULL) return NULL; + return elm->entry.rbe_right; +} +void *rb_tree_parent(void *node) { + rb_node_t *elm = node; + if (node == NULL) return NULL; + return elm->entry.rbe_parent; +} + +static void augment(rb_tree_t *head, rb_node_t *elm) { + if (head->augment != NULL) head->augment(elm); +} + +static void rb_tree_insert_color(rb_tree_t *head, rb_node_t *elm); +static void rb_tree_remove_color(rb_tree_t *head, rb_node_t *parent, + rb_node_t *elm); + +static void rotate_left(rb_tree_t *head, rb_node_t *elm) { + rb_node_t *tmp = elm->entry.rbe_right; + if ((elm->entry.rbe_right = tmp->entry.rbe_left)) { + tmp->entry.rbe_left->entry.rbe_parent = elm; + } + augment(head, elm); + if ((tmp->entry.rbe_parent = elm->entry.rbe_parent)) { + if (elm == elm->entry.rbe_parent->entry.rbe_left) + elm->entry.rbe_parent->entry.rbe_left = tmp; + else + elm->entry.rbe_parent->entry.rbe_right = tmp; + } else { + head->rbh_root = tmp; + } + tmp->entry.rbe_left = elm; + elm->entry.rbe_parent = tmp; + augment(head, tmp); + if (tmp->entry.rbe_parent) { + augment(head, tmp->entry.rbe_parent); + } +} + +static void rotate_right(rb_tree_t *head, rb_node_t *elm) { + rb_node_t *tmp = elm->entry.rbe_left; + if ((elm->entry.rbe_left = tmp->entry.rbe_right)) { + tmp->entry.rbe_right->entry.rbe_parent = elm; + } + augment(head, elm); + if ((tmp->entry.rbe_parent = elm->entry.rbe_parent)) { + if (elm == elm->entry.rbe_parent->entry.rbe_left) + elm->entry.rbe_parent->entry.rbe_left = tmp; + else + elm->entry.rbe_parent->entry.rbe_right = tmp; + } else { + head->rbh_root = tmp; + } + tmp->entry.rbe_right = elm; + elm->entry.rbe_parent = tmp; + augment(head, tmp); + if (tmp->entry.rbe_parent) { + augment(head, tmp->entry.rbe_parent); + } +} + +static void rb_tree_insert_color(rb_tree_t *head, rb_node_t *elm) { + rb_node_t *parent, *gparent, *tmp; + while ((parent = elm->entry.rbe_parent) && parent->entry.rbe_color == 1) { + gparent = parent->entry.rbe_parent; + if (parent == gparent->entry.rbe_left) { + tmp = gparent->entry.rbe_right; + if (tmp && tmp->entry.rbe_color == 1) { + tmp->entry.rbe_color = BLACK; + parent->entry.rbe_color = BLACK; + gparent->entry.rbe_color = RED; + elm = gparent; + continue; + } + if (parent->entry.rbe_right == elm) { + rotate_left(head, parent); + tmp = parent; + parent = elm; + elm = tmp; + } + parent->entry.rbe_color = BLACK; + gparent->entry.rbe_color = RED; + rotate_right(head, gparent); + } else { + tmp = gparent->entry.rbe_left; + if (tmp && tmp->entry.rbe_color == 1) { + tmp->entry.rbe_color = BLACK; + parent->entry.rbe_color = BLACK; + gparent->entry.rbe_color = RED; + ; + elm = gparent; + continue; + } + if (parent->entry.rbe_left == elm) { + rotate_right(head, parent); + tmp = parent; + parent = elm; + elm = tmp; + } + parent->entry.rbe_color = BLACK; + gparent->entry.rbe_color = RED; + rotate_left(head, gparent); + } + } + head->rbh_root->entry.rbe_color = BLACK; +} + +static void rb_tree_remove_color(rb_tree_t *head, rb_node_t *parent, + rb_node_t *elm) { + rb_node_t *tmp; + while ((elm == NULL || elm->entry.rbe_color == 0) && + elm != head->rbh_root) { + if (parent->entry.rbe_left == elm) { + tmp = parent->entry.rbe_right; + if (tmp->entry.rbe_color == 1) { + tmp->entry.rbe_color = BLACK; + parent->entry.rbe_color = RED; + rotate_left(head, parent); + tmp = parent->entry.rbe_right; + } + if ((tmp->entry.rbe_left == NULL || + tmp->entry.rbe_left->entry.rbe_color == 0) && + (tmp->entry.rbe_right == NULL || + tmp->entry.rbe_right->entry.rbe_color == 0)) { + tmp->entry.rbe_color = RED; + elm = parent; + parent = elm->entry.rbe_parent; + } else { + if (tmp->entry.rbe_right == NULL || + tmp->entry.rbe_right->entry.rbe_color == 0) { + rb_node_t *oleft; + if ((oleft = tmp->entry.rbe_left)) + oleft->entry.rbe_color = BLACK; + tmp->entry.rbe_color = RED; + rotate_right(head, tmp); + tmp = parent->entry.rbe_right; + } + tmp->entry.rbe_color = parent->entry.rbe_color; + parent->entry.rbe_color = BLACK; + if (tmp->entry.rbe_right) + tmp->entry.rbe_right->entry.rbe_color = BLACK; + rotate_left(head, parent); + elm = head->rbh_root; + break; + } + } else { + tmp = parent->entry.rbe_left; + if (tmp->entry.rbe_color == 1) { + tmp->entry.rbe_color = BLACK; + parent->entry.rbe_color = RED; + rotate_right(head, parent); + tmp = parent->entry.rbe_left; + } + if ((tmp->entry.rbe_left == NULL || + tmp->entry.rbe_left->entry.rbe_color == 0) && + (tmp->entry.rbe_right == NULL || + tmp->entry.rbe_right->entry.rbe_color == 0)) { + tmp->entry.rbe_color = RED; + elm = parent; + parent = elm->entry.rbe_parent; + } else { + if (tmp->entry.rbe_left == NULL || + tmp->entry.rbe_left->entry.rbe_color == 0) { + rb_node_t *oright; + if ((oright = tmp->entry.rbe_right)) + oright->entry.rbe_color = BLACK; + tmp->entry.rbe_color = RED; + rotate_left(head, tmp); + tmp = parent->entry.rbe_left; + } + tmp->entry.rbe_color = parent->entry.rbe_color; + parent->entry.rbe_color = BLACK; + if (tmp->entry.rbe_left) + tmp->entry.rbe_left->entry.rbe_color = BLACK; + rotate_right(head, parent); + elm = head->rbh_root; + break; + } + } + } + if (elm) elm->entry.rbe_color = BLACK; +} + +void rb_tree_remove(rb_tree_t *head, void *elmv) { + rb_node_t *elm = elmv; + rb_node_t *child, *parent; + int color; + if (elm->entry.rbe_left == NULL) + child = elm->entry.rbe_right; + else if (elm->entry.rbe_right == NULL) + child = elm->entry.rbe_left; + else { + rb_node_t *old = elm, *left; + elm = elm->entry.rbe_right; + while ((left = elm->entry.rbe_left)) + elm = left; + child = elm->entry.rbe_right; + parent = elm->entry.rbe_parent; + color = elm->entry.rbe_color; + if (child) child->entry.rbe_parent = parent; + if (parent) { + if (parent->entry.rbe_left == elm) + parent->entry.rbe_left = child; + else + parent->entry.rbe_right = child; + augment(head, parent); + } else + head->rbh_root = child; + if (elm->entry.rbe_parent == old) parent = elm; + elm->entry = old->entry; + if (old->entry.rbe_parent) { + if ((old->entry.rbe_parent)->entry.rbe_left == old) + (old->entry.rbe_parent)->entry.rbe_left = elm; + else + (old->entry.rbe_parent)->entry.rbe_right = elm; + augment(head, old->entry.rbe_parent); + } else + head->rbh_root = elm; + old->entry.rbe_left->entry.rbe_parent = elm; + if (old->entry.rbe_right) old->entry.rbe_right->entry.rbe_parent = elm; + if (parent) { + left = parent; + if (head->augment != NULL) { + do { + augment(head, left); + } while ((left = left->entry.rbe_parent)); + } + } + goto color; + } + parent = elm->entry.rbe_parent; + color = elm->entry.rbe_color; + if (child) child->entry.rbe_parent = parent; + if (parent) { + if (parent->entry.rbe_left == elm) + parent->entry.rbe_left = child; + else + parent->entry.rbe_right = child; + rb_node_t *goback = parent; + if (head->augment != NULL) { + do { + augment(head, goback); + } while ((goback = goback->entry.rbe_parent)); + } + } else + head->rbh_root = child; +color: + if (color == 0) rb_tree_remove_color(head, parent, child); +} + +void *rb_tree_insert(rb_tree_t *head, void *elmv) { + rb_node_t *elm = elmv; + rb_node_t *tmp; + rb_node_t *parent = NULL; + int comp = 0; + tmp = head->rbh_root; + while (tmp) { + parent = tmp; + comp = head->cmp((void *)elm->content, (void *)parent->content); + if (comp < 0) + tmp = tmp->entry.rbe_left; + else if (comp > 0) + tmp = tmp->entry.rbe_right; + else + return tmp; + } + elm->entry.rbe_parent = parent; + elm->entry.rbe_left = elm->entry.rbe_right = NULL; + elm->entry.rbe_color = RED; + if (parent != NULL) { + if (comp < 0) + parent->entry.rbe_left = elm; + else + parent->entry.rbe_right = elm; + rb_node_t *goback = parent; + if (head->augment != NULL) { + do { + augment(head, goback); + } while ((goback = goback->entry.rbe_parent)); + } + } else + head->rbh_root = elm; + rb_tree_insert_color(head, elm); + return (NULL); +} + +void *rb_tree_find(rb_tree_t *head, void *key) { + rb_node_t *tmp = head->rbh_root; + int comp; + while (tmp) { + comp = head->cmp(key, (void *)tmp->content); + if (comp < 0) + tmp = tmp->entry.rbe_left; + else if (comp > 0) + tmp = tmp->entry.rbe_right; + else + return tmp; + } + return (NULL); +} + +void *rb_tree_next(rb_tree_t *head, void *elmv) { + rb_node_t *elm = elmv; + if (elm->entry.rbe_right) { + elm = elm->entry.rbe_right; + while (elm->entry.rbe_left) + elm = elm->entry.rbe_left; + } else { + if (elm->entry.rbe_parent && + (elm == (elm->entry.rbe_parent)->entry.rbe_left)) + elm = elm->entry.rbe_parent; + else { + while (elm->entry.rbe_parent && + (elm == (elm->entry.rbe_parent)->entry.rbe_right)) + elm = elm->entry.rbe_parent; + elm = elm->entry.rbe_parent; + } + } + return elm; +} + +static rb_node_t *rb_tree_minmax(rb_tree_t *head, int val) { + rb_node_t *tmp = head->rbh_root; + rb_node_t *parent = NULL; + while (tmp) { + parent = tmp; + if (val < 0) + tmp = tmp->entry.rbe_left; + else + tmp = tmp->entry.rbe_right; + } + return parent; +}; + diff --git a/advent-of-code/2023/lib/rb_tree.h b/advent-of-code/2023/lib/rb_tree.h new file mode 100644 index 0000000..2096ff6 --- /dev/null +++ b/advent-of-code/2023/lib/rb_tree.h @@ -0,0 +1,64 @@ +// Copyright (C) 2023 Mistivia <i@mistivia.com> +// Licensed under GPLv3. See LICENSE for details. + +/* + * Copyright 2002 Niels Provos <provos@citi.umich.edu> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef RB_TREE_H_ +#define RB_TREE_H_ + +#include <stdlib.h> + +struct rb_node { + struct { + struct rb_node *rbe_left; + struct rb_node *rbe_right; + struct rb_node *rbe_parent; + int rbe_color; + } entry; + char content[0]; +}; +typedef struct rb_node rb_node_t; + +struct rb_tree { + rb_node_t *rbh_root; + int (*cmp)(void *k1, void *k2); + void (*augment)(void *elm); +}; +typedef struct rb_tree rb_tree_t; + +void rb_tree_remove(rb_tree_t *, void *iter); + +// return a iterator +void *rb_tree_insert(rb_tree_t *, void *treenode); +void *rb_tree_find(rb_tree_t *, void *val); +void *rb_tree_next(rb_tree_t *, void *iter); +void *rb_tree_min(rb_tree_t *); +void *rb_tree_max(rb_tree_t *); +void *rb_tree_left(void *node); +void *rb_tree_right(void *node); +void *rb_tree_parent(void *node); + +#endif diff --git a/advent-of-code/2023/lib/str.c b/advent-of-code/2023/lib/str.c new file mode 100644 index 0000000..511e45b --- /dev/null +++ b/advent-of-code/2023/lib/str.c @@ -0,0 +1,143 @@ +// Copyright (C) 2023 Mistivia <i@mistivia.com> +// Licensed under GPLv3. See LICENSE for details. + +#include "str.h" + +#include <ctype.h> +#include <stdarg.h> +#include <stdbool.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "vec.h" + +void *str_split(const char *str, char delim) { + void* ret = new_vec(); + + if (str == NULL) return NULL; + if (*str == '\n') { + return ret; + } + int count = 0; + const char *begin = str; + for (const char *p = str; *p != '\0'; p++) { + if (*p != delim && !(delim == '\0' && isspace(*p))) { + continue; + } + int size = p - begin; + if (size > 0) count++; + } + count++; + + begin = str; + int i = 0; + bool finished = false; + for (const char *p = str; !finished; p++) { + if (*p == '\0') finished = true; + if (*p != delim && *p != '\0' && !(delim == '\0' && isspace(*p))) { + continue; + } + int size = p - begin; + if (size == 0) { + begin = p + 1; + continue; + } + char *buf = malloc(sizeof(char) * (size + 1)); + buf[size] = '\0'; + memcpy(buf, begin, size * sizeof(char)); + begin = p + 1; + vec_push_back(ret, buf); + } + return ret; +} + +char *str_strip(const char *str) { + if (str == NULL) return NULL; + int len = strlen(str); + const char *begin = str; + const char *end = str + len - 1; + while (isspace(*begin) && begin < end) { + begin++; + } + while (isspace(*end) && end >= begin) { + end--; + } + len = end - begin + 1; + char *buf = malloc(sizeof(char) * (len) + 1); + buf[len] = '\0'; + memcpy(buf, begin, len); + return buf; +} + +typedef struct { + size_t size; + size_t cap; + char *buf; +} str_builder_t; + +// string stream +void* new_ss() { + str_builder_t *self = malloc(sizeof(str_builder_t)); + *self = (str_builder_t){.size = 0, .cap = 16}; + self->buf = malloc(sizeof(char) * 17); + return self; +} + +static void ss_reserve(str_builder_t *self, int extra) { + if (self->size + extra <= self->cap) { + return; + } + int new_cap = (self->size + extra) * 2; + self->buf = realloc(self->buf, new_cap + 1); + memset(self->buf + self->cap, 0, new_cap - self->cap + 1); + self->cap = new_cap; +} + +void ss_add(void *self_, char *format, ...) { + str_builder_t *self = self_; + va_list va1; + va_list va2; + va_start(va1, format); + va_copy(va2, va1); + int size = vsnprintf(NULL, 0, format, va1); + ss_reserve(self, size); + vsnprintf(self->buf + self->size, self->cap - self->size + 1, format, va2); + self->size += size; +} + +void ss_addc(void *self_, char c) { + str_builder_t *self = self_; + ss_reserve(self, 1); + self->buf[self->size] = c; + self->size++; +} + +char *ss_cstr(void *self_) { + str_builder_t *self = self_; + return self->buf; +} + +size_t ss_size(void *self_) { + str_builder_t *self = self_; + return self->size; +} + +char *fgetline(FILE *fp) { + void *ss = new_ss(); + while (true) { + int c = fgetc(fp); + if (c == EOF && ss_size(ss) == 0) return NULL; + if (c != EOF) ss_addc(ss, c); + if (c == EOF || c == '\n') return ss_cstr(ss); + } + return NULL; +} + +int fpeek(FILE *fp) { + int c = fgetc(fp); + if (c == EOF) return c; + ungetc(c, fp); + return c; +} diff --git a/advent-of-code/2023/lib/str.h b/advent-of-code/2023/lib/str.h new file mode 100644 index 0000000..214e297 --- /dev/null +++ b/advent-of-code/2023/lib/str.h @@ -0,0 +1,24 @@ +// Copyright (C) 2023 Mistivia <i@mistivia.com> +// Licensed under GPLv3. See LICENSE for details. + +#ifndef DYMC_STR_H_ +#define DYMC_STR_H_ + +#include <stdio.h> +#include <stddef.h> + +char *str_strip(const char *str); +void* str_split(const char *str, char delim); + + +// string stream +void* new_ss(); +void ss_add(void *self, char *format, ...); +void ss_addc(void *self, char c); +char *ss_cstr(void *self); +size_t ss_size(void* self); + +char *fgetline(FILE *fp); +int fpeek(FILE *fp); + +#endif diff --git a/advent-of-code/2023/lib/vec.c b/advent-of-code/2023/lib/vec.c new file mode 100644 index 0000000..c3d8a0a --- /dev/null +++ b/advent-of-code/2023/lib/vec.c @@ -0,0 +1,72 @@ +#include "vec.h" + +#include <string.h> +#include "stdlib.h" + +struct vec { + size_t length; + size_t capacity; + void** buf; +}; + +static void vec_enlarge(struct vec* self) { + self->buf = realloc(self->buf, self->capacity * sizeof(void*) * 2); + self->capacity = self->capacity * 2; +} + +void *new_vec() { + struct vec* vec = malloc(sizeof(struct vec)); + vec->length = 0; + vec->capacity = 16; + vec->buf = malloc(16 * sizeof(void*)); + return vec; +} + +void vec_push_back(void *self_, void* obj) { + struct vec *self = self_; + if (self->length == self->capacity) vec_enlarge(self); + self->buf[self->length] = obj; + self->length++; +} + +void* vec_get(void *self_, size_t n) { + struct vec *self = self_; + if (n < 0 || n >= self->length) return NULL; + return self->buf[n]; +} + + +void vec_erase(void *self_, size_t n) { + struct vec *self = self_; + if (self->length <= n) { + return; + } + memmove(self->buf + n, self->buf + n + 1, (self->length - n - 1) * sizeof(void*)); + self->length--; +} + +size_t vec_size(void *self_) { + struct vec *self = self_; + return self->length; +} + +void vec_reserve(void *self_, size_t n) { + struct vec *self = self_; + if (n <= self->capacity) { + return; + } + self->buf = malloc(sizeof(void*) * n); + self->capacity = n; +} + +void vec_insert(void *self_, size_t pos, void *obj) { + struct vec *self = self_; + if (self->length == self->capacity) { + vec_enlarge(self); + } + if (pos > self->length || pos < 0) return; + memmove(self->buf + pos + 1, self->buf + pos, sizeof(void*) * (self->length - pos)); + self->buf[pos] = obj; + self->length++; +} + diff --git a/advent-of-code/2023/lib/vec.h b/advent-of-code/2023/lib/vec.h new file mode 100644 index 0000000..5778689 --- /dev/null +++ b/advent-of-code/2023/lib/vec.h @@ -0,0 +1,15 @@ +#ifndef VEC_H_ +#define VEC_H_ + +#include <stddef.h> + +void *new_vec(); +void vec_push_back(void *self, void* obj); +void* vec_get(void *self, size_t n); +size_t vec_length(void *self); +void vec_erase(void *self, size_t n); +size_t vec_size(void* self); +void vec_reserve(void* self, size_t n); +void vec_insert(void* self, size_t pos, void* obj); + +#endif diff --git a/codewars/6-kyu/Does my number look big in this?/solution.hs b/codewars/6-kyu/Does my number look big in this?/solution.hs new file mode 100644 index 0000000..1b84d9f --- /dev/null +++ b/codewars/6-kyu/Does my number look big in this?/solution.hs @@ -0,0 +1,17 @@ +-- https://www.codewars.com/kata/5287e858c6b5a9678200083c + +module Narcissistic where + +splitNum n = reverse $ impl n + where + impl n + | n < 10 = [n] + | otherwise = (n `mod` 10):(impl (n `div` 10)) + +narcissistic :: Integral n => n -> Bool +narcissistic n + | (sum $ map (^ (length splited)) splited) == n = True + | otherwise = False + where + splited = splitNum n + diff --git a/codewars/6-kyu/Duplicate Encoder/solution.hs b/codewars/6-kyu/Duplicate Encoder/solution.hs new file mode 100644 index 0000000..1cb38eb --- /dev/null +++ b/codewars/6-kyu/Duplicate Encoder/solution.hs @@ -0,0 +1,18 @@ +-- https://www.codewars.com/kata/54b42f9314d9229fd6000d9c + +module Dups where + +import Data.Char + +count s c + | s == [] = 0 + | c == (head s) = 1 + count (tail s) c + | otherwise = count (tail s) c + +convert s c + | count s c > 1 = ')' + | otherwise = '(' + +duplicateEncode :: String -> String +duplicateEncode s = map (convert ls) ls + where ls = map toLower s diff --git a/codewars/6-kyu/Equal Sides Of An Array/solution.hs b/codewars/6-kyu/Equal Sides Of An Array/solution.hs new file mode 100644 index 0000000..00717d7 --- /dev/null +++ b/codewars/6-kyu/Equal Sides Of An Array/solution.hs @@ -0,0 +1,11 @@ +-- https://www.codewars.com/kata/5679aa472b8f57fb8c000047 + +module Codewars.G964.FindEven where + +findEvenIndex :: [Int] -> Int +findEvenIndex arr = findEvenIndexImpl [] 0 arr + +findEvenIndexImpl left n right + | right == [] = -1 + | sum left == sum (tail right) = n + | otherwise = findEvenIndexImpl (left ++ [head right]) (n + 1) (tail right) diff --git a/codewars/6-kyu/Valid Braces/solution.hs b/codewars/6-kyu/Valid Braces/solution.hs new file mode 100644 index 0000000..6b139fd --- /dev/null +++ b/codewars/6-kyu/Valid Braces/solution.hs @@ -0,0 +1,21 @@ +-- https://www.codewars.com/kata/5277c8a221e209d3f6000b56 +module Codewars.Kata.Braces where + +validBraces :: String -> Bool +validBraces xs = impl 0 0 0 xs where + impl cnt1 cnt2 cnt3 str = + if str == [] then + cnt1 == 0 && cnt2 == 0 && cnt3 == 0 + else let + x = head str + xs = tail str + in + if cnt1 < 0 || cnt2 < 0 || cnt3 < 0 then + False + else if x == '(' then impl (cnt1 + 1) cnt2 cnt3 xs + else if x == ')' then impl (cnt1 - 1) cnt2 cnt3 xs + else if x == '[' then impl cnt1 (cnt2 + 1) cnt3 xs + else if x == ']' then impl cnt1 (cnt2 - 1) cnt3 xs + else if x == '{' then impl cnt1 cnt2 (cnt3 + 1) xs + else if x == '}' then impl cnt1 cnt2 (cnt3 - 1) xs + else False diff --git a/codewars/7-kyu/Sum of odd numbers/solution.hs b/codewars/7-kyu/Sum of odd numbers/solution.hs new file mode 100644 index 0000000..11bb86e --- /dev/null +++ b/codewars/7-kyu/Sum of odd numbers/solution.hs @@ -0,0 +1,6 @@ +-- https://www.codewars.com/kata/55fd2d567d94ac3bc9000064 + +module Codewars.SumOddNumbers where + +rowSumOddNumbers :: Integer -> Integer +rowSumOddNumbers x = x * x * x diff --git a/codewars/LICENSE b/codewars/LICENSE new file mode 100644 index 0000000..2beb9e1 --- /dev/null +++ b/codewars/LICENSE @@ -0,0 +1,662 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +<https://www.gnu.org/licenses/>. + diff --git a/codewars/README.md b/codewars/README.md new file mode 100644 index 0000000..02b7f67 --- /dev/null +++ b/codewars/README.md @@ -0,0 +1,3 @@ +# Codewars + +My solutions of Codewars katas |
