From e887e789d4bd71bf2d1064110f15d43ff6309f59 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Fri, 1 Dec 2023 00:35:37 -0500 Subject: [PATCH] Day 1 --- .gitignore | 1 + Cargo.lock | 54 +++ Cargo.toml | 1 + input/day1.txt | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++ src/day01.rs | 80 ++++ src/main.rs | 4 +- 6 files changed, 1139 insertions(+), 1 deletion(-) create mode 100644 Cargo.lock create mode 100644 input/day1.txt create mode 100644 src/day01.rs diff --git a/.gitignore b/.gitignore index ea8c4bf..0592392 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +.DS_Store diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..c3610b6 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,54 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] +name = "aoc23" +version = "0.1.0" +dependencies = [ + "regex", +] + +[[package]] +name = "memchr" +version = "2.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" + +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" diff --git a/Cargo.toml b/Cargo.toml index a483005..2521ec0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +regex = "1.10" diff --git a/input/day1.txt b/input/day1.txt new file mode 100644 index 0000000..7b02904 --- /dev/null +++ b/input/day1.txt @@ -0,0 +1,1000 @@ +threerznlrhtkjp23mtflmbrzq395three +9sevenvlttm +3twochzbv +mdxdlh5six5nqfld9bqzxdqxfour +422268 +vdctljvnj2jpgdfnbpfjv1 +tshl7foureightvzvzdcgt +1fourrj +6mfbqtzbprqfive +4sevens34 +fourfourpsckl47xdbncvndrthree +7ltsp1seventhreesix +8sixnmm85 +11three +fourvninelccgtkjzhhdqjmnxjbbkdsnine6two +three8seven +oneonefour7193eight +8jmqfhmzf7 +5nine8 +eight1qlfzvdtseven1threefour +5slbnsevenmz +8sixnzfctpblt +xthzlbsjvz4dlg9fiveseven7seven +fzqeightwothree1qhjtmfdsmsf +74ninesixfivermkvh +five7xshrvvxbjtwo +22threepdtqbceightninesevenvrsct +4ttbxqm76fiveqcpdptn2 +five3nrftzlzrqpkrxgtwoqplpgf +threethreeptz4 +755hhmsrseven +sevenone1 +two7bsnxknseven +threezdbbhkrnrq4seven +eighttwosix71xb +fourtwo86one4 +nxsvfqlpbtmjnjn9zkvhdn2zpn +37five4mrkcjgtpldsixtwo +cjbhbxx7v +911lvreightfour +6qptwo36onefour +fscrbckvp8threemrjmgvcfknfourseven8 +four48718hfour +kbzfourdfxdjmmn9onefourhcxbgnlthree +ktvnxthree6pltdv8hqhkcmcnfj +9qgnmdf +ninefive2 +twobrcdbnninefour85 +4qsst9pnvtxfcrpbgt4 +65cdxrjxqhbr86fourvvjvsdgl3 +mpfsmd7five +2krzxbvdgmfourthreeseven6onesevensix +eightone16 +zcslhb6hfsixnine +four44mrtqqsixtwo +two9gqfsk2six1 +1zrkpqvtfhm3five4 +375threethree +dmnjsjbqcvvqqseven3twoonesixcrdjglhdl +kpkhplpf8seven +zhk9ninesixbsfrg +34four +sevenseven8 +tlppzmxvgjnine9sixtxkpdone +drrzvjcgdxqmtmxffrftkthhfbqrpxmfiveseven32 +eight4mscvrpr7 +sixqmndjctlnxs9q1three +41mfqk81eight55 +jhmhqzcsxfsdxkx5oneseventhree2z1 +6three6k +6nine887 +hdrtcqn7zrsnrsbpxgbbsjzd +hxdvfnxd1sevensixthree1eight8six +eightn2 +sevenqlcf2fiveseven6266 +ttwone4vgtsrcds +four36 +52zlhmm22seven +lpblvxfivethreebfslbtfour6eightone4 +4cbr15two3 +4bvxjzhbdvmjgxlqhk5cxklkx5 +d392qsfpkbvhlz1jkcfkcjnsdvdknqbd +zffmdgmqzzsmzdqbhgjt8hhxzqvgflff22cfrnnq +555onebpttwothreessdtlhkzfk +7jsvkktn +pxslsbnlhj6fivesqdf3nhkmzzgdkckfsbxvgh +snjqcmpqf1threevxj +5jkcvtsgtwo49 +blbsmtgjhthree9glgchhmrlnrvcvf +jpdvqhxrrdonebmgdbpkcj8sixfourrkrllrcv +6five3smn3nine +kptrrdzxcninesevenfiveeight458 +fourfour171twobfqcvdpx6one +pqrzsmqls294 +bx7 +8eightthree71fourtksmgxcz2 +eighttwosix8mtpv +8ninedrjxsbvhrsqvdpbrl97tdkxdjmq9six +59twonine7ninenineninehsbqqzlr +five11 +6cmxnnmzmsk4lqclspone +grzqrbgtb2hztgffpzqflsqhzzdlzmktqbnjone +mrmvfive37two +three5ccvghbkp3mjrsfkbpn +three94oneonethree +mhoneightfivemdggmcjqgv7tlqkmhhxrjh +twodfbnnsfgnjc7fivetwo +sevensix8vfvkrxninedlxdjjmlvp +258 +phl9nine2fivefivenzzdckxdgpzrzqbkx +sfmfive46one +fourtwo6zjtjmtdkfzmltxdhltdzrtqp +429 +one3bzzthqjgl1skhmqvrtffpzqch +one7118 +fourninefivexzsgonefrmxpjx9svccseven +vqs3fourninenine +scchxmzbhqptt5 +seven3threetwo3 +gqdbqxbctkdbxf9zonevk6 +one5dxhfrsrsz7fivesevenseven +51m +twoninedfdshzcqrgvrkdrjmlqvqjhsmxlmfrhcdtbc713 +twofivethree9bccssbgqnthreethree +three76hpkzttdhgj +7dsseven1six9lggkdzrmjtwo +dpxg7threexfvxjsqzx +9191eightninekfcspxskthreethree +seven5five9hrvznqxn9qtqxghtgp9 +gm8threefiverpbqkf5 +8three3eightdgn +27nineeightninej +43fiveprxftkhpszrgsevenninebncn +threeone7drmqtjnine2ninerjbrhtbzfkone +zcplmpnbm3 +gllplmbp57one8fxpqbhgbln +xlxfkgjvnnpbvcclcf18oneseight6 +51pvmcdzbnxtsevenqrvmmfhchthree +nine6fdzrjone +77sixbvlsfninegjq +7hstqmscrqseven95ninerqjb +fourthree8jfnqbbztqsevennbllxgflc5 +four2threedrdqcqsbrnsix +one5onedplktrfb3mphprnfbcnineeighttlb +8five1mscqbplsltllmqjkkcfzkh9 +73nine +one98hmlkqlnbrnbzxjd +three8onesixmckhzrlbssxhoneonexftkn +6pthmtsixeightnine8one +h516nine16 +six83zsqd4lxqzqgcpd7twonehlj +threeseven4five35eightwont +sevenfour3 +275779 +pftjgl25 +eight5oneights +oneeighteight8nsnzphnmspkjxzdxhvhkgrl +9ninekzhkh2lfdseventwo +6two81fivethree +sixblhfvjfnm1mfmnpvqqnqshthreepjlzvfour9 +45spmbfdgdhljpdoneqclcqzccjndhqkthree6 +34jhrxkrtxf +83mgdntfnhdj +sixdtzllvpkppvlxhpkfive8sevenmdzpbnlcnfpcltg3 +8krd +threeqxcx8 +mtrssgmf85onesevenbtpmvptmjk5 +cgjlmfljxm98three4 +threehggmbtmzjceight11 +mxhhvvptm95two +8oneqcht3 +zjbfive6vvrr +1mbxsvmlveight7six645crtjb +6vptgkghfgzfourrsleightfive2five +onejcqbtfivesixeighttwo8 +2eight2kqmmbsbjvxtvjhponesixtwonesn +8pqeight +38mfhtq95ntvbmpthreexxg +six2zhzb4dhf7threeseven +jskqfbsct51seven8fourn +jmlgbbsqtwosklzkz6five +spngmplhchpqtfcksix1 +fiveqvsjlmlqmjzzhktkstwoeight3five +threenbf6zhtwo95nine +9ltqfqqxdlv +two6threeseven +xbgzgqfvgone4fs +fourfivedljcgdjrjzqmjbqqrctdvdnbjszszgpfour1 +82foureighteightqfmxfkvvmr +991pfoursjb +deightwo7sixbtxpv5qjfhkh3 +482nineznmhcqhmrmbxztgkdfour9five +four9threefiveeight2eightgcm +738 +6tfive9sixtwofour +two9fourone8 +5gfnine996zgsnvjn +8hpgkrndtfourtwofive +sbvxxctttjmkchhlbnine8seven +l9 +hm6xdmone5jzhppnlcs +five664 +gxthreemvrm5nine +tjknbthreegjs8ckrrqmffhfour7 +two5bbcszdzvtpprsgkmteightfive +plbtlpktcslgggpznine8sevenonejmsvg1 +87two85seven +5fxdb5sevenseven9 +zgpbndt6one +7239pztpqfkf +768threetwocfzcvc4sx +pbvc34sevenone47 +68nine +kqfxgjpnttwo84one +eighttxk2psqlfzf +sevenshrqgptpfj88fhxgmkkz +7three17one2 +pfmxggfx8lgvvln +39tsix7bkbfzqqx +gtmvx3485mjtrdmsfxl9 +7twosevenfour9seveneight65 +ninehscl531 +82rseventkhksixj +vzjtwo6ztbtjpllptmznhxcnljf +xrjnql792 +53twofourtnbfdhhr2xbsh +twogrhgmvhkgcsj2two +bxlgbpnvpkrphcp54pqjhndjfmf7 +hszmjxgjfcnine7 +sixsix2 +688qmpnj1vsfiveeightmfrd +one2sixmhmlmbghfeight3 +5two4six1twosix +58459nine3fourseven +72nineonedtz88eight +4lgjq +lvstjk3twoninefh +eight161652xczvqcjhtvxgc +1seven5zrkchldlfxvzrqjgzg8bl +ngfkczcrbrfvnsevenf4 +six9fiveseven21fourfour +onecsix1 +8fiverpnktj +5eightfourmjkhskllbrb83eightkrtn +hqrkbrcccd5 +sixjlcncnfivexqhqdbkqfour8 +72two +one8sevenfivefour +drgznqtjdfive3 +2vgpfdhseveneight43thtnthree +2kfgbh17seven5 +bclqfgsdvfour9five +seven48oneeightwon +sixthhzzffourfivervssxzncxcthree9 +ninefive8 +49sixnine73cvzgvnvvjqzmht +sttbtlxgxfd69threeoneqbsmdsbpbfzpfpmf8 +zmxffive57 +dncfqshnpgmfmnpqfiveone4br2threeeight +8fivetworps +two2twoeightnine6 +kttfsevenfrspkpsn8cscqgvthreetwo +sphvhseven1mcone8 +qmtlxml2onetxsjdnprxlcd7jfncngfsv +onetxjrzhnb1fxnlncstxthreelsixjlqhrnjhgt +tdftgntv83433 +sfq4dvgbmrseven6nsmxfgzfh +fourmvsgfvnrpp7one36hkfcmd +528dfbr4six9 +threesevenfiveddpmf9five1four +76ninehfivejseventhree +7ninelkkdgqzgksixlhdsmvvhvseven5 +hrjgpzlggnine4two7 +2sixsixjnsfztffone7tb1 +6pjxcpkpdh +84jsnmmllbzsseven +2three572ninekn1rjqg +sseightwofivenineonesixsix3gqxcnztsveight +nm18sxsrgmkqsfrrcqs +xsvgrddftfmt1nnmzndpc +lx5jlnbzmfeighteight +fdfjhnrhdbpskcpgqjhbfjxsx7 +twokxnskxseventwo2xlmrtphhkvhznp +two3mbfczdreightmxfr85 +rqtmx2qrhhqfmvonefour +59fourjsblcnbrzmbcgdzpnrqcptn +4ninexpjzqsjsznqtbclcplftnfour13six +onekmj58kzvs8v +five2nineseven +1two6jhdzt +2n +tlsbhsr1lhnjhbthz3hkgrlglzsix8l +sevensevenngkc7 +4rxnlbqs +jlsg8ftfpmmlthk3fourzqmrcrx +twosixtwo94 +825tpltn1ssszdsdklbrjn9qtz +seven96seventllvlfxddqjvtft58six +seven9ndsdnone +rrdmxl1 +fjhlhhmmsklmfhrrjhvgblgqqhtvhfpzlgshcgvh445 +6threetrsp75twoddj5 +gslbmxjn9twofivefourkbvdcpxrz4fivejbzhxjk +hp6vplls1pvhscqflc +one91oneeight9ninesixtwo +vxntwofour1 +fivexbslqmnsixq8 +8eight8two2 +524 +8five8rlkbjdsixfbqznnfive +threeseven2fourkkmhgmt +sbsr2nine52seven6 +hxqqhcxzfour2tpbkkzpndpkthreefourfour +eightnbtthbztdtdv87oneonetwo +eightninesevennqdx5 +ptmpmmh6 +5svmgf1 +2mhlmtbfive +sixfour883 +x4eight239fivesl +kqjzgkfs4txmfmn +twonine6hjfzkdk +cntncrvfour4mnd +fourhnnsksgkskq11two4 +eightdhnine25 +two7lhbqh +jbjgqt5threefour44threegcn +37eightpkhjshdg +1seven9pqmnsix +361rqvcqhv5zqzshvrffjqp4 +lbptzzf2ninezninesix7 +xvqgxhhn4694vjfdmnnine +rhqjjxbn68 +zdoneightone3tldkfzzpbqblm12three +sixnine7vss8fflxfxvvj +kmpsffxpsxjbdkphpfour8cseven +5hhdbthreefivepfmonesix +7six13gmqvfcxrbsix +twoxtqbsbsxtdjcdzqfourrrtgs86 +52zdbph3kdtmpl +959threethree +bckxnxxvmhbz923fourthree +seven2lsjr +xvspjhcvpnine8sevenqjvzmjbzseven1zone +twogxgz2onefive +9qmstrkqpgqzkxbbprbsixjk3sixsevenone +4vzrjdvbkmlhtwo6mdkhsixfour +oneone2eight9zszpvnfgn3one +httbg6nztnlpgdgf +qlxrnfclphthree5zbzsrszbc6 +ctcvnkckxtgsg1ninefivecrpnqmngqvnhmqcvn +9sevenfivefour +6pkvvone3 +6nine2sixeightthree4 +9qfivedrpfmxfbskhfstwofivergqcg +955mztjrdmlstwo5onedcrzz +sevenrxbnlfpm6twozg7 +four1oneseven34three3 +ninerhc5qninefivebndtqdjrd25 +lsbx5bhlrjfdrmblnkl41576 +dvzbqqbd4615fourbjsmpvhllhjpzc +657 +4ldkzjvdjfone +nine49seven +4kx2rnmpjnheighthjkxpdstb557 +threeeight34three59 +twofourrv48fivetwosevenddcdm +gkpzqjk89 +341 +two5pnbbmp +nine3btkkdn6 +339 +5gxcktphmzxjdtsb8 +8dhfzjf832 +bqlv7klbrbsfcbdhpcb1eightone +fourcpl5mnbtzmrgdjhfl +22hfmg1 +fiveqxtkfivethreesix5mzhj +qfmfvbks1three3foureight1 +twoseven8ntkbkjmtxrb33 +5ninensvcbfb +nine2839kffmnbgvpzflmbvfpg +34six2fivebdvzlbdqkl +7three8five +ndfrcqjrn3foureightfour +one8pfpnpqxt49fourcspbbhlpszkxd +qrmxsvjsnv2szlxhfour +mpjninesixsixmngjcrphthreeseven6two +vmponeightfour5 +776 +22twov7354one +ninexffxsqrfourcsvhgj8eightthree +nghjjvxldbznlqdeight96vhhgslrddvfmc6 +3sixbjfvtgqp4 +rrqlrfksk9zpvmfqqsgdonesixseven +six1fourqhvggsfdzfckntmfbrhthree +one47onesmdhrtjhjk +seventwoptwo7gtfzvgknbone8 +foureighttwo2nnnxljzt2seven +nine66threemshnrl +9tbtkz98lhlprtwonevn +two6two9867 +8foureightvflcsxxblgzcjmdkllblvt1 +fourzlcneight5 +tltmpnhmrbhnntmjpfkfourtnxtmtqnhrsone9 +838lqcmbqqrdgsix +sixthreeeight9grr5nine8 +oneeight4six68 +rppnht6gdrztq14five +4xvgv72threev +fournine2onenine2two +9dhksjxmct23ninempcqhroneeight3 +eightvhgtlfft4threethreecgnpzjf +sfslpsixthreeeightcqnlpsplvtseven7nine2 +drr2 +twossevenhtffztninehkgzvnmgrn7one +three4fourthree6eightthree +eightpkgknqhfour6 +28onethree25 +1sevennine6vkrqnxct +786ptjbkbf1 +ninetjvnxqkphrltpeightthree514four +376mgfkztqseven +3threeqqvqxtvsnjvdkvpnvhk +8rqxcrxmkxczzfkqkffvzcstwosrtmfnzmbf5eighttwo +two93 +854 +29fourhnmjvlseightnvkfbn61 +6zslckzztm3eight +sixfive1 +xzmlzvhcfk6seven8fiveeightpxbgkcl +seven33bdrzdtwotvseven +seven7oneeightthree +j6sevenzjbf5eighttwo +onegjeighteightttmknmgrmx1oneqxxfgone +fljrjlk4sixone7five +sevenbvqxrx27five9eight +bhdfblngngtkq4 +3sevenfivekpgnine9 +nineonelqppbgtgsnine6five +fdmqs1two3twothree7qdhbmkqxf +176pfmhfrgvsseveneight +one974fourdhvbbvfive8 +crlfbone3sevencjcsix +rdgone8lrkhggmkttlmhvvxhvxpgkkjfllq1 +7xtlstglgnqoneeightfive +onerjcplltnd1seven +gsqtjxhd8nndrkjxgmhzdmflslthreetwotwo +jrspjndsvk1seven4hx +5lks +one935onecmfrqxjxqq +9npxbtsfives2 +9one7bghdxtv1 +1khgbtlhxnsevensznknbbdrvgfgpfour +2sixrzlcqcrmgsxsxv +sixthreezqbrlnngnpbbzp6 +eighteightrkjphnngh4lhrrdfhbx +cqbsglsixfiveonetwonvzclvsdgnmmkmchrml9 +7gsqfourpht3two +sixsevenfoursixnine2ninemrgnlmqd9 +9eight2eightsixfkzlmrzqgt +onethreeseven4 +6seveneight +7rq +jmlbxtsxj265qssfhtlgx9 +three22fiveeightfdpfthree +fiveninerflxggpvflnine5dvgcl +2q2twolxksmntbxrbt6 +c6mvlmhgbztpjhlsm2bhgnxtb65 +4six3six4twoonecchglvpf +1eightvvhtdtwofltvfx +bfnfhrlznxzszzdfoursljone922five +g9 +hczxfzlhjntwo7ninesix35 +8ddh3 +3pjxlfour3 +84tcc2oneightdz +two96 +8mrxsdltwo41onesix6 +four1cjqeightvpghbd9qtdkjfzmmjcslv +oneeight3svkfzqh38threetqsxqz +four1dfhhhnhjcsdzhqdrthreethreeqxmjsdnv +99eightsixone3three +995432 +onez6five +6sixtwo +xhsmjfkgpninesevenfive2onepnfivefive +3xvfdxnfzkvmnfvvrqjqzkkq6vrxdeight +fourfiveseven386 +272pcvttjzdzzonegtsxqntflkppfive +tone4mlskzchk9xgcht +xqrkhzhghptwo18 +two25 +seveneight9 +86three6bfmdkslfmxnbqrzjltwo7 +6vclgmphzt7twovmvvshtslgkng6 +twofourfive2nine34rmljd +two2cjjhrtxtvxntdzxstmcsixrfnzfsdmsninejkl +5ninenine9two6 +threegsmgz4three86seven +five8tkdqvkmjqhdrnv9 +gsjhgthfqpcglnbpgfk83three2vnnhlr +1three8lxqzdcjsix46oneightjhb +rhlbq9txlkxvninesl +six4zldvvgjhzhszrqcdhrm9 +hlsqmddjmeightlfcrqkkbnssnxthree6four5 +gps5eighttwo93 +6four3eighthvhlknbxdpseven4 +threespxdrjqsevenseven75pxxmphbqfhvvdtp +four8nhlsqdlgnone2seven +vjcxsixthree2hspmmpqnhrddseven +1tmrz8xfgtvtqmcrninedbpt739 +knjtcfive1eightknnbxgmsix +qbj9 +fivefsrtdfcddfourtwojxdlmxczkljltbrct8 +jnggmc4fourbtblkhzfnnplggfive +96seven641 +pvvqsmtqf3fourdgqrxrtxlslsone59five +five567 +two6nmhbffour38 +rhppzxndqrhmrxlvhn58fnseven +ctgjbnine9ninebkbone4nine +threeone2sixpldcvhfpfourz3 +jxxgfvzglzrzpfk7stplphbdone8eight1 +3zvpstzgnz4gnfzdhnvvl +eightthree88sixtwosixbrr +seveneightqjncs4vdqllkvmfr +1five653sixonethree +ninehkdxcqrhszdxbgvjjkcvfmzzbq5seventhree +bttqsrsz6four5tdjkmrkcqb +23one35three +nine4five +8jhvnq1foureightsixctfxnine +mscdbpkzfptqvpxd7 +7bmfvmtmjm +five66btxzbjmxhqljqclkponeqxcq +5jpsnjbz +sptwone4ffcqgfvzmsevensix +27sevenqxccm +bpttwonine1vrkhxkxlvd +six6rpqxbhdlgm4 +3threeppmfsix1one +dnhbjkmhbcbzkcncmjcrmkrhmhtwo2qxblfsgtwo +mpztn5 +8hkdnzqqs52 +szfsgbgxmlthreefourtwo43six1 +two5lb +mv1three3d +gfqn45 +87brnjzx +zzfszvk6five +3shknsmbksrxtkqdls6fivegfive +5xtgdxhflbnrq +onelbrxfour6 +one3six +95vqkfive +lnsl6sevengxlbqqrlpdxmhjbnc +vkglhnqxbffll6pseveneightninelgkqv +sevendsix3ghjrlkhlkqztkksvvsrqvhfthree +ssfive8vmfdbfivend1xjpnjfbxxtwo +8eighttwodxpjeightvzqzpltldclmbkj +817rmdzceight3seven +49ftonethree9 +eighttwo5 +9pdzqxgpone11ggnksvvcgg9seven +jjljrfmdxg1fivetwo2kglgxjbjvznrb7rklzlhnpbn +srkrbfseighttwo8 +dsjxggrzsnnine1one1 +798xgsix9two +956six +5pnprseventhree +46cpjgjxs +7kpxxmmbrvm8ptwoneqht +3lfghbcksg +72cdcznmtsg2fiveone +sevendvkzjsmsb8vmcdrxgvjv8fivenineeight +3xvdjgnz17 +zkss7nztwo97oneightnj +ctgseven5nineccmbmdkgxmeight6four +five3mfkrhbzvf +5one55vjsgpszbz +zjbzghrbjh8fourrlpcfrxc +sevengndftmqsxfjdzkjzvtwohzx83 +7xpqmfninesevenfdeight6fivexqfj +hfpbkh325xg +ninefivekcsxrvjvvc7twogqxhddnine +ssvfgvmmv8seven799bnmn +fournhvbhhx9 +sixfour8hbzdbkmzqj6three1 +fivemxhmgvxfpsxm4 +sevenseven1srh7 +eight4pnsnh +4gbskpjhlptkflkjgzxlxrfskxxlrxvf +xmj7cngxjrnzcstrbrjsixfmqxnqnljqthreexsnfptpvd +qceightcplznbthree6 +ninebmqthreesixxfl3one4 +fivelb8four2one +9one5jpfourfour37 +sevenfourtwo6zknqzv +twovbcltvfcv1ninechcjrc +seventwo1five8mdxhv3three +rqtgxztqntznineghqqkhfzvhmf1 +rloneightseven88 +7five81one7 +ninepgnzpfktsslpmbonej6d +ktwoseven78jhsdkkbptptwop +six7nineoneninenine +jtcqdt1 +8fivetcqdglbnbxone +92sdvljhqdt6zgmgsznfchjnpn1 +threefour73threefive1 +jbhqh8phjqmm +4jlpncphmjjtthreethreesixpmpttpd +tzxpfds4two4one7sevenjbblnlsl +fxthhmseven4eighttwo +2csbxskpqzqkktsv2 +xjfjmvtkjfoursevenone9xbrl7 +3ninekgg +8fkmzjqdntzone43fivethree2 +4nine2blkhpjgpnone +3six66foursix +9one1 +4mz +2fourfourone +33six2fourfoursix +8j +59trgvlblqbk35gjeightnine +fdtvfddzfourfivepnrvpr2two3 +ctninetdv26seven +crjtlxgcbgfr8sevensix +fourfourhckrdsqkq8eight +two24kdqkzgffpxkjngj8657 +foursdss33seven9zcl +bhl2clcfsqnhpsixjxonefour5 +545vksixeight +three35five7two +sevenmkddhdvqmsthree2five +7zmxsix2ckskqcglhtgthree59 +xvsthree9 +22q +ninetwo3threenineeight8dzfrf4 +cqnbzgtjthreed2 +76jkpnonepbvhcdpfd8 +sevensevenmjrzvbkkknkfbq2seven5vms5 +threedeight8znlvhlzpbzvhvxxmgdt +cndxthxtvztwonlcqcshvnclzvxmsdrtn1 +hcz8vnkrrkmgpbxk2nine +5h5oneeight3 +5m1five99six62 +l1eighttwofour +2ccxhrlhjbr +tfpzvqj4gs9 +6twosixfivenine1 +8zjsixqnrzlfxdhm8fvpfnnjxhhpggjtjnsix +jzmgdcptone3hqbhthree +jvqmsixone2hlqseven7 +f9eightqkdpqlctcmmzx +98fivethreexgl9 +4bvztrtwo +fivetnrqt8twokfxrsftsnfour +onetwo33threenvng +sixvznvnt3scseveneight81qjdbj +threenine1 +47rjklmqqpnthreeninehcslqslrbjtwoeight +8one1twotlsgf +qpzvxrb242sevenrlssthreethreem +eightthreethreeeightxxrz3gjmccv +862seventhree5one +hjjx3threegsmggrfb +twonc4eightfour43r +7cblplgthnineone1 +fxzjsnfn2xrzfhrsq +one4xbvtvtxvqqmgnm9jdjxbmdjlldrqtzhrsxqseven +lmgtwogqghh9five3seventwott +oneeight2b +4five2525fivembnftdmkxzmq +3m4ninefoureight6ttxrcdgnine +threeeighthcnxpqfgsvv12rkd +gntcxfth588 +sclktwofivesnxkfq7twoxdvlxgvtzjtlgfspzk +rg7 +3vbrgrsevenzgncpj55nine6 +seventhreefiveshlrnfnqjvd21tldlrkjmtwo +8scjnkfpklljchzszvvfourjpvmvmgr6 +8fivepdlqzrsllkqkqnine9four1lqgjz +qmtwone7six2one5 +xrvhsvkvjb2nineleightwob +ninefourhkdzxrgxxhfmsninedlddz5nine +1sevenhslkkjfxz +seven5six94ninemjvv +nine4three +onesktp3szmp +cqconetwoninek4sevensix +nine892fouronegxhscsn +4mvzntcldzjxbmrrtzsheighteightbhtknp9 +4nineoneightfl +17kdhhcnvnnq +ckmqgt16gs +threefivefour9 +3twofoursbzpbdqlj5 +qdxzfxdfnsgj3twofour8fivefour +4xninesixzxkbqsgvpf +fourqthree1nine +one6fivenine2txbfgfkxzfmshmzhv4eight +9lhdxrmvfive +xktdxtwo71 +225two +two3csjhrszsfdkqmxcc3ctlhlbk4nine +bfspnrjxsgoneftk1665 +4fivefivecsbqnljgrk +8xmkhgonefivethreethreenine4zbh +nineone3twofour +pflpcxx7two1jkzqmthreefive +ksnjdtfhrnvcp2six +sixrfsrqfbdvn1c +sixlfmqfsnnnzhmqbngct2 +x9x7sevenqjn +eightninethreeqttkfm1seven +59zx923six +5rnrdbmpddjldqjnrxsdsrgpfive8 +one38432spgsfkjzeightxxk +95csptxbnmdfourmzqccclqjzntftgmskvf9 +tlbbjckfnine6mssscphp4rzndb5three +4sixnineeightztjdssbflnine +dzdftgcnvvrx669 +6six7threeh +eight7onelsrkgtkgdkgsntwosixonedn +4fourfourninenine1 +rtwonegfzmbhjbmbsvf3seven1 +3czkzzzvqbt5rmdskr +9bmponetwo +ltvcjgvkqqmfivethreeeight1jls8 +14oneeight3qtkgbpsnseveneight2 +dmrgm4 +twodlxpltlcxxks5 +tdxfeight3pqdsz35 +6hvfbrqccktfqhnnineone7btwovmgssfts +66threedrsbtwo +prbsfivetwo21ccqb5qhxz +nineninebkzq829fzkd5 +pddtlrsj7twonine5two61seven +threeeightctnkhjnqm5sevenvdjqsjpknmmslmdb +76nqxdvzrninefszr31 +3gvgclgxbvs5eight68sixnmppfhcqhbmzq +1eightrkninefive9four +3hfour375three +eightthree54sixninenggbmckqk +zbtqlmfqmbdxllqpffeight9 +1threehxmlj1czzlphp +4four7stfrr7 +four6htkfsfx3qlk41seven +qsixndconehconenine12 +sqvvptnzbqdmgjlmctqzhlldmzthreefour8 +f6ssgkone +twofive8kqs +foursevenxj6two +rqlqljzzdrzq4 +one3ninefiveonesixpgjsnrvnine +jktfqdxpfive3bhhczvnfive +fivedtcgstrzg7five7seveneight48 +7sevendnqnine54fivecvhzf1 +9fivebseven +nine9mjbjmmfkpxdjhch87hpzx +fivejdqrrx71sixbone6v +2qkkng5 +fiveksvzs3threenine +prtllbkjhxjhg4 +fctmfcrmqgq78rckrfq99d +9seventnsrsbxftwothreefgpzznbjcxh +three34two +ggvr32sbmseven4gjfhqstzq +threefour4three +two6sevenpzdvjdlninesevenfour +pgneight692vqlnhmndjvlj +six8sixqclbkscndtsfczqxhzt9bsf +fivefourdlrjnbvbnine3six72five +4fivefiveglchzczdstone +six4two +7threefoureighteight +ngjpztzcshbksbzlbdnqnine4gbdsbthreetwo2 +39sevenseven +sxcxnqrskgzkzmrkkdbxjthone3 +1lf9onebg +9lgfxnfffh9qbdxdl65fqlsjgdljrcn +37three1twofourfive +92onegdcczrfrkztxttftv +fxzkfnrmh7fiveggfour +14fivetwoflrr59 +7sixtzfpxrfrtnqxvkcgtc +drmjeight1sixthreeeightrxqjknmql6vzz +bsmbtp2 +ninetworfour7vgtvfvbv +ninethreesccxmtmbnnine2eight1five +47twothreethreeonethree7 +ftqjtwo7dbcnfdprnn335 +d5three5b +5eightfivevnf4one +1dgtwojfxnqpc +sixsixone7cpxpnzgeightbvx +33 +7sixtwo4zjb +pzfxv57one9fourfour +9two8 +5nineone1 +one6five9twotwo2vtnqjtpxxr +6threehhrmtfsgld +lbdjsslmqpspxrxqtp186rzjfour +six4qd32dczd3 +six5sevensix6dhlgzlfvgkthree4 +rmgdbsvqqnt7five +8slpfjnhtggzpqr7q8three3 +fivecmsjjhxhh6rmvsnlfive +2onejrnnkpkf7sixsixthreetqkfbk +ltwonejvqkzsltnine5fivemftvx +fourtwolkxrtzdsninenine5pznzrqbcmnph +3rzkfvqfnine +6xbninefourszjltwo6 +59qkf96twofour +fivecp37 +bcpmljn5 +7stthfdseven2threefourcrbxjjfnzbfqsfmqjlts1 +cpvsczrlrgnfpqbfbgh415five +seventhree6 +tworqbfj7114clslxks9 +six5eightjtnq +7six9llnsseventfmflxsjkdgq +six8tznfvz3 +fourpnmbqdbj23 +2ninexltrcbkjlb +665fourptmcdj +seven4mkvn1tkthree8s +eight84one +rhskrpddrmbgg7eight +qgbtqls7fd63xngfvcgdp8kkffgxdcs +9seventhree +lslprchqthree13fourkdfsrtfrthree2 +246eight +5ldnrqhhqmvtwojhtjhflzczsb9kklbkldvc +36fivebgn3vzgvjffckfour +vbxqnvhvmsix9lthree6zvmr8 +eighttwo23 +flqbvc23 +loneightsix9two +xkzvpttgfourfive6rnngs +threeseven6one5 +sixthree5rgklgfxllqzk4onetwo +one15dhhtcsx +zdmhgtnsjs22fjfourqzdsvcbgq +4four5 +hfjrsqjvtjkseven4kqcqbmbseven +241lgrtbsh +fiveptwo9sevenfpxpbfdoneightzj +9eight923xnxgndjfg +two8fivenine9cqcqqssbfc +fivetwosevenlgrvqvtsv5tcmsvbmggvfqqg7 +5mgkmn6ninetwo +mzsncqkbtq45r +fivefivegxzjvnxcbq8ptrzpjm5three +8ngzppeight646seven3oneightf +sevenvcsix8 +vxkmqgpsixgs2 +9jv9 +17jzmvgzc +6dz9 +sevenzzvone86twothreeonesktlhbks +three57vmlrfhcqkvlttzhcbtgqxgtbxb +fiveeighteighttwotwotdtfncfjn8pkxdvkfgr +8k5dsrxlvtmvdsixtwo +nine2fivernnckm +fpngdckp48onepbslnjdm2zbthxqp +nhrl8two +eightczdrdrxninesdqlqhhvq7twoz +sevenssmdflds6 +8sglqfive7p6threeqrdkmg +4brkbn +t4onepvf9three +mdfnjqjdl2lsb2btsj +tthreeljckhjqxbcjvmvx27jrffive +fiveqldglnp2six9vqvdcqxbdznghqcrnbxm99 +9pmkfmr6sevenlfjbvxqdbstwonine +threeninezmhc8three +one4nine4vc +8nqtgvnvcttpsrpsfive +pjjkmpfjpjzsbhzrgrkk96snqbtkkkd +6four58fourtworg +4fivekrjgx4 +mqrzmhhvlvknzdknine9 +one8seven2qd5 +pjhkthxm4 +sixjmbljdchjsrs3bvvnzqcqmjcm3eightwoc +8ninekrb5vxhbhdtdfd7 +7eightvlrsklsbpc3 +2onethree1 +4nine6qvfive2dlhvfour1 +threedkvnvvsmlthree149 +szseight88fourlfcvbzmone1dnzbnkq +onekxnsfour7 +onefivefivefive6rmpjhdvk2 +two75 +xrxzfmnqrvrtflqscnhlbh14vf +hsplmrdxtknine7tqtlk +sncgfpvz43lvjmvrpv +rdhoneightdxrvxhnthsevenfour72dxcdbmpbfd +six2oneonethree1xdszcmstmq +seven1one +12fourbtnxmsrvbnn6 +qfive7twomcmcsgsseven9 +five1nine7 +qcntzlp8one +qgpeightwosix8lbclbpknfive4ksqvptntmonevlrtrcs +nxmff91hzscmcthreesh +6three16 +hrlgqhzhqone14fivenine +fournrvxrxsmvsskdnbzs5zgmfh1m +four67one8drnprkbgt +81brchsdqdlk5fourseven2three +ninefoureightfjtmvsnine9onefive +two7rnl6three9 +eightseven2threethreenineqtwonezkq +eightcfkglfmzqjgrns99seven +dbzvbkslvthreefiveeight141gcklzxrzms9 +4frfvf6fourgnsm +7hcgjbbpbl9qbzzhfq +mnfllkcqgkninefive9 +4qdld5hqgrthreeeight2 +xlnnine6lksthree +lkvcnntznk33three4nine +8five2twonem +695mzfnhtlbhpvn1dfour4 +47seven811tzhqrrshdm +vgoneightnsr3fivethreetwornvbz +gc2 +3sevenxvmzbpknnqninetwofourtwosbpmqk +4seven8 +2fivegk47gsqtvdms +1jqgxbmgs4zxkrtvvtsjf1nfsdgtqrmthreeeight +vbvjdlnfiveninefive162nine +jqqsfqbfq2clfmfxz +2hmn1v2twofour16 +phchfbxz3one +zdcqgg34vqkhlbkc96six7 +5eightbghcktjjninermkpmbpk +4zctvpqqfxqdpf +six5onebljkhvlzfour3vf7 +three7sevenspczxeight3 +eightsjxdbgcjllvpxn5ninehrhlp +r4 +vtkqxmmdfkmbxbvgr633 +nrtfbqdthb1974jsdfive7jc +twothreenineeight3 +seven9c9 +l4rmngrjjl8phsftfrtwoninethree +8hptpqbfltv6twovcz5twothreethree +hncsxnxrbx174dbsddg9n +7fpvztb +eightnineq5kkd1seven +gbj8rvvqjkbp +sevenninecjrxhfsevenfivembxm1nkjrdtrllqrglrrxxj +21eightfive84mkdnzone +3rqjlbfzjninesncjnxxqnine9 +cvtwone2k1zmp65 +1v +one7eighteightsixqkfsm +44jkrsmcthreekktxlnnzjdslhfsmzl +dmhxlbsixh35 +four8ninetwofour864 +5threezmcq +6ninefive7 +4nine9twooneeightwoz +5klvpcfxpkhdhx717 +6stgznine4vhnsnhts9 +9threeone98seven1vnnvgxslf +sixeighteightztpdhvt2zqjstmzmtzgsfthreezzhhdr +twodtbkqsjgtwohfnsqcrmpjfourhkpnsfdkfive6four +ggrxkrdzmthree3 +sixlflcmmjrs5fivenine488 +four94hmhvlczssonedvgchseven6 +ssoneightfbfctjqv43psixsevenslqsfpkb1 +bdpnkb9eightnvtwojxbztssqfmninethree +cpcnkvdbrqrxtfnmzbqgffivesix91fivehgrv +five5495eight2 +7foursix93seventwonbhtmfrbqgq +tpqhxqqxpcnmlhqhkz123ninefive +knqxmrrmninegr4 +14qhlbkthreellvnqpfpbb +7eightcrlb6eightthree7 +twom3 +gtzdljfdzpdg4zbnzbnxmpcpfsevennine3 +svfjvnninefourpqsdmjcfhvccnjkpf8 +dzmoneighttwovk5tvpnmxfive +88msthvt4vbmnbrzjone +nbgcs8nine +4three53pczsx1sevenmzmtrzz +four24qphdrxfsf +gdgj3f +hthphptmmtwo7sixsevenoneightls +qxbhjmmqsixfkfn36three6 +eightmkmdtvkctkvptsbckzpnkhpskdmp3 +six2twobgzsfsptlqnine42xtmdprjqc +pxreightwo7 diff --git a/src/day01.rs b/src/day01.rs new file mode 100644 index 0000000..31f50cd --- /dev/null +++ b/src/day01.rs @@ -0,0 +1,80 @@ +use regex::Regex; + +pub fn run() { + let input = include_str!("../input/day1.txt"); + // let input = r#"1abc2 + // pqr3stu8vwx + // a1b2c3d4e5f + // treb7uchet"#; + // let input = r#"two1nine + // eightwothree + // abcone2threexyz + // xtwone3four + // 4nineeightseven2 + // zoneight234 + // 7pqrstsixteen"#; + + // let sum: u32 = input + // .lines() + // .filter(|s| !s.is_empty()) + // .map(|s| find_digits(s)) + // .sum(); + // dbg!(sum); + + dbg!(find_digits_part2("gdgj3f")); + + let sum2 = input + .lines() + .filter(|s| !s.is_empty()) + .map(|s| find_digits_part2(s)) + .sum::(); + dbg!(sum2); +} + +fn find_digits(s: &str) -> u32 { + let first = s + .chars() + .nth(s.find(|c: char| c.is_ascii_digit()).unwrap()) + .unwrap() + .to_digit(10) + .unwrap(); + let last = s + .chars() + .nth(s.rfind(|c: char| c.is_ascii_digit()).unwrap()) + .unwrap() + .to_digit(10) + .unwrap(); + first * 10 + last +} + +fn find_digits_part2(s: &str) -> u32 { + let re = Regex::new("^([1-9]|one|two|three|four|five|six|seven|eight|nine)").unwrap(); + let mut s = s.to_owned(); + let mut first: Option = None; + let mut last: Option = None; + while !s.is_empty() { + if let Some(m) = re.find(&s) { + last = Some(parse_digit(m.as_str())); + if first == None { + first = last; + } + } + s.remove(0); + } + return first.unwrap() * 10 + last.unwrap(); +} + +fn parse_digit(s: &str) -> u32 { + match s { + "one" => 1, + "two" => 2, + "three" => 3, + "four" => 4, + "five" => 5, + "six" => 6, + "seven" => 7, + "eight" => 8, + "nine" => 9, + _ => s.parse().unwrap(), + } +} diff --git a/src/main.rs b/src/main.rs index e7a11a9..5311c30 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +mod day01; + fn main() { - println!("Hello, world!"); + day01::run(); }