From 900692ce255a44e14a725465815feae77fe080a2 Mon Sep 17 00:00:00 2001 From: Gleb Koval Date: Sat, 2 Dec 2023 15:59:13 +0000 Subject: [PATCH] day 1 and day 2 solutions --- day1/eg1.txt | 4 + day1/eg2.txt | 7 + day1/input.txt | 1000 ++++++++++++++++++++++++++++++++++++++++++++++ day1/solution.py | 34 ++ day2/eg.txt | 5 + day2/input.txt | 100 +++++ day2/solution.py | 56 +++ 7 files changed, 1206 insertions(+) create mode 100644 day1/eg1.txt create mode 100644 day1/eg2.txt create mode 100644 day1/input.txt create mode 100644 day1/solution.py create mode 100644 day2/eg.txt create mode 100644 day2/input.txt create mode 100644 day2/solution.py diff --git a/day1/eg1.txt b/day1/eg1.txt new file mode 100644 index 0000000..1ba8437 --- /dev/null +++ b/day1/eg1.txt @@ -0,0 +1,4 @@ +1abc2 +pqr3stu8vwx +a1b2c3d4e5f +treb7uchet \ No newline at end of file diff --git a/day1/eg2.txt b/day1/eg2.txt new file mode 100644 index 0000000..4316a6b --- /dev/null +++ b/day1/eg2.txt @@ -0,0 +1,7 @@ +two1nine +eightwothree +abcone2threexyz +xtwone3four +4nineeightseven2 +zoneight234 +7pqrstsixteen \ No newline at end of file diff --git a/day1/input.txt b/day1/input.txt new file mode 100644 index 0000000..8cfe38a --- /dev/null +++ b/day1/input.txt @@ -0,0 +1,1000 @@ +zlmlk1 +vqjvxtc79mvdnktdsxcqc1sevenone +vsskdclbtmjmvrseven6 +8jkfncbeight7seven8 +six8dbfrsxp +2zpcbjdxcjfone68six +zqmzgfivethreefdnlhpeight8798 +fivenineone6 +6sixzvdsprdqlftwonine +lqztrmztwo8dg +four6onerv2pfhm +plvzrs5 +5282gdnc918 +pskjsrchjpxoneonenine96fivefour +fivefour2hhtprpjndm4 +6qbdcfdjsd1lmldklflteight +gctgdhpkkjninekj65rkqg8 +eight6gcjlsmzt5 +5chvmhmfgl7xkjfdpdbp +5tpzpnrgpftrnine +threeonehqbzktq1 +685fivetwofour4lvgxgdb +9jdxljkfqttstqxdzdsztsxrfjbkqmmsqzseven +twostcllbpndtwo15seven +8fivetwofivetjfvsxzs5kdkpxgxvsfhr7 +sevenlvrc2fivefivesixqkzdkrfour +45jjpmnscmmk +lhxgbfjtcknpvz6 +tndgnkcqtjbrzgbrfjr3fiveqxlktntzthree +vqb6threeeightbdt +1eighteight7fourone8 +bcmqn9onecnrzhsrsgzggzhtskjeightbz6khfhccktwonenrj +6qmgkbkmlxfourprhxrxrdseight +9three479 +9two6zhtjzfmjrteight +1fiverrxdmvfvxhs7jqzzqpcflzt75 +pnjmlpbbeightskgdf6one +6cpzqzfsjtpfq135 +484 +llfvhxglfivesixthreenseven36 +jhcpt9rq7fhzbnhk +tthree5lrgtbxxvonezfmdpseven2 +67jmrxfdmfbmzsixkzghng +sixthreefdbzhslqone2sevenfoursevennlnpjgsx +54zrkfbfq +six7rfpfbzbghxcnxlnfjkznine7 +8dfoursm338cz +sevenfiveeightone68 +dqmvcbdclx23653 +eight58qgjlcvflrggndskff +shmmk28 +93eightdtgcnhphv1 +gdtdjgggtj3dgrqsmvfh +one3pksbh32three +9kkpjrmhmmlzvqngnhftwoonexjqmnfive +rlsevenblrvrk7 +nine9hqmtshkjdhs +93fdbrbnnvxsktggqnjfjk7brsncmxkcfzhm34 +248twofbkfpxtheightwovng +28746threecbffiveseven +eight449 +4eightnine4ptmzvpfqxhrzvrpjhfsdsvlhbht +sevensevenfive6bjf +sqthreevhmvbgxvnk2one +ghpsix5seven31 +7llnsgdtzbxjbbqcmxfhgcdnptwothreeone +eight3fouroneplsrfvqf +4six6one +27twofvlssjbsk8j +njlllqnrvx8four +5onekcngbbmpnxseven9fourzcprjp +sevenfive2sevenknzpxtx +8eightljhtmnxpjhxhnqtwo1rjddcbj +mzsqh3sixfivethree +deightwoeighteight5 +nine42sevenscnjeight97 +2gcrkrfourfivenpzssevenseven4 +eightdtwosevenmj3two +9zkhqlcd3 +ctpncdkcmonehfive9 +sixrtwo7rqnine689 +sevenm16gshq4xqdxqbhcl +zxxnrpstkkmnhcc6 +three1sixninelsxrbkpneight +jzkfvrtmctjz5 +sdsfrh4nine +foureightfive7six +ninesixfivefive53seven +42threezpvxnrg5sfzctbtk +seven7pkfnqggvjthreextfksczdd +xsb6ntlfzxvlxrkx1sevenkmnqxhcdnqkdzt +6sbzfqfdm +lrfjxppqbdseven94ntnskpkdqeightsix5xskh +98czzcq +696cmcdpztwojk6tz +jbpfbqfdd64four2onezrfm +9jfklkpcffive5phpzqvhrtcqvmxvmgljn8 +329sixjglqzqzjnlsqbnqnzsb56 +59three +4863five +6txkcgtn7gtsxgtnine +lxdtnjvjbgxpnrft8eight2cjqfdtrk6dm +twothree53 +two1qf4 +6ltxhxcdfive +rlrdkzgnk6mnsbxfkhh +41z4nzcqzjqrnmsixtrrbgtwo +tbnsixsixtwomptdjtzkxfhlflpcdnbmrbctjscxq6qtmjmkpfk +1vqlkjtmjeightcjzxnzscczqmxcpvnprhtwo +lznhcphkdmrhpninesix344 +fggprsvtgmbbtlk14xkrnbcjrdbrsbdltfztmtwo +6rqlzs34cdlzmxone +two7zpbgsxl +lckblpljvv5two75fivegttgmvcpmlhltxz +bjfbxdpvnj581three +1seven4 +8ninezhzrgg6crlpggmtfour41lhjcqtblh +seveneight8sevenoneshvkcdhgfmxhn7dzccsdfkcx +7zljpgl2 +six1two +fourztcnpn8bsbzfhdhgkjjsthree +onepthfrh9vcs9sevenhljhmprhlsjrr +vlnpmqlpjfour5 +two3qfourlqsninethreefour +hshdseven7 +eightfive4five6four4flrzhrxzlreight +five187 +seven2xlbqkhtflqtsfhrf1vvnbt +onefiveninethree26 +2sck1n9eight6 +6sixsix7two9xznczchmx +27eight +7six3 +ztlbbncthreeseven54three +eight8r6mcrcgrz51 +eightnines6nine75 +nhx83fivetwofivefourrvxqhnpeightwoj +857sixzrnine6dlprzx +lteightwo2132seven7oneone +1516ldxxftfnineseven5 +6fourfivej3 +sjmjp99 +bprsznhxztpp51 +cmfivetwo1four +6mgcffzzspll15djsoneseven +9qjcvfourqdtmhlqzfxfg6 +six45fivetwo3zkpxmxsgxtmg4 +three12four72kvztxqdmfxhrxsp +threeninebnzthreedfqvm93kqmxpsnmb +8nzfbcmghfive92 +914six +sevenfive6 +3bxxccqzdjsfive78lhtpbl +5zdvjxsfvcptngh5 +vboneight4six17 +seven8eight9krfhll3lnine +stv4eightonesixcfveight +rnmjpszvx94fivefzsphkkftgxpsfhvthsbv +zmntmkcbgrtwonspdq7 +5ntxnjclc8six +8six58five +6ninesixeightqjnjfbbtlmcqvthree +hgjh9vhtdtcgkzpltnpxfqhsix7kq +64sevenc9 +96z62ninenine +sevenseven38 +ckk9zdnkjvskct +8flk7 +8eighthqntfrh +8cthrxbjlxbnqvqc496htsltqpqktqnz +31threetwo5 +twofour5 +rlggcjdthj3nine +18five4 +sevenhgncfjnseven1twoseven +kshqgsm3pcd518 +8qrpbpbbmzmbctsmvtddoneninefivetwofttd +fivetwoqvtscrs133two5seven +6ninedcsrftdtwofivexzmpxdccnine3 +threeseven73 +pppkjkgt3 +seven2six1ctmmjvdgj8h9 +xkpk3fivemgmrfph +pppgfivesixnineqxs6onebgsplgfhqp +cvjq15threesqqtpczr +three95 +twoldjbdxnqncntpphxshbthree767kfqbsqhlkg +9lfhbgmcqnhhlvvpvdtwo37 +v7gj +23fvgbbdjgst8 +six3frmpq +zrggqtwo6sqr8 +fiverdrxxtjlhzn97fxsqpxf +sevenlpb2sj3one312 +four6six9fourjbsix7fnr +lpbgnkhkkbninec8three +spvkzsthfour2 +ljbrlhtkxfkskvdbgxqmmjn3nineqmqtffkfive9 +h1jmxtlfivenine1djqrsnpqccvzmdhsmxnqrjlgdlnj +8threeseven +1onefive6one71five +qbjqnfsevenmls8gdnr66 +jgpzsix76pxldgpcvdcpzn +8nkdjhgrn +threeeighteight79 +9ninelzzrjqpkseven +75six +threebpfsn3three +4twonel +pjvmb14tzbz2tpfourfourseven +zslfour1pkklkrsixncvjtkn +honeight3 +six7stfffkjg +42fourktbdmzstcgmdtcgbhffthree +two27 +ghvrgzj6six1 +vxjqk3xhlr3 +threetgzkjslbdrdxgfzsd3lcheight8ninebxhzf +sixfive7one +f5 +qq6lkvlmrnseven9three +8fournine64rzdnnhgdsixseven +4vttbdfivesgdnjsvsxt6 +765 +6czbdlfcfkvplmcb +7one52 +eight6neightone +six5lttjtcbxmxnz +threetwo692eight +dhcztvmmlllg8four +btdjgnh9vjvlqfkznqr635hhcr +2jvbxcfournine +4sixonemp299sevenfour +1sixmdqkzqtgzeight7nine9 +4nnhfkrlmfpseven +blhvfourtwo5vrlqtqrlpxgd +kptg4eightvglvjdczfive +5599msgkplgqfnzseveneight6 +3tnfvgftsnbzksnrhtrtlbfxcfqfjgnndlmfvkqvhcmgdtwo +txvjfglxtbfive3zpx19 +six9four5 +5fourseven +fsevenmnfskhckvfszs73rnjqjhsseven +95knstccbfivepgpt +kmtjfxtztqnrngxxgcgh1kdxpdjzspz +two2rtcmvpbzsmfourchpqthree99 +fzteighteightlvnoneslhjmcrqrg8pzvszdxzbp +one49szrxcjvtt3eighteight +8nqbmcsthreeninexf7 +fvvzvpmsgrrnhjksf8l4 +7msxhtdk +jgtwonetwosixthreervlmxlnine869lbqzxpqqn +nvdn6bdg9ninesix +82rxtf +9tdqsdppseven7one +tlbbxvtwo8one671bhghlhdpfh +3onethhhlmgfhseven +n2six +53eight +one5five85 +three5375nine55 +fhvxvtjcnn3stcjhsdjtc1hhmk +six1jmgzrklbxrmzshpfgnv94hzfd +737six +25nine +fivevnpmlzvvp118lbv8xzplfttx8 +ninethreesevensevensix4three2 +xkgtqqlcdr51bgtx +sixpddqmbb5onehbmjfbpqx3threechgvdkghhjhnxl +7eight9sdcq1 +9ninejbcxzp +3two2sixone +seven8fiveonecrcqrglql141 +4nine3cllndctlninecrdxsevenbhbqsgtjnchkmknpdht +sevenzfbnvgfive3threesix +tvvjkskxgvfourxhccmmpxqx8mtxmfxmrcnine +ptnnhktxxn2qrjvmddszgcftlpdfvxcpkm +mboneight8lbjvvfzrl8qgqf +7twomjfhzl +sevendrdvmx2ninethree7seven2 +zoneight6eightnldnvhqpbd5 +29c +kzfkvqqs2ninesmlcrg573five +vxcgdz24ljhrhgsix6 +one3nine53xtr7seven +djdeightwoeightc2six6nine +eight2727seventhreeone +3gdtc7llsdlftdrx +581vjcbpmrzlp157jjcmlrzhr +7eightsix8fourgg69 +zsh38twocvklone +three6np +9tvxqtbpf77one7149 +7three3gqfpfqmhsfxqbqbnv +8rhflhmhtbm +217onethreelgfmpdscnine98 +three3stnst6xqqxvxzkfssevenbzktd7 +46ttbnzlfnsjbc +bsqxtvhgthree58four8seventhree +ccntwonedsjvftmftwoeightfourbxxt5eighteight3 +threeninembphrpfourone13hnjvn +bkm2onez6xxdjvnxvxjrtwoeight +jztoneight8gsmnjcfvk +six3fourninetwo62 +99dndgmkcctwoneftn +eight7pkzcxqhzfiveppvnineksjfhhqgm4 +2ngrttwozgdsrdsfq5ftgsq +fourdnmxjn5997eightkxkkpseven +rxnrnqvm98zjxxmkflone +three1dkmtwoone +6tttkrtnhgfzx8five4shlcvhr +nffggbxmhkpcppm8kjhktmdvlkkmrffdng254 +mbjm445 +6nfqxlhklrmfour7 +twosixsqtsfcleight8onefdsjxvbgt +9bkkrznine +fivedzpnp1 +cctxzzjbhgttmszdph1sixqseven2 +1qnfxpzfg2feight +5gdj3shgqvjdsix23gqp +xdgxsrshddmzmhkhznsdthree4one +gmtsixsixninexxsxone7three2 +1rttbtsccr +threeseven1fdzqvmbnsfive6 +nxqxvhsix41385none +sxgmkrzmbvn4sixfive5five6six +three6threepdjsseven3kgxtwo +8grzmhsmkthree +seven1htzbglcdfbcg +5nsjsnrscz1zhrvjmtg5onefive6 +two4one +dzl41four3threehbbqnkhn +onebsm86 +xh2 +eightqmdbfiveqv21sevenseven +5onefour3twolrtmmonetwo +32seven +vpcncrhjxgcs3sevenninenine5two +mponeight9glbvgrff +zgzzzpfffneighttdcplkbfr57 +7nineninemfneight +3ddrsxrmbzsmxkdfive8 +pnxtxmfrpmtwo3 +onerktgpv55 +79twosixhnnrqklz98 +5915vnrpsj +rfg7szlxneight +ninejhnzpnhkrlqceightfive5 +tzcgzzx6two3qfk5dffgnp +ceightwothreerqnfl5fourdfbrthreedntdchgnine +sixnfmdk3sixthreekgvmrzseven1 +mcdbsqnrzconetwo1dthreeeightjfjdblk +48threejtdnq +threerxnrgzd9 +vmzgfplpveightfnctwo4pptlb +ninesixqtbqgjvqv1three8 +cfnlshzvczgvm1onefive +gsskzxkgrbzx5pggzmsfhtwotrsvmttzdc8three1 +3sevenfrc7vzg +dcmxmg7d2jlbtfhkr8 +62nzzeight9txrzlm +9pjllhmfgkvssixsixthreeqmzthree +ctjksjbbdn28 +39fivefive5cnqjtr9vpvsix +jlbjfouronent7mlpqpcvqcmhfhvqjqcmtwo +2kpvxg6nine +seven4mlsbhzcmjfthree8 +1khfjhp3fourrh +ninesixpfrjvfm8kkjsrhttxsslhtwoeightwovvg +four2nine +fourlgcbfptfz45nineeight5eightkqtbt +5sixxqggppnl7 +51zvfive1v +fiveoneqqk5seven7four3five +kqlkrntrcfrhtwo9scczeight8dbqmfhstnzq +ghdjlnzmskmvjeightnzmpbjgone61 +three8jrhhmfnfive3four48eight +nine87ninekfzh8 +329nine +jgtwo3xvlkbvhrss27vltrghkljq1rkzkls +vrcfourtwoqlgcrxf274 +sxzkxpvnhsixsevensixtgptbrpnfthhnj15 +5rqqntzlq1one +1pnine762fhone +ttghtthree5eightbqm4two8 +2pmtldtwo6onedtsklbcbjhone +fourseventhtdcsmc5 +xqp75five99g4 +mrjpmm4crgk212seven3 +qjpdjb1 +two44sevenqtcdhxjp35xxx +sevenvtd7ttvmsninergrgdxbdqcthree +pgkqpltdzcthreemzrsrqjfourcrghhsfsjcqtmvxq4 +threeonexfrdvr1nblctsevendqmmzdr2 +8three2six8 +59twozjfour2 +qgtjgmrvfcffour29four5six2 +zzhnine3nineknzkvmbxvm54fivelrrgc +fonesix3three +seven6fivetlhhonetdzrkhjzqzseven +1ldxvjseven9eight5 +seven2bcbktzsjpp +2kxqxflk55two7cflfdfvsx5six +5lvhclqxtf +one768two +vfh8 +nineseven3xpc2jkvmgkqc6two +vvcvzfb947twortlnl96 +seven58nine4nine8tbtjqfpgp +7onefive4lbhslhdpsbtwo3vm +foursixsix3971fiveeight +nrqxrffqbp15 +mklsgg3oneseven6eight4bnbfxf +9five5klpzgrccnxvd96three +sgbqgrlqreight8 +jlvrfrskmlrdtdpr4foureight1xccgtcf +five5threek4hsmqjq +five6pxqlplmtvcvjgtbk +3sevenninefourone +nbrthreeone9gxeightlrkfvgtzhtwoqvnfb +teightwo972hrdrlgn5mpbjrxprpkjxgdkghgrgbthree +7nzgktdsvkjlqdlonergplcdqvv +kzxttx3fivesevenjdlqz9eight +9slfgkbdmq24nh595two +tkbnjhjrfivekqqxsjleight1 +seven23kh2tggrone +12four1xcvkxbcv1four5zs +j7ml +8eightone58dnxhddzstmfleight +mtd37fiveeight3fxcbcd7 +2fiveeight +zkmvsnsgnine321mtbzzg +4tgzhmf9 +threexjqtqzgzj4kvdtbpjv +twohmnpsqbdcrbl35three4seven +2twolpmdnxmcps8fourttfrhzzx +onegqsqrhx2twoeightcxmnxvzsfivethree +2eightseven92sixcjmkzjsl +9gncpkg +six51eightfourkmqbrrkkrjzmhgsevenfour +9bhxxzseventhreesglvvpjmc83eight9eightwomd +164cndtzcrdrxfzgnvqkvd1threefive +43sjlrhsrthqtwoqrxkqsixsix +twohfbqjxmc3four161three +4ngvsmdvm +xmhkgqdnfbdxcxm9 +lqgxmshjzgggj9jsqnv96one +vt2znbmqonesix1gjppfmsevenone +nvdjzzlspjthree8eight +qzvtwone1one3fivek +eightlfztsninepxfstsxtthreefourthree7 +k6 +zmeight2 +3cblxxxthreethree232 +two6sixcsgnzqbttjdzqs39oneightdr +bnjzfkmfh8ndfssix2pff8nctdvdqk +spxskgfmtgghlmklqzz6tdgxnbnnxfmgnfiveseven +cqrlmd62gsh +6rmrzkv4 +nineone6dbtzrtsp8sixzrhjhkrhvsxktbdkjcrone +5pvhbxqdvvqhlthreejqvs2 +lmeightwothreesjrsqgsv9 +seven8two92eight +five9sixeightonevzqtzq8tcgpbgthzvlcld +51ptkkdnzhgp +7jkrtwofourfour +xpzvfcdv1jvbd5mgvchdbnd9chlvqkc5 +27threectsxpfd12eight +prqbfh3foursevencgmhkmkd12 +one5seven8threegqcznrrxfheightfvkjkssbch6 +1vgsixeight3sztxzjkgldmqqbrm3 +jjcpponejtxkmnmggtfive3 +sixlsqgmqkjjzrpqj3dgsrpdzj3mjkdqhpq +slxstvfive7nfst +6fiventqxzhxkfivekcdbhrkx +sevenjqmfmbjfoursixcx7threexspc +kgqjjxfkmhqtf22htnvmpgxsztbb5 +nineqzgzsscrrfngnzksfour1 +9threerq4rhnbmhhsoneseven9 +6eighteightmjbthree5eight +threexhzqqs2kjdqvjr4 +z3ktworvbgbqzbpt +2onefive6 +c69492 +eightsixnine8tpjcxmpln +mxxfpjsplj3msxqdnnbcbbqxfzs5ninecmjpzq7 +cnineninesixfive3seventwo +six18eight3eightfourthreeone +6zdtsqkplv41jmrk7qkgjpkqgmmqsttvrhkzone +7threenvbjsvbshmd4sxffiveqvvctwo +two2two7lpmsjl4 +sixceighteight71psffhzjdjrm +seventhree2eight +qpmpfdlr7 +dxtzmkcrsix5 +65oneptbzdxcsqseven72five +7bdmgtzdmtwotwoseven8one +14sixckthree1n2 +twotwo5hpqhmnnjbsix35 +one5twothreeeightglqdbjlgkseven +one4twokzbdzv +8mcv71six58kkxdqx +bgbvdrfsixfqqvnlptzrqkhgmt8 +37oneightrmm +3onefbtvqchjthreebhxpvlqcdqh +gjcninercqpvvzdfkcdcfv2 +13fourbgntvtnxmr +8447zdxvzfkft +1foursix +threefivetwoseven4eighttsxflbcqtnfourthree +tseven1twolzjkfdttfklsdzrrflnfxfgvlq63 +four9fone9twobhppd +nzcvxgjqrsfqgkktggdlnine5 +57thz +3threeseven25 +zsbc6fivecqvlhtwolqone +nnsoneightdnine6rhckhj23fjj4 +cj1rbxlggxxgtxxbmtgfg6two +vhkgpz4 +nrmskeightone9six2clhcjkcl9jk +onejvdcrf96hbv +seven8three55 +1sixtwo79 +jcqknvjppbxsphlxrrcbzmkqnine29 +2fourvgzhnq +2six93rdrkfjkqlllx6nine +77onevkvqhvptbn +32szxlxdc5zlrtjdqpt5 +nine75hzkzvdseventhreelxt1six +vdbgshtjm8grgllht4qhpkhdfour +mrvdgqvseight3jtzfdspdtrkf +kcg2twoonelcpxlg +2xlcjcxzczt +1pszcvn12sxmcbdxznpeightxvdjjbgrjlpdv +fourbsbkvnineonesixthree8 +945five5one +nine71gzq79 +3threeeighteightldqcgtbd +two671four2r +bbfpvdsvffour5two +767l97hm +twofour5 +xxrs931ckbg34g +qhnht4 +nine723nine9 +93preight5f6seven +one8qncpgpl +fiveeightsix8jr2 +twocdv9lrtsbcdtvz62pkzm +dmhfljxqxeightxmbprh2 +rr5 +5twotwo +three8two5 +4rjqmbdtxv42twoeightseven5 +fourb349six +f31nineninetxtdtfivehc7 +1one3 +2eightxztclpbvkp +bkxvnhhn6nine211 +1twoseven3xmzg +lnzpnine54eightwoqpr +gnhdcgdmvthree9nine +vlxjmdc1fivesix +nineonefour69 +ktdkztzmmcgxslggh7dhptrkgfbqnine3two4 +qfczhgjnt6 +3fourrzmt +onethree2four3nztsmbqmtldgonenlc +29six9xlffbvfntz85 +five6trqbjkhjfmrlgpcxseven +threegz9chglg6 +9tq +1onefive8two84ngrh +hrqhreightfive1lp +onethree4 +two8psmqcbsixsix +sixseven3xxczmccll +fourmmlcgbkhktbmrp5three +27sztxgmqdvnfivelfcpzjsx7one +hdbhrqhhffbgjxvdpqk6sevenbn +93ninezmtrgjqbsp74 +gsljpvzxkq9 +zbjzzrnkbeightseven1four +fourfivetwothree2rh5 +155cqrh1 +1tjdeight +dvnlk78cbvdrccmmx3seven +8seveneightsix +ffjlhcgxp97plmttszkvj7jvtsgsevenznl +121four +threetkqnxtwobvbmzj4ppkdxqtblszmxqhqbv +5sevenxgcgqnlpkpnfmcnkbfbeighttwosevenhpht +gkgnfiveninelr5eight +six4nine73szmldmdd +9jfgcslbrcz +jrgrnmntmtwonptz8eightninesix6 +238eight1xtjdgb +2one66fourndjcxmmbhfcq1 +5bmfntsevensix +5832663v +7sixdzmhfrjonebdqlqh8threeonenine +92six +vqpg91hspvdgtwol +fivembzffnlcktwo18four7 +six99nbzrgd8 +onexqflrlvdmrsix9nbl1szkf +vqmlzjc1d3 +three7two4vbgzthree +twoninejbbxhdfnbqjddj26one2 +5nine296ninefourone +onevznthreedbtjtgxhh36sevenfour +zfkffkjsz7btqgtm1lqvsix74frjhrkbjj +sltlgnine6fiveninegglpc8ninenine +two7three +fourbrmdvfbtnnnhr1mnhbztwo98 +nine6slnine +cqkfp35hzrdlcpcsjhssdlnjv +six42seven32five +zkhjblqjlsfive9kbxzhjmnzrxbrrj6sevenjdvljbh +9ldrjmjpqeight4pnmcfvg3b +lone8 +two1sixfourgskrlfkxxdhbjspmhg +4hgceight2one52jmbmjkjb +six8zfbjxfckfivesixzrpn3 +vbrbvv6 +jfjkvxcrbjhztvtmjbp15two6one +3xvhtzgqpn4td +xthree44 +68973one7rmx5 +ptbndknk26two8cv7seven +57417four +ngeightwopgdtlxjgs3threefivefivesk92zgcmch +pmfjgxpg6ninefoursix +5hlgzgrxhxxqt8 +1nine3 +gvdhxthjxnxv7dtzninenine4 +jrtwonehzddmgcjsn6rzldcsfpqs8eight6six +5fourfive +jn6 +two2four +567ninefive5fivefourdrbh +36sevensixkbphcrstnine +76svmjhhkrt73 +thgzhsclsptfqfzpsnine4cxxpv +two1one8fninefdctxpmtk7 +seventpxmbxcl9 +cghxxdnnf7vmvqdfhhxznine6dgt +soneightsix7 +7ft3threeqdhxjmkgd6vgfmb +1threesix5lzjzrm +fiveonedknfvkphltcxnsvxpvxlxldxrqftcmqvvqx6 +sone1tnmqklzvbbctjvntddpm3 +nine9vb +eight52threeqnhhvn +87fhkjhseight485 +1onesixzczvlsmhbfour7 +3ztseven +7tjjbq2three +sevenv1eight9cpvmrn8oneightnxs +1threehlhxjj2eight +six87twofour3646 +eightzlmj2zreightbflxtmdbv +one2eightznone +seven2eightvlxkqnpjb7dlqrmnhtfive1seven +43eight3 +fivesixfiveeightsxrvgmpshvone7 +7dpmrqeightone1rdfdrx +dtmtpgjll136dbcjlrhzrdnm7svlrdrcngpnine +5dl9 +94ctwo4four +7ninegnssldmnmqc +nine1sevenzdvkpxxsfccmb +none5five1rsrsxpxnlt1lxtf +sixpl9nhgm +51brpphslhjtwo2stjrkphcgrfive +fivetdhlrcbtwozdsfgcdnhv67fivesdjlqnine +4fourfour7sevenfourfivenjdxvf +674one46 +6ninentdksjfkdvhkkxzrgftnbjmfsjgzd +4ninerpvfmfonetcnhk +1ksbmzccfreight5 +3vqr +ninegqbgveight7hggnxxgrq3 +sixfourfourseven1rfivekcflqd4 +mzvqrlp1sixnine +sevennine3gqjmqrq +6vhp8one251eight +5dnsxqrb3twokdzdbdcncm +srcmzlkrone9ninegbfnfmxjf +82lmhlhmtgfour6nbljxrgjb3ninesixtwoneqhc +6pctdhrmhrgsbm +sevenhgpfqvkh5three51jdkqz84 +hfzlmldpn9tjtlpb +phccmtthonesix6 +3fourbrzqzsbnthone +11pssjfqkfivebmprltbvm4 +gmtc2five +one2lj4fivetwo +ninexjrzfonehvntsmnzx2 +fourg746jpxvrbzdmseven +six76436 +89gddfltmdkkmleightqbzppmklxzgpnlg +sevenmtfmdrbcl9 +3cpgvjgzxsixnine5hvrxbdnclfgbvfsix5twonelv +eightklzkzxltzone5 +377bqrbsdk1eightthree6 +2sevenlfqhmfour +21oneonevg9rr +onenzjgjxlmtrgbt84onenlls +7rlgkgrsixfive +nmmpl6fc7ccg8lkvpvqplztwo +mzbxkmfcd89six +fbhzskjt4seven3jrvfjhqsbcone3 +five3sevensix +eightsix6 +n9 +threeninemzpjqpcpvnine424ninesix +8ninesfour7 +twopbsbvdpnine6fourfive7qbbckmhxgg2 +5ksvzfbdbgvnqonehsgtvgkbgjkzggsmpvkxpxtft +qeightwo2three68nine39lr +5gpz6283five +19fourjctnldrqlghx +gtwonetbqxnvxlz2three +jdvmph5fgztldhtwoxhzk +fourgmhflfpxmbqpt8jdxkntnchmtkgqhsgthree +527five +5sixfour +mdchltjjqmfive7 +kn6glgjlspeightfivej +3vsblvhkmt7 +17rmnoneqqgqmcvlseventwotwofive +eightjbmnzngtxsix3two +fourgdczfkvs3onekrcm +2prvszkhlnine +nine67mqtxbthtfxgtwof +lrcrninevgshzsrmj9threethree6 +bslrhlvpthree49fmlzb +3nzqmndm7hxzrlsxgmt +48jtjrmzvtct +pzpthxqxs9pjkhxc6gk5 +eightbdvrcsg2tgjkzzj +2oneeightonemlgpgtdg +8sevenrxksglxdfour3lhst +four88sevennine1 +fiveqszbfmdv8xfiveeight +sqqbhtk3nine5mqzkzbzlxlhdtwo +8eightone +63njcjnbhptone75fqhg +fourthreefivesix9pvfivehmbhmhtrplseven +5fourbfnzxfivenine8four +rzhqrxfhpf9seven69kcjhxv +nlh3fourfourlbppcjdx37 +hntmdckqhonejmcfphrrthreesix3two6 +eight7sevenonefourfour +nkhfgtknbjsixzrpppnqsone15threesixfive +nine5xlvfqmfourfive3 +sscctsdfourkppsrd6eight4 +eight92 +1oneightfs +2hmgrqgjznhh1xztfmthreev +jvpzlqbsrb3 +pszdpm3 +kccl2 +dzxmqpgfive6338seven +9nqfpv +prphfourninesix5six +57vbcbcvtbgtqmktjscjbzfkjgzzv7rspqlrdfsmbsvbmb +qxqlzmeightfourhzvctqsxczg4qggztsnrzz +79seven8rzgzhksz97tbrftfllmpone +twovdspsvmftgnfjdqgjpv92qdqzcgr2 +6ninesevenninecxzmvlczjf1eight +186 +fourtwo324five5eightv +six95five1tnpsqkr4twocgnbrtr +threesix2ksh +dpbbkpxvd457sixbncfnkbleight3 +bxrbglhfcz2five +8three3fivethreeqjg54nine +nineonepvhrzcdm9lbqqgrdmggzkqzvhnbczrhhvjz +3rgljppmcftqmqkqbl +9threeqjrjrgseven +4qtfn +five7fourfourhbspnlmgsmxnxt5 +fffctbhcpklfndj23twotwo39 +62sevenxnxthreefive6two +5772six9five +seven599rpztwo +onefiveonemsftxtqdcsix7jngtvr +12fttpqzzlk +zcndrqjsfourthreethree11seven +nineone8 +tdlbrszns4pdlptfvcnxqhx +5six2nine8hvktskx +5xvcnbsix9vnclxm +94ptv6mzgninesk96 +4lfvvczdgvh8rzgkmvnk +74nsvkm5nztmctpmngppzkphltpx +46two9four67nine +oneonefive5fchd3nksmgs +6vnstxdtlninezgdvpmjjcxlqvc +6five3 +7four76rklqgljhdzzhdcqrqzpxmfftbcfiveoneightjzg +43eight43955four +gsrrtkpqpseven1fourbfninereight +6rvdtwotwo4eighteight5 +foureight9 +468cgbctpkqninetsxskqbhmj +7twonine4 +8jnssjzcgpzrvbqzmv5three3jmhfjcbtwo +4qjrgrntbfzghfkzxvmj53pcrjrlls +twonnjv8 +97three9zgkhgmrcfour +9eight23 +qtsgznprvthreethree6 +63tworhdlrfstgxfmjjknfourqfvfjjz +sevenltdcgs8three +bjctzmmbhrqlfzqgxbcdgdgprv9twogjmrdclzt +63lslhrbmcznine6 +66gc8seventwo +zdrpnjjtwo62ph6 +ninerdxqgxtqrrgx3gz3three5lfc +lflcrscclg35oneeightpmhhm1bkftvxqbmx1 +74rgb +six8ninelvxdqphkd6 +5zsbfjsixseven1 +4rflxzvnn +mjbpr4qjjhvbgn +26four6drctrdmz +6mrzflsszvq +fcjbdqdnh1stglpmc6nmvggcvnrghcpcnz +one2four48fourcgkvvnlzlb +kc2461two +fivethree54dbvxmf +849psvj9six +hnxg5rbhbqzzeight4 +zzsix45glphncrrq5two4nqrdsk +seventhree5qpfour7nnbllpkgveight +bsh78mzxzhhseven8 +jllhfive7sevenninebcmninet +nineseven4pdkfpdzqpbzgt +sevenninetbthree5skjmeightfpjrq +nxkv6 +four59 +zrhcvb6qlctpeightbnphxmlk1cjzdbl +8mtgqjthreenine32 +6slj8zqbpqmr5 +rqkvxmqtkn8oneckdxtqvxcthreehngfdqqsseven +nine4nfqpgdpvx9fivethreefourfnhfjmfzqr +3gdxbh2gbm6 +72qmrrqbsflqpspdp9ff8two +xgbphtnjfrg5fourdfmsmqhfp597 +bkkpgrhj8hlbsqmjdjqxjtjkrgppjgszpmm +five71 +9rmmf1hqqsmdrrfour +7ninelflmvj6seventhree +172 +tfhqv1 +jfbtwoneninenine6dgxnqjgsteighttwo +4dnvfvx +37sj6three48nfjtclz +2two4fsbbmrtnlqljqdskqseven +1pnpzdr3sevenfive +fourrbktzvtslxjdz9 +47six +jgcrllvbsvnrnmqfppxjfournbmjgp36nineb3 +s6fgr4four4 +cmpvp8three7 +xjqmgdrvtlv5xmcpnkhvfhrbjzx +117eight +9snnxnrccnonepdbfhhqcnpsevendsffjsvknpvmkdxp +rgsix6rqzsix8nine +nine8two +2clfqtxkztwo4twobjscfzptgn +6s5dnfkpxts5five +five9cst +eight71dmbdqfgtpvj3 +vdf3fjfsczlvvnine3foureightfivennhqmcdbdb +two59eight9 +eightdkfmscfmzrk7ninespg9 +sixseven46seven +493djtvlhsixnhnts1sss +ninepczttwothreemtz3three +fivezlfjhqnknnhdfour8eightninetwo +4ngvsvfivemgthtlcczfbjq1ngxvsbmt9 +sixcgkmnd2 +12 +nkgbpqfvvb9threesixqgqvjgzdxm1rc +five7seven +2seven8151 +86eightfivethreebgbfvr4 +355 +hgldv8four2dzmtpdsmck4five +ninemb7gtqzrpbt31fourndtsjkhv +3fivefourghlmgfhninesbtcsqone32 +7krkptwo4qmzhvpsixthree +74ppbsmnpfthreefivefive +9four5zdkprcnbtl6 +four3seveneightbrmdbcxxrk +twothreerdvxmqsbtgtszmxr4eight9jzbxpfstc +73prc73six6three1 +9fivesix5fivepsg +two98two98 +oneseventhreethree4qvjtzksdsz +tnbsgjqdkl22 +rmlbp4seven45 +9dpzqbds2pffivefqrchvhpvjbtnl +79hdzstwofoureight5bjs +t2 +4pstpbdkxblnmv9nzfzsttfgfivefiverrtlmgj +zkkhkggtthree3eightseven +d11fourzfcnmzbxgbpf +66six53klhrdnbtp85 +onenineonelsfhzbkjgsfivedhzlfcvh8 +jdt4four +bgfzvxthreeonebhlqjbprf1 +sevenfourktsxkbbgt5 +mmqffp1 +vqghrsgxpsssix2jxzvdjdconeznlgpxbqdlsncrsix +5bnzrdptseven8nine +zqdklqmjjc2rl8jxtmsixxftvspzlhfive +vmn9 +7mhhcftwofour21sixvvhlmspeight +blvhpfour354sevendrllsfivexmt +six5fivetxrvnvftfvgcddshzktwo83 +3mdcpcj +zdtjmglv8rkgpfvninethreetfgmx6sksteight +48five8mnstwoone7nv +cbpvqbddlllczgfmninenine3zqvptoneightx +1two2 +jxfhzr35threesixlxghqbqtq +nftv7sevenninetwo2seventwonnkbvqnjjx +eightgjeight6f4 +2fivessrktznhjvxmghnlhbmfseven2two +onedhvdg82xdvgmhxzbqrpzlnfx4 +17nzhkkpchk9 +dzccfzphmz6sevensixeightmcvxsthree +onettfmvfhgsix1two +eightone37 +2onepdnbrbxk4foursevenzrmzmvqzgstppr +five536seventhj96 +nlhqljfzmb4khqtjh +j8l +2kpmrhmhonefour +2jblsixkbblgzbfprhbjnrtspcqs +6twothree +two19eight9 +fivexbrjpnhhlvdztthree9 +jzlmvxjn9oneoneone +2cnqphtdjgdnhbkseven2fiveninefive +threetwonine67tqpbdfhfbv +smgr56slfpdmfive6ninehmqrck +fqqnjqpccjqt6six75lpfczmnine +bq2mdxchhmbxfzzkqgsixrbcpklpqnxsvnbthree +eightthreefxxssg8cx +lhlc6 +nine6onexmvlbtbxznmrztnv +8fivedlxzgxxflbltteighttwochtxlfjx +seveneightfour1three4gbcnnk +8fivejtxbpvmpxoneninesixzdrjhtncbnkgpsxqs6 +1hxsxn84eight +sevenseven71phgltmtxq4 +8fivepcqthree3dn +f6bbrdqflknp +fiverpjbb9rjbrfrlrnine +zfqpjjktg5seveneightfiveltvvtxdfk +flhnczsbx6 +tsqlvphjmfourrcqsjj7four9six2rnz +fivedmznjqtwoqmone1 +eightfllck3spsfrgz92gmcgkgg +tcrrrztsevensixqthpdqgxv91vvhbsqgzkq +22pztfnhh554qdvzjxnnzzrj +tscrkt4 +fzmsgmzbz5 +rxzsnjhcnkthree8eight +9fourdhjpp2648 +4chvdrvtgqgbzhcxztwosixsixhnqknqmntzlltqncdxddnjlk +xbfk2cr +hrmbslbdgnine8nineeightseven8one3 +kmkdhbonesix79rbshvkkvjnzzq4 +9jrz26 +seven163nine +83sixgvhjttnhkq9frphcqrng +8five3seven +three16xqdzlkqjjtf +5fiveeightl8veight1pxfptklnhj +npllktfive45nhvqjcjgpxx +hbfr9mm +onerbfkf4threeone +7eightone +eight2kmjlsix8one61 +rvrnrdrninenine3zq6jqsr +lztlntnsevenpplkhkftq1 +tfrrjmcvtbmktnxtxkkrcctmc33four5gfqpcjreight +33rgcjxfsfqsvxxbxcnrjfndrrfmrtk +3627837xhhb8 +bmjhkkn4pgf +qkrsvjclp23 +5fourzllbmcgkxsevengkrzkpvcmvgtxlrv6 +fivetczxxvjrrqfive1sevennvj6one3 \ No newline at end of file diff --git a/day1/solution.py b/day1/solution.py new file mode 100644 index 0000000..245a326 --- /dev/null +++ b/day1/solution.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3.12 +from typing import Iterable + +def first_digit(s: str): + for idx, c in enumerate(s): + if "0" <= c <= "9": + return idx, int(c) + +def first_word(s: str, words: list[str]): + indexes = [(s.find(w), w) for w in words] + try: + midx = min([idx for idx in indexes if idx[0] != -1]) + return midx[0], words.index(midx[1]) + 1 + except ValueError: + return None + +def not_null[T](i: Iterable[T | None]): + return [a for a in i if a is not None] + +digits = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"] +rdigits = [d[::-1] for d in digits] + +if __name__ == "__main__": + with open("input.txt") as f: + lines = [l for l in f.read().split("\n") if l != ""] + print("Part 1:", sum([ + first_digit(line)[1] * 10 + first_digit(line[::-1])[1] + for line in lines + ])) + print("Part 2:", sum([ + min(not_null([first_digit(line), first_word(line, digits)]))[1] * 10 + + min(not_null([first_digit(rline := line[::-1]), first_word(rline, rdigits)]))[1] + for line in lines + ])) \ No newline at end of file diff --git a/day2/eg.txt b/day2/eg.txt new file mode 100644 index 0000000..1cd7d33 --- /dev/null +++ b/day2/eg.txt @@ -0,0 +1,5 @@ +Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green +Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue +Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red +Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red +Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green \ No newline at end of file diff --git a/day2/input.txt b/day2/input.txt new file mode 100644 index 0000000..41ecd2e --- /dev/null +++ b/day2/input.txt @@ -0,0 +1,100 @@ +Game 1: 4 green, 7 blue; 2 blue, 4 red; 5 blue, 2 green, 2 red; 1 green, 3 red, 9 blue; 3 green, 9 blue; 7 green, 2 blue, 2 red +Game 2: 1 blue, 2 red; 1 green, 2 blue, 1 red; 1 red, 5 green; 3 red, 2 blue, 8 green; 3 blue, 2 red, 4 green; 2 blue, 4 green, 3 red +Game 3: 7 red, 7 blue, 9 green; 15 green, 4 red, 8 blue; 3 green, 12 blue, 6 red +Game 4: 4 blue, 11 green, 6 red; 4 green, 2 red; 12 red, 1 blue, 3 green +Game 5: 10 green, 4 blue, 9 red; 3 green, 15 blue, 11 red; 15 blue, 1 green, 2 red; 8 red, 8 blue, 5 green +Game 6: 5 green, 19 red; 6 green, 13 red, 2 blue; 2 blue, 16 red, 4 green; 13 red, 9 blue, 5 green +Game 7: 1 blue, 6 red, 6 green; 7 blue, 4 red; 6 green, 1 red, 11 blue; 3 green, 4 blue, 4 red; 6 green, 13 blue, 11 red +Game 8: 8 green, 2 blue; 20 green, 1 red; 1 blue, 6 red, 6 green; 9 green +Game 9: 5 red; 4 green, 3 red, 1 blue; 1 blue; 6 red, 1 blue, 9 green +Game 10: 2 green, 3 red; 18 blue, 20 green, 9 red; 7 red, 9 blue, 17 green +Game 11: 15 green, 7 blue, 9 red; 7 blue, 10 green, 7 red; 5 red, 3 blue, 10 green; 5 blue, 12 green; 14 green, 8 blue, 5 red; 7 blue, 2 red, 5 green +Game 12: 3 green, 1 red, 8 blue; 9 blue, 3 red, 3 green; 4 blue, 1 green; 2 red, 3 green, 1 blue; 4 red, 7 blue, 3 green +Game 13: 14 green, 1 red; 4 green; 2 green, 1 blue; 14 green; 13 green, 1 red, 1 blue; 1 blue, 1 red, 5 green +Game 14: 1 blue, 6 red, 13 green; 5 red, 10 blue, 3 green; 19 green, 1 red, 14 blue; 4 red, 17 green, 9 blue; 12 green, 10 blue, 7 red +Game 15: 10 red, 2 blue, 18 green; 17 green, 3 blue, 7 red; 18 blue, 8 red, 12 green; 6 blue, 6 green, 12 red +Game 16: 14 blue, 5 green, 12 red; 7 green, 3 red, 9 blue; 4 green, 1 red, 8 blue; 9 red, 19 green, 12 blue; 12 blue, 7 red, 6 green; 5 blue, 3 green, 6 red +Game 17: 1 green, 1 blue, 15 red; 1 blue, 3 green, 12 red; 9 blue, 2 green, 10 red +Game 18: 12 red, 7 green, 7 blue; 3 blue, 8 red, 1 green; 2 green, 17 red +Game 19: 1 red, 7 blue, 17 green; 11 red, 15 blue; 11 blue, 18 green; 6 blue, 14 green, 14 red; 16 blue, 8 red, 8 green; 17 green, 9 red, 1 blue +Game 20: 11 green; 1 blue, 4 green, 7 red; 7 green; 3 red, 1 blue, 6 green +Game 21: 18 blue, 6 green, 10 red; 12 blue; 9 blue, 2 green, 9 red; 9 red, 20 blue, 1 green; 8 blue, 6 red; 19 blue, 1 green, 4 red +Game 22: 4 blue, 16 red, 3 green; 7 blue, 3 green, 12 red; 10 red, 7 green, 10 blue; 7 red, 11 blue, 4 green; 3 blue, 1 green, 16 red +Game 23: 5 green, 8 red, 1 blue; 2 red, 5 blue, 3 green; 2 green, 17 blue, 4 red; 2 blue, 2 red; 7 red, 1 green, 14 blue; 4 red, 8 blue +Game 24: 1 blue, 3 green, 1 red; 3 blue, 11 green, 15 red; 3 blue, 2 red, 12 green; 9 green, 6 red, 2 blue; 15 green, 12 red, 3 blue; 13 green, 1 blue, 13 red +Game 25: 6 blue, 5 red, 10 green; 9 red, 3 blue, 3 green; 6 blue, 11 red, 15 green; 7 green, 10 red, 4 blue; 2 red, 20 blue, 11 green +Game 26: 3 blue, 5 red, 10 green; 7 green, 6 red; 7 green, 1 red, 3 blue; 10 green, 4 red, 3 blue; 4 red, 7 green, 3 blue; 8 green, 4 red +Game 27: 16 green, 6 blue, 4 red; 3 red, 6 blue, 7 green; 10 green; 6 green, 1 red +Game 28: 5 green, 5 red, 2 blue; 1 blue, 9 red, 6 green; 2 blue, 3 red; 1 blue, 1 green, 5 red; 4 green, 3 red; 9 green, 1 blue, 14 red +Game 29: 1 red, 2 green, 13 blue; 1 green, 2 red, 9 blue; 12 red; 3 blue, 5 red +Game 30: 8 blue, 3 red, 9 green; 10 green, 9 blue; 9 green, 12 blue; 3 blue, 2 red, 4 green; 8 blue, 9 green; 1 red, 12 blue, 6 green +Game 31: 8 red, 16 blue; 2 red, 1 green, 1 blue; 5 red, 8 blue, 1 green +Game 32: 3 green, 5 blue, 8 red; 10 blue, 1 red, 3 green; 9 green, 3 blue, 2 red; 2 blue, 1 red, 14 green; 3 blue, 10 red, 16 green +Game 33: 1 red, 3 green, 2 blue; 15 blue, 1 green; 1 green, 1 red, 10 blue +Game 34: 4 green, 7 blue; 2 blue, 12 green; 6 red, 14 green, 7 blue +Game 35: 9 blue, 1 green; 2 green, 6 blue, 11 red; 1 green, 10 red, 1 blue +Game 36: 5 blue, 1 green, 2 red; 11 blue, 3 green, 5 red; 2 green, 14 blue, 2 red; 3 green, 5 blue, 5 red; 13 blue, 2 green, 5 red; 3 green +Game 37: 4 blue, 2 red, 8 green; 1 blue, 9 green, 4 red; 1 red, 4 green, 1 blue; 16 green, 3 blue, 4 red +Game 38: 9 blue, 9 green; 1 green, 3 blue; 8 blue, 6 red, 5 green; 1 green, 9 red, 1 blue +Game 39: 1 red, 17 green; 1 blue, 7 green, 7 red; 6 red, 4 blue +Game 40: 1 blue, 2 red; 10 blue, 4 green, 2 red; 1 green, 11 blue, 3 red; 4 blue, 2 green; 3 blue, 4 red +Game 41: 7 red, 4 blue, 4 green; 10 red, 11 blue, 1 green; 6 red, 6 blue, 4 green; 13 blue, 3 red, 7 green; 9 green, 12 blue, 14 red; 9 blue, 12 red, 10 green +Game 42: 3 blue, 1 red, 11 green; 4 blue, 9 green, 8 red; 3 red, 5 blue, 1 green +Game 43: 2 green, 17 blue, 9 red; 16 red, 12 blue, 2 green; 12 red, 12 blue, 7 green; 17 red, 16 blue, 7 green +Game 44: 2 red, 3 green, 5 blue; 5 red, 5 blue, 7 green; 2 red, 5 blue, 5 green; 6 red, 5 blue, 2 green +Game 45: 9 green, 1 blue; 1 red, 5 green, 2 blue; 2 blue, 4 green, 9 red; 13 green, 7 red, 1 blue; 3 blue, 4 green +Game 46: 5 green, 7 red; 8 green, 5 blue, 1 red; 1 blue, 7 red, 17 green +Game 47: 1 green, 17 blue; 9 blue, 1 green; 1 blue, 1 red +Game 48: 1 red, 6 green, 7 blue; 9 green, 1 red, 2 blue; 10 blue, 6 green, 1 red; 1 red, 4 green, 9 blue; 6 blue, 3 green, 1 red +Game 49: 1 red, 1 blue, 16 green; 3 red, 1 green; 16 green; 2 blue, 8 red, 19 green; 20 green, 9 red; 8 green, 6 red +Game 50: 1 green, 2 blue; 2 red, 3 blue; 4 red, 2 blue; 1 green; 3 blue; 3 blue, 2 green, 1 red +Game 51: 6 blue, 5 green; 6 red, 5 green; 6 green, 6 blue, 16 red; 10 red, 10 green, 1 blue +Game 52: 4 red, 5 green, 1 blue; 15 green, 1 blue; 8 green, 5 blue, 5 red; 4 blue, 11 green, 1 red +Game 53: 5 green, 3 blue, 5 red; 2 red, 4 blue, 1 green; 1 red, 2 green; 11 red +Game 54: 7 green, 16 blue, 5 red; 5 green; 10 blue, 6 green, 5 red; 3 green +Game 55: 3 green; 16 green, 1 blue; 13 green, 19 blue, 1 red; 13 green, 18 blue +Game 56: 9 green; 3 blue, 1 red, 10 green; 1 red, 4 blue, 9 green +Game 57: 14 blue, 2 red, 3 green; 1 red, 8 blue, 7 green; 1 green, 3 red, 15 blue; 5 green, 12 blue; 4 green, 15 blue +Game 58: 9 red, 5 green; 10 green, 11 red, 1 blue; 12 green, 17 red, 1 blue; 1 blue, 1 green, 17 red; 14 red, 1 blue, 16 green +Game 59: 2 red, 12 blue, 10 green; 6 green, 1 red, 14 blue; 14 blue, 9 green, 2 red; 12 green, 14 blue, 2 red +Game 60: 5 blue, 8 green; 1 red, 6 green, 7 blue; 1 blue +Game 61: 5 red, 2 blue, 5 green; 2 blue, 11 green; 1 blue, 2 red, 14 green; 3 green; 4 red, 13 green; 2 blue, 6 green, 1 red +Game 62: 1 red, 1 blue, 2 green; 3 red, 1 blue, 2 green; 1 blue, 10 red; 6 red, 1 blue +Game 63: 7 red, 6 blue, 4 green; 2 blue, 5 green, 8 red; 5 blue, 4 green, 10 red; 4 blue, 7 red, 10 green; 5 blue, 10 green, 8 red; 4 blue, 10 green, 3 red +Game 64: 6 red, 7 green, 15 blue; 8 blue, 16 green, 3 red; 11 green, 12 blue; 4 red, 17 blue, 8 green +Game 65: 2 blue, 7 green; 2 red, 8 blue; 2 green, 1 red, 5 blue; 1 green, 2 blue; 19 green, 7 blue; 2 red, 3 blue, 14 green +Game 66: 15 green, 7 blue; 9 blue, 3 green, 16 red; 1 red, 1 blue, 16 green; 18 red, 8 blue, 11 green +Game 67: 1 blue, 1 green, 2 red; 5 green, 8 red, 2 blue; 7 red, 1 blue +Game 68: 3 blue, 10 red; 13 red, 1 green; 5 blue, 5 red; 2 blue, 1 green, 16 red; 16 red, 3 blue +Game 69: 7 red, 1 blue, 3 green; 14 green, 2 blue; 3 green, 2 blue; 4 red, 1 green, 1 blue; 10 red, 14 green, 2 blue +Game 70: 10 green, 12 red; 5 red, 7 green; 1 blue, 6 red, 11 green +Game 71: 16 green, 13 red, 10 blue; 7 red, 7 blue, 15 green; 17 green, 13 red, 1 blue; 5 blue, 8 green, 11 red; 7 red, 1 blue, 15 green; 15 green, 4 blue, 2 red +Game 72: 3 blue, 3 red; 2 blue, 3 red, 1 green; 1 red, 1 blue, 3 green; 1 green, 2 blue, 3 red; 3 blue, 1 green, 1 red; 1 blue, 4 red +Game 73: 10 blue, 11 red, 5 green; 6 green, 9 blue, 4 red; 10 red, 5 green, 9 blue +Game 74: 6 green, 17 blue; 1 red, 1 blue, 11 green; 2 blue, 1 red, 3 green +Game 75: 11 red, 11 green, 3 blue; 11 red, 1 blue, 6 green; 4 green, 3 blue, 8 red +Game 76: 3 green, 3 blue, 12 red; 3 blue, 15 green, 3 red; 4 red, 15 green, 2 blue +Game 77: 13 blue, 11 red, 1 green; 3 red, 12 green, 12 blue; 7 red, 15 green, 4 blue; 5 red, 2 green, 3 blue +Game 78: 4 red, 8 blue, 2 green; 7 blue, 3 green, 7 red; 3 green, 13 blue; 3 red, 4 green +Game 79: 7 blue, 13 red, 8 green; 7 green, 15 red, 9 blue; 2 green, 8 red, 10 blue; 13 blue, 20 red, 7 green; 11 red, 2 green, 14 blue +Game 80: 12 red; 2 blue, 15 red, 3 green; 1 blue, 1 green, 2 red; 1 green; 1 green, 3 blue, 13 red; 1 green, 2 blue, 1 red +Game 81: 11 blue; 6 blue, 8 green, 4 red; 7 blue, 1 red, 1 green +Game 82: 9 blue, 1 red; 3 blue, 1 red, 3 green; 8 blue, 8 green, 2 red; 5 blue +Game 83: 7 blue, 13 red; 4 blue, 2 green, 3 red; 15 blue, 9 red, 1 green; 14 red, 1 green, 12 blue +Game 84: 8 blue, 1 green, 20 red; 9 green, 20 red, 18 blue; 16 red, 15 blue, 5 green; 15 red, 10 green, 16 blue; 11 green, 14 red, 12 blue +Game 85: 1 red, 2 blue, 9 green; 13 green, 3 blue, 5 red; 1 green, 1 red, 3 blue; 8 green, 2 blue, 1 red +Game 86: 10 red, 6 blue, 11 green; 1 red, 11 green; 7 blue, 6 red, 11 green +Game 87: 14 red, 4 blue, 4 green; 14 red, 4 blue, 7 green; 12 red, 11 green, 5 blue; 5 blue, 12 red +Game 88: 3 green, 4 blue, 11 red; 3 green, 4 blue, 3 red; 10 red, 3 green; 3 blue, 2 red, 2 green +Game 89: 4 blue, 2 red, 3 green; 3 green, 7 red, 13 blue; 1 green, 6 blue +Game 90: 7 red; 5 blue, 11 red, 8 green; 8 red, 3 green, 2 blue +Game 91: 2 blue; 4 red; 2 blue, 4 green; 3 green, 1 blue, 1 red +Game 92: 7 blue, 10 green; 9 green, 9 blue, 7 red; 6 green; 12 red, 1 blue, 4 green; 5 red, 1 green, 13 blue +Game 93: 7 green, 6 red, 1 blue; 3 red, 6 green, 8 blue; 1 blue, 6 green; 6 red, 15 blue, 4 green; 10 blue, 2 green, 6 red; 3 green, 5 red, 6 blue +Game 94: 5 red, 1 green, 15 blue; 1 blue, 6 red; 2 red, 6 blue, 2 green +Game 95: 9 blue, 4 red, 17 green; 15 green, 9 red, 10 blue; 1 blue, 13 green, 12 red +Game 96: 1 blue, 12 green, 1 red; 3 blue, 1 green, 5 red; 2 blue, 8 red, 10 green +Game 97: 18 blue, 7 red, 11 green; 6 red, 3 blue, 14 green; 1 red, 13 blue, 4 green +Game 98: 5 blue, 2 green, 8 red; 12 red; 13 red, 4 blue, 4 green; 7 red, 11 blue; 10 blue, 2 green, 2 red; 6 red, 12 blue +Game 99: 4 green, 2 blue, 4 red; 9 blue, 11 red, 1 green; 5 green +Game 100: 2 blue, 12 green; 6 green, 1 red, 12 blue; 1 green, 5 blue, 1 red; 1 red, 12 green, 6 blue; 16 blue, 3 green \ No newline at end of file diff --git a/day2/solution.py b/day2/solution.py new file mode 100644 index 0000000..1715190 --- /dev/null +++ b/day2/solution.py @@ -0,0 +1,56 @@ +from dataclasses import dataclass + +@dataclass +class CubeSet: + red: int + green: int + blue: int + + @classmethod + def from_str(cls, s: str): + data = dict([ + (colour, int(count)) + for colour, count in (x.strip().split(" ")[::-1] for x in s.split(",")) + ]) + return cls( + red = data.get("red", 0), + green = data.get("green", 0), + blue = data.get("blue", 0) + ) + + def power(self): + return self.red * self.green * self.blue + + +@dataclass +class Game: + no: int + cube_sets: list[CubeSet] + + @classmethod + def from_str(cls, s: str): + game, cube_sets = [x.strip() for x in s.split(":")] + return cls( + no = int(game.split(" ")[1]), + cube_sets = [CubeSet.from_str(x.strip()) for x in cube_sets.split(";")] + ) + +if __name__ == "__main__": + with open("input.txt") as f: + games = [Game.from_str(s) for s in f.read().split("\n")] + print("Part 1:", sum([ + g.no + for g in games + if all([ + cs.red <= 12 and cs.green <= 13 and cs.blue <= 14 + for cs in g.cube_sets + ]) + ])) + print("Part 2:", sum([ + CubeSet( + red = max([cs.red for cs in g.cube_sets]), + green = max([cs.green for cs in g.cube_sets]), + blue = max([cs.blue for cs in g.cube_sets]), + ).power() + for g in games + ])) \ No newline at end of file