From 4ab4eb48df323f00bc6b789c4d9e3cbc89584151 Mon Sep 17 00:00:00 2001 From: Bart Riemens Date: Thu, 7 Dec 2023 21:43:37 +0100 Subject: [PATCH] 2023 - Day 1 --- 2023/01/PART1.md | 44 ++ 2023/01/PART2.md | 23 + 2023/01/input.txt | 1000 +++++++++++++++++++++++++++++++++++++++++++ 2023/01/sample.txt | 4 + 2023/01/sample2.txt | 7 + 2023/01/solution.ts | 63 +++ 6 files changed, 1141 insertions(+) create mode 100644 2023/01/PART1.md create mode 100644 2023/01/PART2.md create mode 100644 2023/01/input.txt create mode 100644 2023/01/sample.txt create mode 100644 2023/01/sample2.txt create mode 100644 2023/01/solution.ts diff --git a/2023/01/PART1.md b/2023/01/PART1.md new file mode 100644 index 0000000..5d71546 --- /dev/null +++ b/2023/01/PART1.md @@ -0,0 +1,44 @@ +--- Day 1: Trebuchet?! --- + +Something is wrong with global snow production, and you've been selected to take +a look. The Elves have even given you a map; on it, they've used stars to mark +the top fifty locations that are likely to be having problems. + +You've been doing this long enough to know that to restore snow operations, you +need to check all fifty stars by December 25th. + +Collect stars by solving puzzles. Two puzzles will be made available on each day +in the Advent calendar; the second puzzle is unlocked when you complete the +first. Each puzzle grants one star. Good luck! + +You try to ask why they can't just use a weather machine ("not powerful enough") +and where they're even sending you ("the sky") and why your map looks mostly +blank ("you sure ask a lot of questions") and hang on did you just say the sky +("of course, where do you think snow comes from") when you realize that the +Elves are already loading you into a trebuchet ("please hold still, we need to +strap you in"). + +As they're making the final adjustments, they discover that their calibration +document (your puzzle input) has been amended by a very young Elf who was +apparently just excited to show off her art skills. Consequently, the Elves are +having trouble reading the values on the document. + +The newly-improved calibration document consists of lines of text; each line +originally contained a specific calibration value that the Elves now need to +recover. On each line, the calibration value can be found by combining the first +digit and the last digit (in that order) to form a single two-digit number. + +For example: + +``` +1abc2 +pqr3stu8vwx +a1b2c3d4e5f +treb7uchet +``` + +In this example, the calibration values of these four lines are 12, 38, 15, +and 77. Adding these together produces 142. + +Consider your entire calibration document. What is the sum of all of the +calibration values? diff --git a/2023/01/PART2.md b/2023/01/PART2.md new file mode 100644 index 0000000..2ca9713 --- /dev/null +++ b/2023/01/PART2.md @@ -0,0 +1,23 @@ +--- Part Two --- + +Your calculation isn't quite right. It looks like some of the digits are +actually spelled out with letters: one, two, three, four, five, six, seven, +eight, and nine also count as valid "digits". + +Equipped with this new information, you now need to find the real first and last +digit on each line. For example: + +``` +two1nine +eightwothree +abcone2threexyz +xtwone3four +4nineeightseven2 +zoneight234 +7pqrstsixteen +``` + +In this example, the calibration values are 29, 83, 13, 24, 42, 14, and 76. +Adding these together produces 281. + +What is the sum of all of the calibration values? diff --git a/2023/01/input.txt b/2023/01/input.txt new file mode 100644 index 0000000..df09d64 --- /dev/null +++ b/2023/01/input.txt @@ -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/2023/01/sample.txt b/2023/01/sample.txt new file mode 100644 index 0000000..7bbc69a --- /dev/null +++ b/2023/01/sample.txt @@ -0,0 +1,4 @@ +1abc2 +pqr3stu8vwx +a1b2c3d4e5f +treb7uchet diff --git a/2023/01/sample2.txt b/2023/01/sample2.txt new file mode 100644 index 0000000..41aa89c --- /dev/null +++ b/2023/01/sample2.txt @@ -0,0 +1,7 @@ +two1nine +eightwothree +abcone2threexyz +xtwone3four +4nineeightseven2 +zoneight234 +7pqrstsixteen diff --git a/2023/01/solution.ts b/2023/01/solution.ts new file mode 100644 index 0000000..78a118a --- /dev/null +++ b/2023/01/solution.ts @@ -0,0 +1,63 @@ +const sample = await Deno.readTextFile("sample.txt"); +const sample2 = await Deno.readTextFile("sample2.txt"); +const input = await Deno.readTextFile("input.txt"); + +const wordsToNumbers: Record = { + one: 1, + two: 2, + three: 3, + four: 4, + five: 5, + six: 6, + seven: 7, + eight: 8, + nine: 9, +}; + +const getNumberStringsFromString = (data: string): string[] => + data.match(/(\d)/g) ?? []; + +const getNumberStringsAndNumberWordsFromString = (data: string): string[] => + Array.from( + data.matchAll( + new RegExp(`(?=(\\d|${Object.keys(wordsToNumbers).join("|")}))`, "gi"), + ), + (x) => x[1], + ); + +const replaceWordNumbersToNumbers = (data: string): string => + data.replace( + new RegExp(Object.keys(wordsToNumbers).join("|"), "gi"), + (match) => String(wordsToNumbers[match]), + ); + +const solvePart1 = (data: string): number => + data + .split("\n") + .filter(Boolean) + .map(getNumberStringsFromString) + .map((numbers) => [ + numbers[0], + numbers[numbers.length - 1], + ]) + .map(([a, b]) => parseFloat(a + b)) + .reduce((s, v) => s + v); + +console.log("Sample:", solvePart1(sample)); // 142 +console.log("Input", solvePart1(input)); // 55090 + +const solvePart2 = (data: string): number => + data + .split("\n") + .filter(Boolean) + .map(getNumberStringsAndNumberWordsFromString) + .map((numbers) => numbers.map(replaceWordNumbersToNumbers)) + .map((numbers) => [ + numbers[0], + numbers[numbers.length - 1], + ]) + .map(([a, b]) => parseFloat(a + b)) + .reduce((s, v) => s + v); + +console.log("Sample2:", solvePart2(sample2)); //281 +console.log("Input", solvePart2(input)); //54845