commit 5edbcae3fb82f5d91270e8c98aaa271592af216e Author: Baipyrus Date: Fri Dec 8 09:08:25 2023 +0100 initial commit (previous days; code already done) diff --git a/Day1/Part1.js b/Day1/Part1.js new file mode 100644 index 0000000..fe4d2c6 --- /dev/null +++ b/Day1/Part1.js @@ -0,0 +1,20 @@ +import { readFileSync } from "fs"; +const t0 = performance.now(); + +const lines = readFileSync("input.txt") + .toString() + .split("\n") + .filter((e) => e.length > 0); +const numbers = lines.map((a) => + a + .split("") + .filter((b) => parseInt(b)) + .join("") +); +const combinations = numbers.map((e) => parseInt(e[0] + e[e.length - 1])); +const sum = combinations.reduce((a, i) => a + i); +console.log(combinations); +console.log(sum); + +const t1 = performance.now(); +console.log(`Runtime: ${t1 - t0}ms`); diff --git a/Day1/Part2.js b/Day1/Part2.js new file mode 100644 index 0000000..59f0d66 --- /dev/null +++ b/Day1/Part2.js @@ -0,0 +1,48 @@ +import { readFileSync } from "fs"; +const t0 = performance.now(); + +const names = { + zero: "0", + one: "1", + two: "2", + three: "3", + four: "4", + five: "5", + six: "6", + seven: "7", + eight: "8", + nine: "9", +}; +const lines = readFileSync("input.txt") + .toString() + .split("\n") + .filter((e) => e.length > 0); +const numbers = lines.map((a) => { + const f1 = Object.keys(names) + .map((e) => [names[e], a.indexOf(e)]) + .filter((e) => e[1] >= 0) + .sort((c, b) => c[1] - b[1])[0]; + const l1 = Object.keys(names) + .map((e) => [names[e], a.lastIndexOf(e)]) + .filter((e) => e[1] >= 0) + .sort((c, b) => b[1] - c[1])[0]; + + const numbers = a + .split("") + .map((c, i) => [c, i]) + .filter((b) => parseInt(b)); + const f2 = numbers.sort((c, b) => c[1] - b[1])[0]; + const l2 = numbers.sort((c, b) => b[1] - c[1])[0]; + + const before = [f1, f2, l1, l2]; + const after = before.sort((c, b) => c[1] - b[1]).filter((e) => e); + const i = after.length - 1; + if (!after[0] || !after[i]) debugger; + return parseInt(after[0][0] + after[i][0]); +}); +const sum = numbers.reduce((a, i) => a + i); +console.log(JSON.stringify(numbers)); +console.log(sum); + +const t1 = performance.now(); +console.log(`Runtime: ${t1 - t0}ms`); diff --git a/Day1/input.txt b/Day1/input.txt new file mode 100644 index 0000000..7b02904 --- /dev/null +++ b/Day1/input.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/Day2/Part1.js b/Day2/Part1.js new file mode 100644 index 0000000..456972d --- /dev/null +++ b/Day2/Part1.js @@ -0,0 +1,38 @@ +import { readFileSync } from "fs"; +const t0 = performance.now(); + +const lines = readFileSync("input.txt") + .toString() + .split("\n") + .filter((e) => e.length > 0); +const ids = lines.map((e) => { + const current = parseInt(e.match(/^Game (\d{1,3}):/)[1]); + const pulls = e.split(":")[1].trim().split(";"); + + let failure = false; + for (const cubes of pulls) { + const values = cubes.split(",").map((e) => e.trim()); + const bag = { red: 12, green: 13, blue: 14 }; + values.forEach((e) => { + const splits = e.split(" "); + const color = splits[1]; + const amount = parseInt(splits[0]); + bag[color] = bag[color] - amount; + }); + if ( + Object.keys(bag) + .map((e) => bag[e]) + .filter((e) => e < 0).length > 0 + ) { + failure = true; + break; + } + } + + return failure ? -1 : current; +}); +const sum = ids.filter((e) => e >= 0).reduce((a, i) => a + i); +console.log(sum); + +const t1 = performance.now(); +console.log(`Runtime: ${t1 - t0}ms`); diff --git a/Day2/Part2.js b/Day2/Part2.js new file mode 100644 index 0000000..564c3db --- /dev/null +++ b/Day2/Part2.js @@ -0,0 +1,30 @@ +import { readFileSync } from "fs"; +const t0 = performance.now(); + +const lines = readFileSync("input.txt") + .toString() + .split("\n") + .filter((e) => e.length > 0); +const powers = lines.map((e) => { + const pulls = e.split(":")[1].trim().split(";"); + + const min = { red: 0, green: 0, blue: 0 }; + pulls.forEach((cubes) => { + const values = cubes.split(",").map((e) => e.trim()); + values.forEach((e) => { + const splits = e.split(" "); + const color = splits[1]; + const amount = parseInt(splits[0]); + min[color] = Math.max(min[color], amount); + }); + }); + + return Object.keys(min) + .map((e) => min[e]) + .reduce((a, i) => a * i); +}); +const sum = powers.reduce((a, i) => a + i); +console.log(sum); + +const t1 = performance.now(); +console.log(`Runtime: ${t1 - t0}ms`); diff --git a/Day2/input.txt b/Day2/input.txt new file mode 100644 index 0000000..7afc5dd --- /dev/null +++ b/Day2/input.txt @@ -0,0 +1,100 @@ +Game 1: 1 blue, 1 red; 10 red; 8 red, 1 blue, 1 green; 1 green, 5 blue +Game 2: 9 green, 11 red; 1 green, 7 red, 1 blue; 1 red, 1 blue, 1 green; 11 green, 3 red, 1 blue; 5 green, 12 red; 8 green, 1 blue, 7 red +Game 3: 16 blue, 2 red, 4 green; 8 red, 4 green; 7 green, 16 blue +Game 4: 3 green, 4 blue, 6 red; 7 red, 12 green, 5 blue; 5 green, 16 red, 8 blue +Game 5: 4 green, 4 blue, 3 red; 4 green, 7 red, 1 blue; 2 blue, 2 red, 4 green; 3 green, 7 red, 4 blue; 2 blue, 3 green, 8 red +Game 6: 3 green, 4 blue, 10 red; 13 red, 3 green, 4 blue; 11 red; 14 red, 1 green; 6 red, 2 green, 1 blue; 10 red, 1 blue, 1 green +Game 7: 2 green, 9 red, 9 blue; 12 red, 14 blue; 8 red, 3 green +Game 8: 9 green, 1 red; 18 green, 2 red, 7 blue; 1 blue, 9 green, 3 red; 3 red, 15 blue, 18 green +Game 9: 2 red, 1 blue, 10 green; 4 red, 1 blue, 5 green; 6 green, 3 red; 1 green, 2 blue; 8 red +Game 10: 9 green; 6 red, 4 green, 4 blue; 9 red, 2 blue, 9 green; 8 blue, 9 red, 12 green; 4 red, 8 green, 2 blue; 6 green, 7 blue +Game 11: 1 blue, 15 red, 2 green; 3 green, 9 red; 1 blue, 3 red, 1 green; 10 red, 1 green; 3 red +Game 12: 6 blue, 9 red, 4 green; 1 green, 8 blue; 4 green, 8 blue, 1 red; 7 green, 7 blue, 2 red +Game 13: 11 green, 8 blue, 1 red; 5 blue, 2 red, 5 green; 2 red, 18 green; 5 blue, 5 green, 2 red +Game 14: 1 red, 4 blue, 3 green; 2 red, 1 green, 1 blue; 1 red, 5 green, 1 blue; 3 red, 4 green, 4 blue +Game 15: 2 blue, 1 green; 3 red, 2 blue, 7 green; 1 red, 4 green, 15 blue; 1 green, 14 blue, 2 red +Game 16: 3 red, 10 blue, 9 green; 20 blue, 13 green, 1 red; 9 green, 11 blue, 6 red +Game 17: 4 red, 1 green, 1 blue; 1 green, 1 red, 11 blue; 1 red, 7 blue +Game 18: 5 red, 9 green; 17 green, 2 blue, 16 red; 11 red, 2 blue, 1 green +Game 19: 3 red, 14 green; 4 blue, 1 red, 17 green; 14 green, 3 red, 9 blue; 9 blue, 8 green, 8 red; 4 green, 8 blue +Game 20: 8 green, 3 blue, 3 red; 5 green, 6 red, 1 blue; 1 blue, 6 red, 13 green; 1 blue, 4 red; 4 red, 4 green, 1 blue +Game 21: 10 green, 3 blue, 7 red; 4 green, 14 blue, 11 red; 2 red, 8 green, 15 blue; 13 green, 7 blue, 4 red +Game 22: 3 blue, 11 green, 3 red; 7 green, 2 blue, 2 red; 3 red, 3 blue, 15 green; 12 green, 2 blue, 5 red +Game 23: 4 red, 3 blue; 2 green, 7 red, 6 blue; 1 green, 2 red, 3 blue +Game 24: 7 red, 3 green, 2 blue; 3 red, 9 green, 9 blue; 8 green, 6 red, 7 blue +Game 25: 2 red, 2 green, 2 blue; 3 green, 1 red, 4 blue; 4 red, 3 blue; 4 green, 1 blue, 5 red; 2 green, 4 red, 2 blue; 5 green, 3 red +Game 26: 1 red, 7 blue, 12 green; 2 blue, 2 red, 7 green; 3 green, 5 red, 6 blue; 8 green, 3 blue, 5 red; 15 green, 7 blue +Game 27: 4 blue, 7 red, 15 green; 4 red, 1 blue, 15 green; 3 red; 8 red, 4 blue, 10 green; 4 red +Game 28: 2 blue, 5 red, 8 green; 13 red, 9 green; 2 blue, 4 red, 5 green; 1 blue, 14 green, 12 red; 13 green, 11 red, 3 blue +Game 29: 7 green, 10 red; 9 green, 2 red, 1 blue; 3 blue, 13 green, 5 red +Game 30: 3 green, 6 blue, 5 red; 3 green, 1 red, 13 blue; 2 red, 2 green, 7 blue; 13 red, 2 green, 9 blue; 2 blue, 7 red, 2 green +Game 31: 8 red, 16 green, 1 blue; 10 red, 3 blue, 11 green; 2 green, 4 blue, 3 red; 2 blue, 7 red, 12 green; 16 green, 9 red, 6 blue; 8 blue, 9 red, 11 green +Game 32: 6 red, 3 green, 7 blue; 3 green, 7 blue, 3 red; 4 green, 1 red, 7 blue; 7 blue, 6 green, 5 red; 9 green, 11 red +Game 33: 8 green, 6 blue; 2 green, 8 red, 1 blue; 12 green, 4 blue, 14 red; 11 blue, 1 green, 7 red; 1 blue, 5 green, 9 red; 7 green, 7 red, 5 blue +Game 34: 5 blue, 6 green, 7 red; 6 blue, 5 green, 10 red; 9 red, 3 blue, 7 green; 9 red, 4 green; 15 red, 6 green, 4 blue +Game 35: 6 blue, 4 green, 7 red; 2 blue, 6 red; 4 green, 11 red, 2 blue; 2 red, 1 blue, 4 green; 10 red, 10 blue, 1 green; 11 blue, 4 green +Game 36: 13 blue, 6 green, 7 red; 5 red, 9 blue, 9 green; 6 red, 2 blue, 3 green; 2 blue, 7 green; 7 red, 5 blue; 12 blue, 7 red, 3 green +Game 37: 2 red, 12 green, 3 blue; 6 red, 4 blue; 3 blue, 1 green; 4 red, 5 blue, 6 green +Game 38: 3 red, 16 blue, 10 green; 6 red, 5 green, 5 blue; 7 blue, 12 red, 5 green +Game 39: 17 red, 4 green, 6 blue; 6 blue, 11 red; 18 red, 3 green, 1 blue; 3 blue, 6 red, 2 green; 19 red, 5 blue +Game 40: 1 red, 2 green, 3 blue; 6 blue, 5 green, 1 red; 5 green, 1 blue +Game 41: 7 blue, 6 green; 8 blue, 2 red, 3 green; 2 blue, 3 green; 3 green, 7 red, 17 blue +Game 42: 6 blue; 10 red, 5 blue, 14 green; 1 blue, 11 green; 6 blue, 2 green, 5 red; 7 blue, 13 green, 11 red +Game 43: 15 green, 3 blue; 7 blue, 14 green; 11 blue, 3 green; 17 green, 1 red, 1 blue; 17 green, 2 blue, 1 red +Game 44: 11 red, 4 blue, 16 green; 11 blue, 16 green; 14 red, 10 blue, 17 green +Game 45: 6 blue; 6 green, 6 blue, 1 red; 5 blue, 11 green; 4 green, 6 blue +Game 46: 6 green, 3 blue, 2 red; 9 green, 4 red, 2 blue; 9 green, 1 red, 3 blue +Game 47: 6 red, 3 blue, 9 green; 3 green, 11 blue; 4 blue, 1 red; 11 green, 11 blue +Game 48: 13 blue, 15 red; 9 red, 9 blue; 15 green, 9 red, 1 blue +Game 49: 8 green, 4 red; 1 red, 6 blue; 5 blue, 8 green; 1 red, 2 green, 3 blue; 2 red, 5 blue, 5 green +Game 50: 1 red, 8 green, 3 blue; 1 blue, 9 green; 3 green, 6 blue +Game 51: 8 green, 8 red, 8 blue; 9 green, 2 red, 6 blue; 1 green, 1 red, 1 blue; 5 blue, 1 red, 7 green; 7 blue, 5 red, 5 green +Game 52: 2 green, 1 red; 4 blue, 7 red, 2 green; 3 red, 4 blue; 1 green, 1 blue, 7 red; 8 red, 1 green, 8 blue; 4 blue, 3 green, 4 red +Game 53: 9 blue, 9 red; 3 blue, 3 green, 5 red; 1 green, 6 blue, 2 red; 4 red, 3 green, 3 blue +Game 54: 1 blue, 2 red, 2 green; 6 green, 1 blue, 3 red; 1 green, 1 blue +Game 55: 14 red, 8 blue; 9 red, 2 green, 8 blue; 6 blue, 11 red, 1 green; 10 red, 3 blue, 4 green; 13 red, 2 green, 4 blue; 5 green, 5 blue, 3 red +Game 56: 12 green, 3 blue; 1 red, 13 green, 5 blue; 17 blue, 6 red, 2 green; 4 red, 12 green, 12 blue +Game 57: 9 green, 9 red, 10 blue; 10 blue, 10 red, 9 green; 4 blue, 14 red, 8 green; 14 red, 7 green; 10 green, 3 blue, 7 red; 1 red, 2 blue, 1 green +Game 58: 1 green, 9 red, 11 blue; 5 green, 11 red, 6 blue; 2 green, 3 red, 8 blue; 2 green, 14 blue, 4 red; 9 blue, 1 red +Game 59: 10 blue, 13 green, 3 red; 4 red, 12 green, 8 blue; 4 red, 9 blue, 10 green; 17 green, 5 red, 7 blue; 4 red, 3 blue, 10 green +Game 60: 4 green; 5 blue, 8 red; 19 red, 3 blue, 2 green; 4 green, 14 blue, 3 red +Game 61: 2 red, 6 blue; 15 blue, 5 red; 1 green, 2 red; 1 green, 2 blue, 8 red; 7 red, 10 blue; 11 blue +Game 62: 10 blue, 2 green, 7 red; 2 red, 2 green, 10 blue; 5 red +Game 63: 19 red; 1 green, 2 blue, 3 red; 1 blue, 11 red +Game 64: 11 red, 3 green; 3 red, 1 blue, 3 green; 2 green, 2 red, 4 blue; 9 red, 1 green; 3 green, 7 red, 4 blue; 9 red, 2 blue, 3 green +Game 65: 2 red, 12 green; 3 red, 3 green; 8 green, 1 blue, 4 red; 2 red, 3 green +Game 66: 4 blue, 11 red, 15 green; 1 blue, 2 green, 10 red; 4 red, 5 green; 16 red, 16 green, 4 blue +Game 67: 6 red, 1 green; 1 green, 1 blue, 12 red; 11 red, 2 blue +Game 68: 4 green, 5 red; 9 blue, 1 red; 1 green, 2 red, 7 blue; 6 red, 5 green, 8 blue; 2 green, 7 red, 2 blue +Game 69: 9 red, 16 green, 12 blue; 5 red, 4 green, 3 blue; 6 green, 11 blue, 6 red; 13 green, 16 blue, 7 red; 1 red, 8 blue, 14 green +Game 70: 7 red, 5 blue, 4 green; 6 red, 12 blue, 13 green; 5 green, 4 red, 8 blue; 9 blue, 5 green, 2 red +Game 71: 15 red, 3 green, 3 blue; 1 red, 5 green, 6 blue; 6 green, 7 blue, 16 red +Game 72: 4 blue, 4 green, 6 red; 9 green, 2 blue; 15 green, 5 red +Game 73: 1 green, 7 red; 6 red, 2 blue; 5 red, 9 blue; 12 blue, 9 red +Game 74: 6 blue, 4 red, 4 green; 17 green, 1 blue; 4 blue, 7 green, 4 red +Game 75: 3 green, 2 blue, 10 red; 17 red, 14 green, 2 blue; 2 green, 1 blue, 14 red; 16 red, 1 blue, 9 green; 14 red, 1 blue, 9 green +Game 76: 1 red, 10 green, 4 blue; 4 blue, 4 red, 7 green; 1 red, 2 blue, 15 green; 5 blue, 7 green, 1 red; 5 blue, 3 red, 17 green; 18 green, 4 blue, 1 red +Game 77: 4 green, 5 blue, 7 red; 3 blue, 4 red, 5 green; 1 red, 1 green; 6 green, 4 blue, 16 red +Game 78: 2 blue, 9 red; 7 red, 3 blue, 18 green; 2 blue, 12 green +Game 79: 3 red, 10 green, 10 blue; 10 blue, 12 green; 7 green, 10 blue, 3 red +Game 80: 10 green, 2 blue, 14 red; 3 blue, 4 red; 12 green; 3 red, 2 blue, 1 green; 10 red, 12 green, 2 blue +Game 81: 1 green, 3 red, 6 blue; 5 blue, 1 red, 1 green; 6 blue, 9 red +Game 82: 3 blue, 11 red, 20 green; 15 red, 5 green, 3 blue; 4 red, 7 green, 3 blue +Game 83: 5 red, 12 blue, 6 green; 11 green, 9 blue, 6 red; 6 green, 1 red, 7 blue; 16 blue, 4 red; 3 green, 6 blue +Game 84: 3 red, 3 blue, 2 green; 3 red, 9 green; 2 blue, 11 green, 1 red; 1 red, 11 green, 1 blue +Game 85: 11 green, 1 red, 2 blue; 6 red, 8 green, 14 blue; 3 red, 6 green, 15 blue; 9 blue, 7 red, 1 green; 19 blue, 2 green, 5 red; 6 blue, 7 red, 6 green +Game 86: 11 red, 4 green; 2 green, 1 blue, 10 red; 11 red, 3 blue, 9 green +Game 87: 2 green, 17 blue; 12 blue, 3 red, 2 green; 3 green, 2 blue, 13 red; 6 red, 3 green; 13 blue, 11 red, 3 green; 5 blue, 7 red, 1 green +Game 88: 1 red, 12 green; 4 green, 3 blue; 6 blue, 12 green; 1 red, 2 blue +Game 89: 9 green, 2 red, 12 blue; 19 green, 12 blue, 3 red; 2 red, 8 blue, 11 green; 13 blue, 8 red, 9 green +Game 90: 2 red, 2 blue, 7 green; 7 green, 2 red, 12 blue; 6 red, 9 green, 5 blue +Game 91: 14 blue, 2 red, 7 green; 7 blue, 7 green; 1 red, 5 green, 10 blue; 4 red, 7 blue, 4 green; 5 green, 1 red, 13 blue; 5 green, 1 red +Game 92: 6 green, 4 blue, 7 red; 18 blue, 3 red; 6 red, 2 blue; 16 blue, 5 red, 3 green +Game 93: 6 red, 17 blue, 5 green; 14 red, 16 blue, 10 green; 11 blue, 7 red, 11 green; 6 blue, 7 green, 3 red; 17 blue, 1 green +Game 94: 4 green, 9 blue; 2 green, 6 red, 3 blue; 5 red, 4 green, 8 blue; 4 green, 5 red, 6 blue; 7 green, 7 red, 6 blue +Game 95: 6 blue, 2 red, 3 green; 9 green, 2 blue; 2 red, 4 blue, 11 green; 4 blue, 4 red, 8 green; 13 green, 5 red, 7 blue; 4 red, 15 green, 2 blue +Game 96: 5 red, 8 blue, 5 green; 12 blue, 2 red; 15 blue, 2 red, 1 green; 4 red, 1 green +Game 97: 5 red, 5 blue; 1 red, 11 blue; 3 green, 10 blue; 3 green, 1 red, 7 blue; 2 blue, 6 red; 1 red, 1 green, 8 blue +Game 98: 4 red, 3 blue, 8 green; 5 blue, 2 red, 8 green; 7 green, 10 red, 2 blue; 11 blue, 9 red, 9 green; 6 blue, 10 green, 11 red +Game 99: 7 green, 3 red, 9 blue; 3 blue, 5 red, 4 green; 2 red, 6 green, 1 blue; 12 blue, 1 red, 1 green; 11 green, 1 red, 12 blue +Game 100: 2 blue, 1 red; 4 blue, 2 red, 1 green; 7 red, 5 blue; 2 red, 1 green, 5 blue diff --git a/Day3/Part1.js b/Day3/Part1.js new file mode 100644 index 0000000..1309c7c --- /dev/null +++ b/Day3/Part1.js @@ -0,0 +1,51 @@ +import { readFileSync } from "fs"; +const t0 = performance.now(); + +const lines = readFileSync("input.txt") + .toString() + .split("\n") + .filter((e) => e.length > 0) + .map((e) => e.split("")); +const numbers = lines.map((a) => { + const current = { index: 0, number: "" }; + const scan = a + .map((c, i) => { + if (!isNaN(c)) { + current.number += c; + return -1; + } else if (current.number.length > 0) { + const next = { + number: current.number, + index: current.index, + }; + current.index = i + 1; + current.number = ""; + return next; + } + current.index = i + 1; + return -1; + }) + .filter((e) => typeof e === "object" || e >= 0); + if (current.number.length > 0) scan.push(current); + return scan; +}); +const adjacent = numbers + .map((a, l) => + a.filter((n) => { + for (let k = 0; k < n.number.length; k++) + for (let i = -1; i < 2; i++) + for (let j = -1; j < 2; j++) + if ( + lines[l + j] && + (lines[l + j][n.index + k + i] ?? "").match(/[^.\s\w]/) + ) + return true; + return false; + }) + ) + .filter((a) => a.length > 0); +const sum = [].concat(...adjacent).reduce((a, i) => a + parseInt(i.number), 0); +console.log(sum); + +const t1 = performance.now(); +console.log(`Runtime: ${t1 - t0}ms`); diff --git a/Day3/input.txt b/Day3/input.txt new file mode 100644 index 0000000..8faa3ba --- /dev/null +++ b/Day3/input.txt @@ -0,0 +1,140 @@ +.......12.......935............184.720...243........589.652..........435..........483.............6...........................904........... +......*.....968*.....$............*........=..348...*..........986....*...................459....*........422................#......%482.... +....291............612....290..........903........699......218*.......376............890....*.838...81......*.....138.../194................ +..............156......$..*...891.&731....%..89...................523..........699....+...227......*.......225....=...........388....*...... +................*...189..591.*................*.......783.....107..-...54.287..$................533.../..............909........&.603.424... +...229*952.....938............470.555.......746...28.....+...*.........................................279..826..788*....................... +...................................*...............@.........867.-....102..845...542.779.....................*........182.166...511......... +563.727.....282....237..171.......892...183.......................989....*..........*................$....709...8*974.=...%.....*.....873... +....#..........+...*.......*..........................&......129+......491...................877....715.......................270.......#... +.................53.....781...&295....@773.336......547................................45......*.............=800.....*359.................. +...342*468....&.....573....................*.................................%850............*..465................192.....*.......&115..... +............988.......*...731.............789.673....*256..............677..................621...........#....716......910..297........22.. +204&....69............905...=.....641.472.......#.524............127....*..714.........*62..........622..324..&.................*........... +..........*........................+....@.................812......*..955.....*.....257....../.................../..............545......... +........668....91..&.........840......+..............566.....+...66.........660..............469.................525...765...........25..... +...............$...666.979..*........952...122......%............................71......=39...../94.........................132......*..... +......@.................../.460..#.......=.=..........146..625........214.........#.278................667..........386.......-....936...... +....643.......@..................974...464...........*.....*...........*.............%.....$...........=...=..%995...*...................... +........./...577...-....3.../186.................*.995.....678.&.......882...559...........374.......&...554.........428.......725....*..... +.......96........678....%.....................529..............374...........*......924........=277..606..................#...#......8.257.. +...609....................397.......475...................651.......856......697.&.....&..=...................486........888................ +............-................*..................756...399....*..42................866....287.....#......515...*......................137.... +.....285..947....#..........997......=.....665..*......*..420...*.....-..268*457.............=63..758.....+..623.............+../........... +..............458.....422.......338...827...+..462....797.....26....523..........*.880*.............................&.....934..157.......... +.......149........409....$................................................868.378......144..149............356.....872..............871.533. +....22...*..........$........7.......149....979......................826.&.....................@........-.....*275.....................*.... +........518.773*.........10..$..........*........805..812.972......................123......*............98.........=........./609.682...... +.................5........./............349........$.....*..................786....*.......160..903...40.............209...............*.... +.......*.....................................497...........#.............../.....153.795............./.........&806..........839....419.337. +78...582............675................145.........405....77..361............952.......*..../741....................624..527*............... +...................../../....=.....+....&.............*51.....*..........733*.........728.........173....834.....76......................... +................878....276..792.....372....................385..179.............@610.............................%........146=.............. +..........522.....*...........................-....30....-........*.@................110=..+.......197.....643.................762......%... +......%....*...173.............420..407......261.........687.806.12..104.....914..........685.233.&.......*.....549...=...........*......591 +.....837..135.......313...579....%.=.....613................../..........729.........257#.....&.........430.399*.....157.........970........ +...................*.....*.....*......@.....*............../....566........+.....................*906....................%.................. +....459.78$.775.768..62...345.537......122.803.142*758...148...*....992................711....316.........#...............521.298*590..289.. +....*.................#.........................................444............382.....*...@...............753.......927................/... +.....592..735......+.............634.......652.....853....690................./.......874.846.35.....884.........182.-...................... +.419........*.839.157.......795...................*.......*...........928........................756....*64......*.....*19.....309.......... +.........716...*.......591....*....358$.#378.............623...............687.........-816......*............292...110....&....*......643.. +..134...........910......*.941.......................................547=....*....................490....938+..............422.482.......... +...*..331....$..........80.................#346....180...........737.........76.......992@...91......................../.................... +...16....$.140.464*831.....933.917....303............*......%.....*....336........339.......*.............@..939....583....*564.........864. +..............................*........=...+54.....449......209.912.....+.....615..%.....605............960..*..........219................. +.........@442.....730..................................413...........................26.....................944..336........188......./..... +...190............#...@...524.544....968*.............*........466...222...536...843.@..........=.....32...........$..........-.......410... +......*..80@..491....232..-......*.......16........402......27..*...*.....*...................480....*........&........894.................. +.....218.........*.............=..819......................*........857...896...........677........689........638...45*.....993............. +................754...........434.........622.338...........607....................&......&.%213...........................-................ +........+.894......................681.......*.........484.........963.498...*..538.............................................346......... +.....802.....*162....752...........................................*........520...........229.2.586..513..............25=.746........782*423 +...............................@...307#.497....551..996..696....879...911................%......................277*........................ +....*157.....137....#.........621.........*...#.....*...#............*............527......9........./..............844.....@224....304..... +.541............*.649.............412.....744......560..............404.....240.......986*.@.......346.....@..........................+..... +......268....764.................%.......................902....856.......*....*..........................242.....842.....#................. +........&...............514..38..........+..=...........@..............715.142..587.......307.................731...*...954....878*......... +............................*.....349....76.92....612.....376.......................257...$...................../.968..............765...... +........960*414........713.501......&............%.......*......*941............................#........415...........937%................. +....967............409..*......605......................375..771........599*884.................880.........*...127..$.................$513. +.....*................*..171..*.....@.......507.895..................*.................636...........768...114....-..292.......-...223...... +...807...977.......218.......753...47.......*......*..............507.90....../725.......*.........+...@.....................755......*..... +............*478.............................542....676...............................673........974.....@....*170....261..............134.. +800...............532............................15............%...445..102.............../510.........625.279..........-.....*............. +.......................654.....850.405......................395.....-.......467....477...........973............../........191........398... +.925...793...423*.........@..........................................................=.659..........*.....817.....230...........653..-...... +.......*.........52...........764$....273...................@........430....................................*...........669.....-.......71.. +.435....804..177....990.838.........#..-...475...297..337..360.........*....914.............................833............................. +....*.......*.........*...*.......281......&......*..+.............328..746......=215.......359....295.....................#481......868.... +..967........936.689%.785..515...............*64.827........................761.........+....&.......+..............................*....637 +....../.+265..............................562...............235........585..*...........793........=...838.147....284.902..301*330.......... +....579.........................21%..327................481..*...469%..*.....297.704..............797.....*...........*.................#... +......................638............*...................*....81.......780.........*...../...282....................907.882.781.......797... +..........671....608.................295.................302......953............171..919.......*........................*...*......#....... +............*....*....251.....191........#............*..........................................999.....451....+....286.415.581....274..... +..245$.....217...649.-....................898......950..................495*497.......53*............@...........398..-..................... +...........................942.......323...............+.....623.........................804.......875........................#............. +.....42..543.................*..320....*..918....314....145...........603......991$.921.......261......................762...187.....951*638 +.....*..#........53........374........756...........*.........-.......................*........../..217*550..............*.................. +....217..........*................................743......703....368...$861..4*966.415..703................................*959........*344 +...........626...31...602.................700..........696........*.....................*......396..........591.......*124.................. +..135........@................................699.139.....*.662....46........=797......144.....#...*289......*.....840............-...102.44 +................909.......180.............100.*....#...574..*............52...................................451............764.517....*... +........701*..........127*............117../...787...........67.....903..........273....*900................................=..........112.. +............430............423.67.......*..............*572...........@...199.........94..........686.....679.....................921*...... +.542*119...............396....*.......938...........250......888..........*.....978...................25..../.........306.............780... +...............251........*.....................238......................340....+..............112....*........120...*....24................ +.223.....549......-..98..60..775..28*105...........*.436..951.599.................309*682.......*..937...158.....*....697.*......764..$..... +.....788............#....................768.....266........*..%..............................779........*.......542.......148...*....529... +....*......310.............412.......23.+....289..........560............249+.204..606*................271...805.......394.......898........ +....919.......&...867.......*........*......%.........592............166.........*.....460.........369..........*........*.................. +.........920.......*.....233.....732..500.....950.....*.......514...........110..961..................*309.....450..#...521................. +.................753...............*............#...965..............................852...841....%........524.....981............653....... +...........858...........*..234..922........65..................991.........-839.800....*......869...836..$.............675..789...*....505. +..........*.............516...*..................774.....&.149.=.................*.......737.........*......402....%.......*....#..762...... +........780.........4.........116.....................976..-...........%........791..................300.....%....338.471................... +...................*.................480*160..3..............*727.....363................................................................167 +...........743.....721.......................*..........808...............942...........339.289.............$............416.....$.......... +..955...................606*623.............718...503....*...................*245..........*........531.....686......250..../....275........ +.............@....................110...............*...309..#....&......210..........386.................%...........*........+........391. +.....444.....743......519..691......*.......-824......+......759.617....*.......710..*.....814.........356.........464.......709............ +......*..746......247.....*......596..999.............907.............296.-..../.......760.+.................$.890.......................669 +...479.....*.........*.......561.....+..........*178......................977....266...*.....640..........607.....*.....%...........545..... +........395...=......361........*372.........655..........398...203..11................147..*......../.............196..499........*........ +..561........646......................*898.......175.570.....$.....#...*..135..............633..314...871......898..........891...90.....780 +.......*91........405..............627..............*....736.........760.....*........=..........*...........%....*..........*.............. +....722...........*......................................*.................744.698.367..-........767..........236.692.......308............. +...............740........./............906......*593...977.......645............*......167.............................................*... +........+...............123...................281....................*...543......461........................175.....................381.319 +.282...814......771*........920.......................@............473....*...............&....872...../401.....*......=......18............ +....*.........%......993...*...........................256..223...........242....977.......293.-...............550.....435.................. +....23.........960........307....$.....504.638*656...............&...................203.............33.$430..................731........... +................................885......*................398....763...........805.....=....338.......*......146*916..................513... +..20...............42....................828.............../...................*............$.........531............159*761......78........ +......805-...-..........598...........#.............351........34.........682..516.534..............*........&..........................283. +..............664....../.......255..887.....258......%.........*.........*............*.....226..931.91......128............................ +...557.938#.......75.....585..*...............*.194......#..686........786..........755.......&..........637..............988.......275..... +....*............%....35...*.141...........508.....*865.967..............................80*............./.....978....790*.....@...*........ +.662..................*..............@939...........................204........484....34....99.............@.................350.54......... +............358....832..=......................%......307.95........*......654...*......&.........734.....491...50...924.385................ +............*............340................483.........-.*.......118..794*.....431...........783..*..............-......*.........&594.#... +..........338........=.............$.................*....94....................................*...546.....$.......187..593.768........282. +...............796.380.183....+.564..94.144.........138..............394.392.....971.......#928.447........275..57...*.......&.............. +...........233...*.......%...40........*........................945.....*.........-.................%.............=.438...........*......906 +.....881.../...491...903..........918.....303......................*........578*...................807......597................681.539...... +......*.................*.463.467*....246.......577.....198.....245.....967.....988.&.........759.......=...*.........-889.................. +......462..978........664...%...........*.-731.../.....&....375.............#.......217........@........381.250...219......947.............. +..........&..........................252.......%.............*..............258............427...137...............@........@....-175....... +....864...................461..................234.......69.222........*...........411....=............651...#.............................. +....*......243...............*283...................777-..*..........92.761..581%.*.....................$.....258..867..876................. +.916......%.........629.................911*238...........680...239................672.............137@...469.........*.......737...@....... +..............764....*........894/..289...........944..........#...........@....%........../876..........*.........687.........*....436..... +......442.255.....442..903.............*.....*493..../......................338..346...................927..............764.....536......... +.........*.....*........*.....869*888.597.241..................11-....542#...........412*..................235.............................. +.804.329......344....195...94.......................................*....................880......44.622.........342.18...............417... +....*.....=................+.........76..328.....803.....658.....254.............327..........340......*.............@...................... +...........254........../...........*...*...........*234...%..........20.....238...*..........*.........380......&......78.246%...598....... +.96....990.........%..718...%....869.......596....*......................423.....433..93.....613....$.............905...=........*.....497.. +...*....*........=.86.....499..............*...385.296...................*...........*...............523.$.....................529...$.*.... +...780.685.....822....................560.35.............................529......780.....................453......................711..930. diff --git a/Day4/Part1.js b/Day4/Part1.js new file mode 100644 index 0000000..ff27adc --- /dev/null +++ b/Day4/Part1.js @@ -0,0 +1,28 @@ +import { readFileSync } from "fs"; +const t0 = performance.now(); + +const lines = readFileSync("input.txt") + .toString() + .split("\n") + .filter((e) => e.length > 0); +const cards = lines.map((line) => { + const id = parseInt(line.match(/^Card\s{1,}(\d{1,3}):/)[1]); + const left = line + .match(/:\s*((?:\s*\d{1,2})+)\s*\|/)[1] + .split(/\s{1,}/) + .map((num) => parseInt(num)); + const right = line + .match(/\|\s*((?:\s*\d{1,2})+)\s*$/)[1] + .split(/\s{1,}/) + .map((e) => parseInt(e)); + const matches = right.filter((a) => left.some((b) => a === b)); + return { id, left, right, matches }; +}); +const points = cards.map((e) => + e.matches.length > 0 ? 2 ** (e.matches.length - 1) : 0 +); +const sum = points.reduce((a, i) => a + i); +console.log(sum); + +const t1 = performance.now(); +console.log(`Runtime: ${t1 - t0}ms`); diff --git a/Day4/Part2.js b/Day4/Part2.js new file mode 100644 index 0000000..fb1e4d0 --- /dev/null +++ b/Day4/Part2.js @@ -0,0 +1,30 @@ +import { readFileSync } from "fs"; +const t0 = performance.now(); + +const lines = readFileSync("input.txt") + .toString() + .split("\n") + .filter((e) => e.length > 0); +const cards = lines.map((line) => { + const id = parseInt(line.match(/^Card\s{1,}(\d{1,3}):/)[1]); + const left = line + .match(/:\s*((?:\s*\d{1,2})+)\s*\|/)[1] + .split(/\s{1,}/) + .map((num) => parseInt(num)); + const right = line + .match(/\|\s*((?:\s*\d{1,2})+)\s*$/)[1] + .split(/\s{1,}/) + .map((e) => parseInt(e)); + const matches = right.filter((a) => left.some((b) => a === b)).length; + return { id, left, right, matches }; +}); +const cardCount = (c) => + 1 + + [...Array(c.matches).keys()] + .map((e) => cardCount(cards[c.id + e])) + .reduce((a, n) => a + n, 0); +const totalCards = cards.map((e) => cardCount(e)).reduce((a, i) => a + i); +console.log(totalCards); + +const t1 = performance.now(); +console.log(`Runtime: ${t1 - t0}ms`); diff --git a/Day4/input.txt b/Day4/input.txt new file mode 100644 index 0000000..704fc54 --- /dev/null +++ b/Day4/input.txt @@ -0,0 +1,190 @@ +Card 1: 2 15 17 11 64 59 45 41 61 19 | 4 36 62 43 94 41 24 25 13 83 97 86 61 90 67 7 15 58 18 19 38 17 49 52 37 +Card 2: 41 62 67 93 88 12 78 51 95 49 | 55 63 89 78 45 11 62 50 81 9 32 82 15 36 74 54 4 58 5 56 44 83 90 49 34 +Card 3: 51 22 38 33 85 23 56 76 60 93 | 94 40 61 37 38 82 93 96 13 50 81 65 56 26 4 18 86 30 8 16 60 27 23 48 51 +Card 4: 51 6 90 10 97 65 19 17 24 3 | 93 82 10 13 17 3 90 74 14 7 77 38 70 97 72 60 6 79 65 94 24 19 51 45 28 +Card 5: 76 61 43 95 41 2 40 58 30 96 | 72 23 69 5 30 3 10 17 78 20 13 86 60 81 90 46 96 39 6 32 31 73 65 95 62 +Card 6: 32 70 49 99 27 26 75 96 91 4 | 15 74 28 2 17 82 55 96 88 11 95 77 12 38 91 3 56 44 7 32 19 94 85 27 97 +Card 7: 38 21 90 66 46 32 55 94 72 75 | 3 10 90 77 41 99 46 82 65 72 9 21 66 94 80 22 97 56 93 61 18 81 34 76 64 +Card 8: 32 36 87 79 4 17 1 77 16 63 | 9 63 23 25 91 82 35 74 28 72 6 52 56 12 39 99 57 46 15 76 85 2 75 77 96 +Card 9: 42 5 58 80 96 88 37 30 49 69 | 26 6 17 71 46 51 45 10 62 33 38 23 42 74 50 61 95 11 93 57 14 22 72 85 86 +Card 10: 10 74 58 71 57 35 34 96 77 18 | 14 27 22 18 70 42 56 94 76 74 85 73 61 34 88 45 39 64 35 87 90 58 91 75 54 +Card 11: 24 26 43 62 66 93 38 51 95 86 | 31 75 23 91 12 3 90 9 36 87 76 58 40 35 56 65 17 74 61 93 20 71 82 92 73 +Card 12: 2 25 63 37 64 81 20 15 28 88 | 67 26 12 6 58 37 69 93 83 52 81 25 19 30 80 54 73 21 86 20 8 57 47 32 60 +Card 13: 48 37 14 80 51 17 85 26 40 33 | 80 7 79 38 8 74 10 78 89 16 81 84 19 49 86 83 63 82 40 58 25 47 53 34 4 +Card 14: 93 27 7 80 63 89 50 96 3 15 | 6 19 40 46 51 29 9 86 39 77 4 54 38 41 67 69 1 56 5 35 30 17 71 2 43 +Card 15: 33 72 28 75 56 22 16 38 44 51 | 81 67 79 73 52 40 69 43 12 77 31 41 23 14 64 58 5 88 95 13 99 6 42 83 38 +Card 16: 36 82 59 39 57 26 61 45 60 65 | 66 51 24 1 4 78 17 16 74 95 34 47 75 6 67 44 48 14 10 89 46 2 31 18 68 +Card 17: 40 50 36 8 54 17 29 13 89 98 | 6 59 60 57 18 30 80 32 46 77 86 35 48 84 91 4 38 99 17 33 3 15 82 83 62 +Card 18: 81 11 66 67 19 65 39 64 20 9 | 25 14 60 2 50 97 43 18 36 24 89 74 94 71 51 45 5 34 52 31 90 6 48 40 55 +Card 19: 41 81 99 97 18 92 79 82 83 62 | 97 34 41 76 87 60 21 63 93 55 77 92 42 56 80 94 81 36 11 1 83 70 52 5 29 +Card 20: 50 94 73 61 56 88 35 48 54 21 | 89 35 83 42 45 12 61 18 68 52 13 25 88 54 6 74 21 57 50 56 34 73 48 94 46 +Card 21: 95 69 16 96 19 86 94 74 33 1 | 19 95 86 16 94 76 17 39 5 1 97 27 44 69 74 96 29 48 14 92 33 7 12 91 42 +Card 22: 17 78 32 62 96 43 68 23 97 52 | 97 28 87 26 23 14 78 39 92 56 31 3 32 52 13 43 80 62 17 69 68 5 96 25 75 +Card 23: 57 93 4 6 2 34 18 80 99 9 | 9 53 58 19 35 6 46 87 86 36 59 17 26 54 39 52 99 20 69 18 25 30 34 41 42 +Card 24: 72 43 5 36 81 31 77 76 58 48 | 75 48 31 88 33 38 37 69 40 25 4 93 35 23 76 36 64 44 6 65 59 15 43 17 28 +Card 25: 14 52 98 94 85 95 27 54 67 34 | 54 14 19 3 24 36 6 52 16 95 76 61 23 8 98 34 28 99 67 85 27 55 70 59 94 +Card 26: 33 15 53 51 14 47 12 83 6 48 | 25 15 51 33 12 53 60 49 98 47 30 89 78 83 88 85 6 7 38 92 48 93 74 14 9 +Card 27: 72 33 73 12 18 13 15 88 82 39 | 23 33 72 13 18 1 12 15 64 8 59 73 48 31 40 57 76 39 52 88 89 36 82 41 67 +Card 28: 42 32 84 56 53 69 5 15 8 63 | 88 32 91 44 62 37 69 72 98 29 8 82 21 5 56 15 6 42 58 61 89 35 96 84 59 +Card 29: 51 41 27 43 38 63 67 26 8 50 | 52 8 1 32 26 59 4 67 27 98 75 11 54 14 50 16 70 66 2 86 62 37 65 38 55 +Card 30: 79 88 87 54 17 18 16 58 57 1 | 54 17 68 89 10 29 97 16 72 57 2 38 12 65 98 11 1 33 64 40 79 63 70 88 18 +Card 31: 61 75 59 95 28 91 57 54 55 82 | 19 57 30 95 54 81 64 28 94 92 3 80 10 63 6 83 88 69 59 15 27 93 96 40 38 +Card 32: 67 44 87 82 49 2 85 79 35 77 | 65 21 63 44 4 52 28 89 11 87 37 97 76 71 64 96 69 79 93 13 33 5 7 58 35 +Card 33: 34 69 25 16 38 4 48 28 39 80 | 90 71 48 27 46 54 19 16 69 12 6 59 25 17 10 81 47 30 28 13 66 38 58 4 80 +Card 34: 65 48 49 80 28 9 22 57 47 95 | 28 59 79 2 4 89 64 98 14 90 18 22 92 52 3 37 95 87 74 54 43 26 51 42 88 +Card 35: 60 8 75 58 47 63 90 71 93 50 | 60 9 24 63 98 66 39 91 46 34 86 67 16 95 53 73 48 87 75 96 44 90 68 26 93 +Card 36: 31 61 33 38 70 46 2 81 73 58 | 49 67 79 3 20 64 96 62 81 82 54 57 70 30 43 56 71 86 6 19 48 93 58 15 27 +Card 37: 86 62 46 70 33 84 90 66 89 96 | 56 39 63 53 45 80 49 61 52 64 12 69 74 26 44 86 96 62 27 31 78 2 28 21 16 +Card 38: 95 40 44 15 99 76 85 20 38 11 | 57 22 23 29 69 90 48 51 66 24 11 32 33 25 92 94 70 88 78 39 28 60 77 55 31 +Card 39: 67 40 10 87 93 47 23 98 96 91 | 14 30 78 72 70 99 52 65 84 12 18 75 59 85 83 89 55 11 82 34 63 10 97 54 69 +Card 40: 95 51 94 2 36 99 98 46 87 82 | 1 40 18 73 50 82 66 14 65 85 83 45 89 58 79 55 84 80 90 72 22 5 38 44 69 +Card 41: 68 75 93 29 66 95 27 46 23 82 | 8 60 39 33 41 36 25 73 94 89 50 71 85 19 51 30 53 45 9 31 83 99 5 32 52 +Card 42: 73 48 37 23 32 19 72 52 58 91 | 35 19 55 9 23 79 62 87 72 58 95 68 20 38 5 48 60 37 73 46 91 12 74 52 32 +Card 43: 42 39 19 59 11 50 88 31 10 9 | 77 11 39 56 42 67 22 12 88 57 75 79 80 6 92 86 99 33 59 90 89 93 68 70 61 +Card 44: 86 12 3 41 71 82 6 48 97 93 | 49 75 31 45 41 83 10 86 8 91 9 70 97 69 52 77 51 36 34 14 81 28 2 40 64 +Card 45: 51 9 72 44 18 14 40 97 2 25 | 83 80 62 22 7 34 88 33 17 23 38 81 70 89 26 35 57 78 46 76 4 61 56 98 55 +Card 46: 22 59 61 94 67 87 21 18 12 69 | 50 22 60 21 67 26 59 94 28 33 30 12 16 69 4 27 95 18 61 53 56 47 85 88 87 +Card 47: 91 58 84 29 4 60 77 41 83 97 | 70 35 40 17 62 41 9 59 26 76 78 16 25 92 91 95 71 77 63 21 6 67 54 46 49 +Card 48: 90 56 13 75 73 2 8 62 21 88 | 38 88 76 75 8 2 82 77 56 73 28 18 59 21 65 90 23 94 5 13 15 79 26 1 36 +Card 49: 84 14 99 51 58 28 63 36 48 91 | 94 46 6 61 2 9 40 38 64 63 91 16 49 81 70 48 80 36 51 58 84 98 96 34 60 +Card 50: 79 98 99 11 7 34 38 52 74 27 | 21 57 11 19 89 94 72 52 81 62 92 79 32 77 28 74 84 86 80 69 83 38 98 3 34 +Card 51: 58 60 15 93 24 72 94 29 59 12 | 71 72 7 86 23 39 65 87 76 22 6 74 69 94 46 52 91 60 96 24 93 47 4 15 59 +Card 52: 6 92 21 7 9 55 17 33 23 16 | 28 69 86 94 34 21 95 51 22 41 99 87 46 1 49 36 90 76 35 30 64 5 44 93 58 +Card 53: 57 10 81 4 93 79 51 87 28 50 | 38 34 97 15 49 89 59 37 25 48 70 41 98 33 78 87 95 85 35 71 32 30 96 67 36 +Card 54: 25 41 26 14 99 98 71 83 31 54 | 68 17 28 80 79 10 31 99 54 83 27 14 25 32 26 85 42 76 33 49 8 24 67 71 41 +Card 55: 38 26 25 70 78 37 13 76 31 73 | 82 10 2 51 13 8 98 12 19 77 84 89 93 22 54 35 23 31 69 42 43 25 39 57 94 +Card 56: 31 25 88 98 23 3 2 58 99 67 | 46 27 75 97 84 53 9 47 64 49 23 92 15 74 44 78 58 56 83 30 31 7 5 2 94 +Card 57: 50 61 25 29 59 1 47 72 65 84 | 72 74 97 28 30 75 56 61 44 40 62 95 4 8 64 22 34 25 14 16 50 92 65 39 13 +Card 58: 73 65 94 47 90 35 95 12 81 78 | 86 87 24 11 1 81 96 33 12 18 74 41 9 22 5 44 48 82 68 67 88 94 20 59 90 +Card 59: 41 27 3 55 16 83 49 75 51 88 | 33 66 74 58 60 72 75 67 78 55 68 95 81 3 39 86 69 94 92 4 5 44 57 26 56 +Card 60: 33 93 56 90 16 46 65 78 13 6 | 55 41 70 6 63 69 90 82 22 17 66 2 53 79 49 25 10 34 47 54 43 58 59 81 68 +Card 61: 72 45 87 76 64 80 96 22 67 98 | 69 25 90 48 67 88 30 34 38 98 19 73 86 8 99 35 44 95 91 36 63 37 2 13 66 +Card 62: 96 68 19 52 97 83 60 67 20 35 | 21 96 30 58 10 7 40 25 92 33 15 69 61 34 6 81 87 75 41 16 51 27 8 4 86 +Card 63: 17 1 45 26 82 78 85 15 89 8 | 49 38 16 22 71 50 81 74 87 61 14 19 64 93 96 23 59 56 76 86 53 6 7 80 41 +Card 64: 3 17 22 94 37 39 67 73 27 4 | 8 27 22 5 28 53 47 52 94 25 29 54 1 59 98 16 78 9 65 91 61 74 73 60 37 +Card 65: 80 48 70 23 99 11 20 31 54 94 | 73 69 21 10 66 90 80 29 55 67 92 20 96 94 79 93 31 30 17 14 27 75 13 95 71 +Card 66: 14 79 31 27 89 95 69 63 12 67 | 36 85 67 24 87 72 89 26 17 31 27 55 10 32 14 63 71 79 13 12 81 69 28 95 30 +Card 67: 87 44 51 53 37 69 39 96 90 16 | 22 63 83 31 32 76 66 68 29 30 53 48 4 72 82 46 95 80 17 21 56 51 89 12 77 +Card 68: 39 27 17 15 50 65 38 94 84 42 | 42 84 17 50 52 47 67 93 13 35 7 26 23 95 39 81 94 15 78 27 43 21 38 55 86 +Card 69: 13 22 8 54 61 77 75 31 1 67 | 68 54 15 23 40 58 67 3 71 78 90 33 44 22 57 19 8 30 74 38 48 41 9 25 65 +Card 70: 10 43 33 21 31 6 94 46 82 83 | 48 62 6 19 67 72 46 81 75 5 54 8 56 92 37 76 96 71 32 36 26 14 30 79 9 +Card 71: 91 9 15 33 37 22 61 74 14 70 | 79 31 18 42 43 40 26 56 95 45 86 76 65 23 3 94 24 35 4 2 68 51 25 12 80 +Card 72: 30 79 24 55 42 8 13 90 68 73 | 37 61 34 94 51 30 3 10 26 19 50 42 40 31 80 86 66 27 83 90 73 79 99 14 76 +Card 73: 25 88 63 85 56 49 30 46 10 99 | 46 68 67 60 11 78 6 85 12 97 91 21 27 81 39 48 69 44 25 63 22 10 3 61 79 +Card 74: 21 3 32 71 98 69 44 78 34 11 | 83 56 29 18 34 9 63 92 53 22 61 45 41 38 82 27 49 5 32 99 69 17 55 66 96 +Card 75: 68 92 32 65 49 38 3 56 17 44 | 47 68 6 1 10 24 66 84 60 2 48 56 57 61 51 35 28 17 82 52 98 81 23 75 38 +Card 76: 30 57 5 8 10 95 45 85 54 3 | 53 2 54 34 23 12 48 16 37 92 85 27 83 8 21 44 81 26 49 67 36 25 52 47 68 +Card 77: 31 84 72 26 83 55 20 42 65 61 | 53 96 17 18 59 21 23 77 78 15 43 58 66 3 60 55 38 45 6 72 44 94 11 79 19 +Card 78: 62 77 52 72 13 24 31 60 29 26 | 74 51 46 67 97 14 71 70 55 94 6 16 65 85 66 80 60 27 32 39 73 61 34 91 69 +Card 79: 69 74 82 58 44 37 86 51 75 20 | 93 70 2 35 30 79 45 56 65 59 22 64 89 36 66 5 34 13 49 43 97 74 7 26 83 +Card 80: 84 16 89 49 81 1 79 44 93 25 | 2 35 29 8 87 21 22 57 9 73 67 82 54 45 71 72 59 5 4 97 70 60 91 7 92 +Card 81: 25 44 10 12 23 79 60 45 96 90 | 62 23 25 40 12 90 42 10 79 45 69 46 9 27 73 59 34 44 29 94 95 86 66 1 58 +Card 82: 42 43 37 18 40 64 75 76 99 3 | 67 42 11 18 91 99 14 90 3 23 73 82 76 40 37 44 28 64 96 16 74 75 55 61 15 +Card 83: 38 89 77 47 66 22 87 59 7 43 | 59 46 7 73 79 23 96 22 28 87 66 32 77 89 98 19 38 18 43 56 15 47 74 95 99 +Card 84: 86 13 97 81 46 12 88 34 92 52 | 88 69 8 2 76 63 95 27 46 31 81 48 75 92 60 33 36 22 34 13 57 30 21 42 98 +Card 85: 57 71 21 43 41 23 18 15 59 93 | 40 8 21 25 19 57 52 71 75 45 16 18 89 99 43 20 27 4 53 98 80 22 7 29 41 +Card 86: 84 43 50 94 92 31 48 8 6 91 | 92 53 6 94 25 41 74 54 62 43 95 79 16 31 8 89 84 30 50 91 58 47 17 96 46 +Card 87: 45 96 17 51 25 40 39 13 78 82 | 66 61 23 13 59 10 1 86 30 62 74 41 34 45 8 65 36 16 78 93 20 92 35 82 90 +Card 88: 29 89 14 85 93 19 56 36 99 15 | 91 14 94 89 96 19 85 71 23 46 21 75 92 7 6 33 60 8 72 81 99 36 29 56 22 +Card 89: 77 79 82 96 75 63 72 59 37 11 | 43 97 11 61 80 68 22 19 71 63 16 18 56 49 9 79 45 36 37 89 1 8 48 4 40 +Card 90: 2 81 33 10 60 57 38 99 95 65 | 3 98 33 80 32 65 45 96 99 61 25 73 74 37 91 6 2 79 38 34 97 89 36 11 5 +Card 91: 31 62 73 12 53 51 64 55 9 20 | 45 76 95 42 81 56 32 62 11 48 93 9 69 79 84 28 46 82 88 96 31 91 13 98 92 +Card 92: 64 5 81 2 59 24 40 74 84 58 | 93 43 67 70 53 20 91 18 49 4 14 52 74 19 79 85 61 86 82 57 38 44 34 9 83 +Card 93: 6 94 85 43 15 67 68 79 81 65 | 15 35 14 78 21 68 86 9 97 99 75 87 23 46 70 30 41 27 18 84 3 50 53 63 79 +Card 94: 61 34 62 94 50 23 69 98 78 60 | 43 9 90 28 49 36 19 97 56 75 62 15 79 70 40 78 24 94 48 88 45 91 66 4 34 +Card 95: 73 26 99 83 45 46 9 50 38 14 | 98 81 63 27 55 28 32 82 92 41 87 60 49 50 99 95 11 89 4 78 17 47 20 15 96 +Card 96: 52 80 3 67 69 57 16 34 40 77 | 70 35 97 2 71 25 1 15 54 26 19 5 83 20 4 99 56 38 51 87 53 47 30 13 96 +Card 97: 54 41 65 23 52 82 81 22 28 47 | 27 90 3 24 15 85 36 88 97 37 4 18 42 50 99 35 83 78 79 46 40 63 92 34 67 +Card 98: 47 56 85 60 12 1 35 88 30 86 | 75 83 15 97 66 74 55 62 9 58 19 82 51 54 61 68 47 7 17 10 39 44 20 96 34 +Card 99: 52 25 39 18 92 17 93 29 6 9 | 22 83 86 51 5 43 20 73 13 66 6 82 24 8 2 11 87 79 57 50 19 35 45 62 49 +Card 100: 27 91 93 24 17 47 80 13 51 8 | 59 78 63 74 81 26 98 64 97 79 6 77 54 83 9 86 69 31 12 10 5 56 34 33 60 +Card 101: 8 45 53 15 57 36 69 47 13 1 | 15 13 79 47 69 36 99 57 25 91 1 8 39 73 90 24 84 93 60 40 53 55 3 45 87 +Card 102: 45 76 11 54 1 15 24 60 20 29 | 25 32 88 5 66 40 16 58 24 70 79 36 29 53 54 86 60 15 78 57 27 92 99 33 30 +Card 103: 46 15 97 62 94 19 99 76 42 93 | 65 19 5 58 3 10 12 24 50 64 54 22 85 31 44 93 30 47 14 21 97 78 2 15 81 +Card 104: 61 83 16 66 81 55 52 36 76 95 | 28 51 36 20 11 6 27 33 92 57 94 96 45 9 15 2 63 72 58 44 5 81 43 1 66 +Card 105: 44 12 34 11 26 72 57 55 38 69 | 41 57 62 26 14 72 89 99 34 69 28 10 68 70 2 50 98 37 12 38 44 71 11 80 55 +Card 106: 43 33 65 67 24 17 58 16 94 9 | 51 54 71 14 95 18 42 45 73 97 24 25 92 49 29 83 38 10 30 61 22 79 43 60 65 +Card 107: 74 9 87 65 8 71 6 51 47 79 | 74 5 6 71 65 82 57 88 66 76 70 8 51 87 54 81 96 79 7 9 47 12 24 52 50 +Card 108: 32 87 49 10 41 34 68 79 33 23 | 16 67 63 69 60 37 8 2 47 78 5 9 34 61 10 42 36 95 68 24 75 77 85 56 18 +Card 109: 98 95 89 44 76 63 83 99 71 79 | 49 64 88 18 67 48 23 37 32 99 65 14 1 63 80 84 60 5 87 94 70 8 96 16 35 +Card 110: 73 30 38 99 23 57 68 39 20 45 | 74 9 1 8 35 42 23 24 83 66 76 90 30 56 82 15 6 49 88 45 96 62 43 27 16 +Card 111: 48 62 64 91 57 12 68 30 25 18 | 78 3 21 29 20 77 91 74 72 1 18 28 19 25 44 52 34 12 64 17 6 7 57 5 14 +Card 112: 62 10 63 18 34 55 72 86 12 45 | 82 7 27 95 76 64 11 31 42 38 75 15 69 29 79 20 17 8 16 39 60 24 87 81 9 +Card 113: 91 58 97 55 46 75 74 53 72 2 | 82 7 17 38 89 81 14 24 33 13 11 91 79 93 96 18 2 35 80 15 45 63 41 46 37 +Card 114: 76 22 44 83 99 59 21 67 12 17 | 78 68 63 53 16 29 31 90 70 18 69 9 40 38 32 8 27 85 67 26 62 56 97 35 94 +Card 115: 11 49 95 65 18 67 29 91 45 25 | 37 44 78 20 88 35 32 60 90 40 26 5 68 53 70 31 74 63 21 4 87 46 12 92 91 +Card 116: 50 25 19 90 91 8 80 44 9 38 | 40 47 45 53 99 1 74 65 49 67 16 29 81 70 78 89 42 80 97 76 66 21 24 95 83 +Card 117: 38 7 34 3 57 30 29 44 52 21 | 5 48 70 24 26 50 32 27 1 4 25 96 54 16 90 61 33 67 89 78 83 22 72 6 47 +Card 118: 35 25 23 73 66 57 86 21 27 8 | 9 98 50 78 75 99 83 10 70 97 49 85 14 73 46 29 16 5 60 82 15 45 62 37 3 +Card 119: 51 84 3 55 90 61 93 18 38 35 | 63 50 60 78 87 74 95 58 26 27 34 11 81 30 28 99 94 89 64 1 96 65 72 56 76 +Card 120: 17 74 98 56 54 31 10 26 60 45 | 20 90 98 46 31 15 89 10 94 26 35 69 79 60 58 11 74 77 50 30 64 56 9 45 12 +Card 121: 27 43 12 84 96 70 61 19 92 46 | 59 18 91 25 23 97 32 72 4 21 95 93 85 60 81 9 58 30 53 94 90 69 48 89 2 +Card 122: 88 85 3 82 19 98 72 38 87 93 | 60 3 31 93 51 81 82 23 69 14 72 21 95 45 76 59 86 53 85 73 19 56 61 39 35 +Card 123: 22 6 50 96 91 15 33 7 29 57 | 72 67 62 78 91 96 23 7 17 69 26 29 75 2 57 20 43 74 82 68 56 92 54 66 48 +Card 124: 73 15 66 38 69 4 83 45 70 95 | 19 71 6 5 15 17 95 1 34 3 68 70 42 75 12 46 38 8 83 39 2 16 74 79 36 +Card 125: 32 86 2 71 72 53 73 67 12 85 | 60 31 70 99 33 45 95 22 79 41 25 3 46 5 20 75 37 55 35 18 36 59 8 63 80 +Card 126: 44 96 40 68 25 34 13 72 2 80 | 47 18 77 23 63 80 17 73 3 79 21 15 11 58 54 96 95 62 51 41 75 44 40 24 97 +Card 127: 4 34 21 87 85 1 44 72 71 24 | 72 46 83 10 50 77 87 49 91 85 1 42 66 38 54 89 35 86 59 65 71 15 34 4 99 +Card 128: 24 86 90 74 48 83 88 13 2 38 | 8 16 10 92 76 44 1 59 34 37 80 52 27 70 66 26 22 43 6 84 30 21 60 77 74 +Card 129: 28 71 81 50 31 13 6 63 58 51 | 5 35 62 15 72 47 76 44 32 34 2 14 50 45 77 18 24 81 78 59 48 40 9 7 26 +Card 130: 19 68 83 40 64 99 55 45 17 9 | 22 77 99 80 90 13 88 44 57 26 85 81 15 56 30 54 18 95 6 83 51 55 94 93 73 +Card 131: 47 44 33 5 59 74 1 21 46 3 | 4 14 87 41 82 63 31 45 47 23 55 94 89 39 86 20 52 66 10 59 48 34 68 21 12 +Card 132: 78 15 99 9 40 5 34 75 3 79 | 70 30 80 23 95 66 85 7 43 27 12 83 22 44 21 10 31 14 26 45 68 57 49 94 53 +Card 133: 54 14 80 44 33 11 53 69 1 71 | 64 2 56 28 84 76 26 32 92 3 39 47 69 9 6 75 50 99 95 30 35 73 98 13 59 +Card 134: 58 85 26 9 2 94 59 23 57 52 | 21 39 80 34 50 27 45 76 16 75 54 92 8 66 53 32 17 74 83 13 1 93 99 88 46 +Card 135: 43 81 39 26 61 75 13 40 72 48 | 9 87 61 99 51 81 59 55 19 13 35 74 60 45 39 40 65 33 78 46 26 8 71 7 44 +Card 136: 76 86 15 32 6 81 29 16 22 92 | 88 73 92 50 75 79 82 61 86 41 30 69 18 76 45 15 67 16 29 81 93 65 32 14 6 +Card 137: 37 65 99 6 61 45 27 86 68 84 | 6 7 61 67 65 33 86 64 59 90 96 54 99 23 85 68 18 55 40 4 10 37 97 77 73 +Card 138: 39 80 50 4 53 73 48 54 12 60 | 63 50 72 33 17 11 24 18 54 58 68 7 30 75 22 85 87 40 19 44 69 90 97 43 36 +Card 139: 8 86 87 39 58 56 80 34 85 81 | 25 9 2 26 19 61 96 72 36 45 6 21 91 7 34 89 59 56 87 8 49 98 85 74 97 +Card 140: 19 21 14 84 81 4 62 24 71 77 | 96 14 77 71 38 24 45 51 40 81 5 19 99 57 48 65 72 4 60 62 41 79 87 49 2 +Card 141: 87 32 58 9 88 63 22 71 83 18 | 37 26 51 34 44 22 84 48 58 65 3 62 45 90 60 70 74 81 57 68 18 47 85 73 40 +Card 142: 17 56 69 87 23 26 25 32 49 47 | 65 83 15 63 73 30 93 85 45 27 84 14 58 76 38 33 8 94 61 74 37 36 52 41 78 +Card 143: 52 86 94 23 28 58 81 71 30 21 | 23 96 75 87 55 50 21 76 9 80 97 69 35 33 27 71 86 94 30 42 84 10 3 14 62 +Card 144: 80 8 67 32 42 49 76 93 41 90 | 21 59 34 80 71 37 28 33 9 68 95 31 26 47 73 94 41 13 48 27 96 7 85 17 62 +Card 145: 22 13 74 92 75 17 19 48 58 55 | 36 31 20 92 11 76 23 51 71 84 59 88 89 38 1 90 97 46 30 41 77 6 17 64 2 +Card 146: 51 81 54 87 95 28 30 44 88 85 | 96 1 35 64 45 97 54 84 4 86 40 49 15 28 19 75 10 2 68 60 66 59 12 18 63 +Card 147: 44 45 70 23 71 37 17 59 97 53 | 88 9 26 22 62 68 6 96 77 31 95 50 54 42 14 5 30 24 48 3 67 75 56 49 7 +Card 148: 38 54 1 75 6 24 70 82 74 94 | 23 34 92 5 14 83 45 88 81 21 43 78 87 56 63 36 48 4 51 60 42 25 18 2 35 +Card 149: 11 87 55 57 8 27 48 67 12 45 | 3 37 54 81 2 15 92 30 5 10 38 98 64 93 99 68 36 50 88 97 35 29 79 46 58 +Card 150: 65 89 66 91 37 3 49 19 29 17 | 24 34 69 99 15 58 56 28 90 7 73 75 72 66 77 49 8 17 21 74 84 67 19 29 54 +Card 151: 86 4 93 67 52 14 43 99 9 38 | 34 60 72 47 24 76 38 67 48 85 14 43 93 92 49 45 18 25 86 9 31 99 63 41 4 +Card 152: 79 39 53 12 11 17 27 51 92 5 | 12 79 51 75 92 2 56 39 81 67 17 5 53 55 72 48 60 11 18 27 98 77 6 66 86 +Card 153: 22 95 26 5 32 14 7 66 8 35 | 60 32 96 25 8 57 73 95 74 27 66 26 7 1 14 5 12 34 21 35 22 87 77 24 85 +Card 154: 79 4 94 63 9 96 21 86 59 46 | 52 76 55 94 57 74 46 15 38 83 32 4 9 73 62 43 36 98 89 18 96 45 79 25 35 +Card 155: 53 58 97 98 67 5 8 46 31 54 | 76 5 46 80 30 54 31 33 51 97 47 67 8 83 10 58 60 73 98 71 62 82 48 95 77 +Card 156: 3 1 23 18 71 21 8 79 84 2 | 59 8 18 87 29 14 46 99 61 90 66 21 68 62 2 86 31 88 23 74 38 10 73 7 84 +Card 157: 24 3 22 90 56 15 78 61 1 81 | 33 70 73 5 71 93 30 67 53 18 62 7 19 85 47 65 43 82 69 75 57 46 44 99 50 +Card 158: 2 8 21 71 24 82 47 53 11 25 | 27 25 35 20 3 53 73 96 38 7 65 89 16 78 97 85 74 18 56 49 32 88 59 42 33 +Card 159: 69 81 74 51 35 90 33 58 97 22 | 89 45 91 1 77 10 72 35 31 42 28 71 97 80 87 22 64 33 95 3 68 56 69 82 67 +Card 160: 99 34 53 3 6 48 93 1 42 13 | 50 35 79 89 26 5 91 10 57 63 30 72 64 17 37 40 90 88 78 18 25 95 67 58 14 +Card 161: 41 39 34 75 50 52 94 71 82 13 | 26 8 87 95 20 91 49 96 65 36 51 24 46 69 83 52 47 41 79 11 50 73 89 70 44 +Card 162: 48 87 68 57 81 52 49 60 28 15 | 92 11 94 54 45 39 7 84 93 67 42 64 26 90 6 79 4 3 23 96 41 37 97 24 50 +Card 163: 67 41 11 38 81 56 45 4 76 70 | 32 87 62 51 58 27 91 37 29 90 22 43 77 97 35 46 93 88 23 31 99 21 79 18 47 +Card 164: 2 79 35 21 96 29 22 10 69 99 | 47 91 17 60 20 31 37 81 53 84 16 77 4 46 75 26 78 93 32 76 52 8 27 59 10 +Card 165: 32 37 54 95 66 64 59 19 28 44 | 96 49 3 75 94 63 98 65 4 7 2 73 50 24 78 31 21 42 82 25 70 79 35 38 1 +Card 166: 24 61 72 44 27 38 81 59 69 89 | 85 29 98 3 73 63 25 1 16 96 57 8 78 92 82 20 79 94 71 62 2 49 97 93 99 +Card 167: 55 22 60 95 80 25 28 56 69 18 | 22 38 29 46 90 41 59 93 94 57 74 43 97 49 27 34 19 64 55 81 33 37 13 15 89 +Card 168: 90 51 39 37 67 12 65 14 6 4 | 64 70 6 37 25 26 4 48 43 91 28 90 27 41 87 74 14 39 56 51 9 67 12 65 34 +Card 169: 57 11 25 88 28 82 60 95 27 26 | 42 82 35 47 87 14 11 88 63 96 65 43 95 25 99 5 26 20 28 57 60 40 76 27 7 +Card 170: 31 34 19 29 1 55 20 61 10 94 | 48 77 3 87 91 37 38 57 75 53 12 60 76 45 4 68 13 73 35 7 30 20 6 14 69 +Card 171: 67 10 59 89 52 53 40 17 64 29 | 88 27 59 1 75 10 95 67 34 40 83 4 82 64 2 52 89 29 53 33 8 71 91 85 17 +Card 172: 87 63 66 32 37 96 3 29 88 90 | 96 18 87 17 14 69 58 65 52 31 1 44 37 60 5 32 41 90 7 49 29 66 35 77 82 +Card 173: 70 84 52 81 63 32 61 94 38 97 | 24 34 63 52 81 99 8 57 66 50 94 84 70 38 61 86 15 32 47 78 45 77 95 76 97 +Card 174: 4 74 29 30 24 87 91 92 5 2 | 55 86 5 70 12 94 96 89 58 29 14 62 4 99 48 81 91 45 27 54 31 22 68 43 76 +Card 175: 91 78 3 20 86 98 89 82 13 57 | 24 76 59 66 73 1 5 82 45 6 92 3 33 43 17 83 12 14 91 71 19 46 54 96 25 +Card 176: 12 55 93 3 43 81 28 59 72 76 | 4 90 55 84 69 74 46 45 65 17 26 71 70 21 29 23 61 99 92 44 40 41 51 8 57 +Card 177: 56 5 89 93 62 17 2 6 50 40 | 35 60 5 47 76 92 15 2 34 28 69 29 19 9 27 49 1 88 57 48 84 8 26 59 91 +Card 178: 1 93 34 57 67 58 84 37 42 91 | 42 69 41 34 91 28 75 70 1 93 4 49 66 6 37 38 32 89 46 44 62 81 9 22 73 +Card 179: 90 95 7 29 42 51 22 39 84 75 | 75 25 80 96 55 41 73 43 26 42 46 7 86 22 84 1 39 50 90 12 3 29 51 95 81 +Card 180: 72 76 4 68 9 41 16 44 61 13 | 63 92 39 68 5 13 11 65 50 25 76 55 71 29 82 31 53 59 2 99 74 16 1 90 41 +Card 181: 29 63 61 82 33 94 51 32 50 84 | 80 85 7 8 54 30 87 56 90 75 69 60 25 43 53 47 72 81 1 59 97 28 52 46 10 +Card 182: 98 45 44 32 19 6 51 49 64 84 | 64 20 90 6 4 54 19 80 51 72 69 99 29 44 45 46 84 65 43 53 74 23 42 66 49 +Card 183: 23 35 4 50 88 87 38 7 19 2 | 76 79 80 5 66 30 74 29 37 94 11 50 1 67 13 27 90 40 70 91 71 12 81 9 33 +Card 184: 55 74 2 73 75 22 32 71 67 27 | 92 19 9 24 74 73 8 67 30 18 14 71 77 45 85 72 15 69 13 27 94 63 98 40 93 +Card 185: 14 73 72 38 16 40 83 28 37 96 | 19 74 49 96 90 48 26 1 95 54 3 82 50 41 43 64 69 80 77 97 52 16 23 25 31 +Card 186: 24 91 35 21 16 71 94 95 25 53 | 60 5 17 58 82 35 45 80 28 16 13 53 68 97 86 8 52 61 65 1 27 67 91 43 3 +Card 187: 96 39 77 52 97 33 80 99 18 15 | 48 8 85 79 81 33 43 90 62 14 36 65 2 32 82 15 91 23 34 68 56 87 11 57 73 +Card 188: 8 35 86 95 94 65 26 11 96 31 | 2 98 50 33 59 93 28 49 87 29 79 8 23 6 54 16 82 96 83 61 27 60 53 62 30 +Card 189: 60 27 78 55 84 1 36 28 20 77 | 45 85 75 8 54 74 58 73 17 68 13 53 47 79 7 65 35 40 51 87 18 37 71 72 21 +Card 190: 41 31 39 33 54 42 71 47 59 24 | 21 96 85 12 81 83 64 87 93 77 92 38 25 52 20 88 65 10 29 16 95 98 22 37 15 diff --git a/Day5/Part1.js b/Day5/Part1.js new file mode 100644 index 0000000..6ef470e --- /dev/null +++ b/Day5/Part1.js @@ -0,0 +1,44 @@ +import { readFileSync } from "fs"; +const t0 = performance.now(); + +const categories = readFileSync("input.txt").toString().split("\n\n"); +const seeds = categories[0] + .split(" ") + .slice(1) + .map((e) => parseInt(e)); +const dictionaries = categories.slice(1).map((e) => { + const splits = e.split("\n").filter((e) => e.length > 0); + const name = splits[0].replace(" map:", ""); + const maps = splits.slice(1).map((a) => + a + .split(" ") + .filter((b) => b.length > 0) + .map((c) => parseInt(c)) + ); + const filter = (j) => maps.reduce((a, i) => [...a, i[j]], []); + return { + name, + ranges: { + destination: filter(0), + source: filter(1), + length: filter(2), + }, + }; +}); +const locations = seeds.map((e) => + dictionaries.reduce((a, i, j) => { + const current = j === 0 ? e : a; + return ( + i.ranges.source.reduce((b, p, k) => { + const next = current - p; + const inRange = next >= 0 && next <= i.ranges.length[k]; + return inRange ? i.ranges.destination[k] + next : b; + }, null) ?? current + ); + }, 0) +); +const closest = locations.reduce((a, i) => Math.min(a, i)); +console.log(closest); + +const t1 = performance.now(); +console.log(`Runtime: ${t1 - t0}ms`); diff --git a/Day5/input.txt b/Day5/input.txt new file mode 100644 index 0000000..7cd63b1 --- /dev/null +++ b/Day5/input.txt @@ -0,0 +1,183 @@ +seeds: 629551616 310303897 265998072 58091853 3217788227 563748665 2286940694 820803307 1966060902 108698829 190045874 3206262 4045963015 223661537 1544688274 293696584 1038807941 31756878 1224711373 133647424 + +seed-to-soil map: +3809825462 2725979505 339457863 +3359244708 2085610478 450580754 +652041572 2536191232 189788273 +841829845 3346349446 343599367 +1408035723 73701258 732851393 +2140887116 3689948813 88205018 +0 3778153831 371129494 +2953980724 0 73701258 +3027681982 1754047752 331562726 +2229092134 1029159162 724888590 +1185429212 806552651 222606511 +371129494 3065437368 280912078 + +soil-to-fertilizer map: +201390752 0 263005475 +772560454 263005475 186665885 +3597849741 3228095269 216867970 +959226339 951560560 85171934 +2882237029 3813801625 34286208 +0 586356609 16090261 +1460387186 1189054013 136970257 +2511361703 2581174071 147006778 +201110502 1477157137 280250 +3582774663 3444963239 15075078 +2073881675 2245158204 30510333 +3127914126 3163440286 64654983 +1724767985 602446870 349113690 +1597357443 1036732494 127410542 +1044398273 1164143036 24910977 +635875205 449671360 136685249 +2916523237 2728180849 211390889 +1069309250 1854080268 391077936 +167223128 1820192894 33887374 +4168481019 2454687794 126486277 +3496254979 4048626015 86519684 +2454687794 4238293387 56673909 +2104392008 1648916365 171276529 +3814717711 3460038317 353763308 +464396227 1477437387 171478978 +2658368481 2939571738 223868548 +16090261 1326024270 151132867 +3393107291 4135145699 103147688 +3192569109 3848087833 200538182 + +fertilizer-to-water map: +357701033 441924316 54941059 +2047098412 1574732688 106451110 +2414997091 2961420861 217583761 +3647103220 3202843177 147888878 +1781607871 3397471081 265490541 +433955285 629676938 29320532 +3280739425 2494455782 366363795 +2818710889 1426835569 147897119 +1120892574 3179004622 23838555 +1539573533 3662961622 195295312 +3794992098 1820059317 63264836 +0 84223283 357701033 +1144731129 1702496991 117562326 +2153549522 2046878176 261447569 +593734757 726830618 239035306 +987137385 83279657 943626 +2966608008 0 83279657 +1734868845 3350732055 46739026 +1438972249 2860819577 100601284 +2632580852 2308325745 186130037 +1262293455 965865924 108845646 +412642092 1681183798 21313193 +472462518 1305563330 121272239 +988081011 496865375 132811563 +463275817 2037691475 9186701 +3049887665 1074711570 230851760 +832770063 1883324153 154367322 +1371139101 658997470 67833148 + +water-to-light map: +4062286509 3839153068 91029970 +1610728246 3827168971 11474903 +2753947407 2725849236 1101319735 +2525484879 1829977386 228462528 +657837215 1095779595 241604827 +1895347620 1337384422 492592964 +1425623249 4009599599 185104997 +2446068318 3930183038 79416561 +1894838426 3838643874 509194 +2389619503 896001044 56448815 +3855267142 2058439914 207019367 +1187459420 657837215 238163829 +1622203149 2467395620 172372577 +2387940584 952449859 1678919 +985523081 2265459281 201936339 +4153316479 954128778 141650817 +1794575726 4194704596 100262700 +899442042 2688664470 37184766 +936626808 2639768197 48896273 + +light-to-temperature map: +0 2682471120 43545350 +2829609407 2423668531 227914183 +3685065657 3821208881 65673550 +1319277847 0 33132672 +818263707 3091863377 5216721 +3144636417 670795080 1340457 +1352410519 895535914 570572224 +2709351136 1662268878 120258271 +115643652 2726016470 93054822 +455333494 1538206440 124062438 +3839611769 4030334543 30664857 +3750739207 4258515305 36451991 +2070721515 33132672 155555065 +3132740473 2067641423 5192544 +4147162986 3685065657 58311172 +4278703737 3743376829 16263559 +1070098598 2174489282 249179249 +716608392 2072833967 101655315 +43545350 1466108138 72098302 +3057523590 3016646494 75216883 +2700979566 887164344 8371570 +4205474158 4060999400 73229579 +2226276580 188687737 474702986 +1971879519 1968799427 98841996 +3931845119 4134228979 124286326 +579395932 2819071292 137212460 +3137933017 672135537 6703400 +1062694241 663390723 7404357 +3787191198 3886882431 52420571 +269061216 1782527149 186272278 +1031805835 2651582714 30888406 +823480428 678838937 208325407 +3870276626 3759640388 61568493 +4056131445 3939303002 91031541 +1922982743 3097080098 48896776 +208698474 2956283752 60362742 + +temperature-to-humidity map: +219529182 731674447 232727899 +2748076784 2771987989 46463882 +2514344851 4061235363 233731933 +0 1369964423 219529182 +452257081 362359049 21789881 +4243457964 2720478657 51509332 +3085663754 3109574959 64704581 +1639319644 384148930 347525517 +3150368335 3626166922 251414834 +1986845161 0 139120377 +1382707786 1339581093 30383330 +1413091116 1113352565 226228528 +2794540666 2818451871 291123088 +2125965538 338187591 24171458 +474046962 139120377 157229612 +2361125570 1100881680 12470885 +631276574 296349989 41837602 +3401783169 3428035243 198131679 +3989702261 3174279540 253755703 +2224646236 964402346 136479334 +2150136996 2299087215 74509240 +3806048654 3877581756 183653607 +3599914848 2514344851 206133806 +673114176 1589493605 709593610 + +humidity-to-location map: +4029426902 1202474782 191291587 +2764446301 708692227 493782555 +2188304413 3350514524 33021460 +3318755823 4213528230 67155117 +2000392671 620732246 87959981 +3754724301 3075811923 274702601 +3258228856 1393766369 60526967 +2088352652 4113576469 99951761 +363515622 1849258760 614077493 +1213242541 342257124 11129119 +1733046668 353386243 267346003 +1224371660 4280683347 14283949 +2577070088 2888435710 187376213 +4220718489 2832149614 56286096 +324294413 1810037551 39221209 +3385910940 2463336253 368813361 +977593115 3383535984 235649426 +1238655609 3619185410 494391059 +4277004585 324294413 17962711 +2221325873 1454293336 355744215