diff --git a/day_1/.gitignore b/day_1/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/day_1/.gitignore @@ -0,0 +1 @@ +/target diff --git a/day_1/Cargo.lock b/day_1/Cargo.lock new file mode 100644 index 0000000..865acc3 --- /dev/null +++ b/day_1/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "day_1" +version = "1.0.0" diff --git a/day_1/Cargo.toml b/day_1/Cargo.toml new file mode 100644 index 0000000..4ee878a --- /dev/null +++ b/day_1/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "day_1" +version = "1.0.0" +edition = "2021" + +[dependencies] diff --git a/day_1/README.md b/day_1/README.md new file mode 100644 index 0000000..b1d2802 --- /dev/null +++ b/day_1/README.md @@ -0,0 +1,72 @@ +# - Day 1: Trebuchet?! - + +Source: + +## Getting Started + +### Prerequisites + +[Rust](https://www.rust-lang.org/) v1.74.0 + +### Run + +```sh +cargo run +``` + +## Instructions + +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](https://adventofcode.com/2015/day/1) ("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](https://en.wikipedia.org/wiki/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: + +```txt +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? + +To begin, [get your puzzle input](./input.txt). + +Your puzzle answer was `55130`. + +**The first half of this puzzle is complete! It provides one gold star: `*`.** + +### 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: + +```txt +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?** + +Your puzzle answer was `54985`. + +**Both parts of this puzzle are complete! They provide two gold stars: `**`.** diff --git a/day_1/input.txt b/day_1/input.txt new file mode 100644 index 0000000..bf41e23 --- /dev/null +++ b/day_1/input.txt @@ -0,0 +1,1000 @@ +eighttkbtzjz6nineeight +5knjbxgvhktvfcq89onefive +hnjcrxeightonejnlvm4hstmcsevensix +trsdgcxcseven39dpmzs +oneninesixtwo26 +dppthreeh32twobhrqzks +1cxklgfbvhsnccfive4 +foursgjsevenseven5five19 +nrrk87 +63ntkjbvcv3ntdcptmvheight78 +7xv3one +3tzjcrfbvhtqctfmqmdcbjhxln9eightnqbcqztmxcthree +sevensszlgdrlrhnptonethree3qvrxkbgfxtthree +3nckzkpkjsvztqkgvm99 +fourthreeonesevencqdv2gnvblhr +528ksdcbx +six342 +3twozrfrtljql9eightgcqrgmbzz7dlcr5 +6five2threesevenone65 +4onejrg23sevensxfive +fourthreecszzvhzfsevensix916 +spqzvdxxjeightninejzbpzone7 +cfivesevensix332lfpcffmld +ninesevenhrdvmzj24bcxxz6 +khpn3fourvhqmntjxfhsvrlnvc +bfzxhzftwo2czsrv +mmblpnnineseven4gtfvqscghfour +1zjgqlz +five1ninetjjtfxqpdkgrxtgxrcsevenkfdzlh +s8twoned +8fiveone53nineeightthree7 +926xrfcjzvpd7 +3sevenqnzjsqh6fnssjdsbv3nine +rjbbsevenvzkghzsixsbjchs59 +221fsnxtbstone1 +seven9fourpdseven1four2eight +two1nine4nine7 +9seven7 +fourcjmdgjsfive2l +twokvhrdldggn15twoxfivenine +mmjtldgmvq157hchsnvpbjvrvtvnineeight +cgzeight3sjmhdcvlnthree5vkgfmx +8sevenfourgnxdpp62xx5 +jgdk3z7mmkkjkm +9xrdltttpqznsljbvcdvtz +62zthreethree6 +sjbxq9ptsvjhpzmxfoureightmdbnlsckfqlqr +91xrnsbxxsvk6brxfftpttsevencszfhsnrfive +two9ljdfskpfive +1seven384 +xbfkhfvlts8dhtnxhxgn93three7one1 +3xkjrnqnqhgcfgjvfmxhghp15 +nine9844 +5onepczqjfcgfrbmtstbqbktphkvqcmbbvhpld +eightsixhnsbnine1twonevrs +eightcmbm2zbxsixone34 +five99qccjbklfivevqskhpxzd +seven9four2kzkjbrp +ttdbhd4gqzdlqldnm +9cqcztfourrsfskdjf +njttzmcrchfd4 +r414tzqnfddrbf +4tzbfcjksjsn7eightonelvkjzkch +ls7four +6eightsixrtkcrcbmqq6eight3nine +onesix5five7six1 +dvrqseven5ninegqthree4two9 +fourgdkmbrlgc8 +three7nine +sixqrpzqvxd7xnbkftn5seven +oneonerbpgk5ljpqh5threevtpkpfxtsv2 +ljttxthreefour3three4gxzgsfm +sixttjvhdggbk357 +eightlb4 +fourtwo4twonekzb +8one2cdsnrbfxbsixztcfour1 +ldveight19lg +seventpd84dscfmxj +one34flpg6eight76 +cfninepkscscc5 +flqv5v6twooneprlprlkcbk +qsqlrvmkq5457ninetwosevenm +xlvvtxgspct4gmrgeight +hpbbkqthree4gzbq768five +5dqfsixeightonenine +seven4nfshmhvgqm4 +rhfgvzxtfckbtmxtt9rqms9one +3gsgfbrnkhqrjddvlx59four2jfz +fdl4two +9sevennine158 +five9eight49 +3mfsixnkxdbpdxqdgfdqnk +six9fivefive +fourjdmvlvkrp5seventhreejnqncmktwonev +8cjfqkkgtzlnine +3nnsevenjdbjfp1 +ghthree1mhgtklfqdkqthree7seven4 +4mqsstftj +sixprblqsevendsxvqnk5 +four45one +dxhvj23188xz4 +dcmnr2 +xfoneightsixnine6fiveseven +6cxbbxkrxphsix +5ckkzlzjngvssfx +223zgb +six4qsf +hfxgsfhfhpjlvb329eightone +9zjkckhxoneightbnj +xsdp23seven3four7 +8five53eightthreenljbtgcnfive +fnjn36 +eightkpkxrvssix2lhctc +6ninebqcksevensevenhk +2one98rrtlncrxhllbgthreelgvkdf +sixzdnlfrvvd4 +lltjs8sixqbblmfdhctwo +6twonclq98sscjn +six3niners7eightwokjj +sixeighttwo1onerxrvvbfxxqmxnq9 +conetfpbsrm81sixsgkfqk8six +jbqs5277 +kjbncjlqthxzlznld89bgqgkxfzpqsptwo +onefive1 +pchlnspk52one4sgqj +zd3 +43fsfplhgxtjthree7gs4npllqvll +eight8sixeightone6onexr +six6hqltskzpkgbggjktlzlpktdqhzdbnine9 +eightnpfbmfninevgpjsleightxh3mz +rninenine7nine +fourbbjnjrbzdvshfeight62 +3hzpfsfsdm +2vzhjbv6 +27bpninejhbcjrmz7zfqf4 +ppflreightpmztvhvonetnjmrxdd31one +threeseven7 +srf5hcxvhsmn5five +onersvqvqgkfiveeightqxgrjgfcqj5ntgdzxp3zxdcmbsjqn +mcb643fivetwo +onermbkvmkc9pfvlpdhkzj +3oneeight64 +qtnptg5two36nine2tprkbtb +15lbhtcqfnj1qgjk +eightkzrnlrrnlltdmxlbxfourpbpghtgkb9nvlvsm +26kmmkz +jhnldxdtpseven46oneightnb +4lfftjtbzvppxsix17nxpgvjkxd +vszsbxdzjfourhlxldrthdzpqg6slnj8four +nineone2njsfpcb +5sevenone6five +jrmdhdvrb53onelgvlkd29seven +qqqg7eightseven +sevenm9 +3dfcfcdb9twoqbvxjgt56six +xq88jjmv83pspctxthree +38five5 +six7rbrvjb +eightlvqn335nine +rgmfflzxzd9hs3foureight5 +qm6qvmrone4 +fournine8 +two688qqdtdfbmzn5 +8joneonefourljvbjntkngtskcgfnszpgxt +ninethree5pjzcvntl984five +mfgqzcjbglx7 +ninemxnfcqrbjonek1nineggj +8dcfkfdtwo +4cltttbrlzpgzbdbqsevendtwosspqk +8eight9klmcbninetwozdcznsv +six85pjqldfbqvclntpnqgv +1dgprzx53 +4sixthreeh3fjqpggtjzq +fourone8fiveseven4kgbs7 +seven64npxthreeonefour +xvntvgxv9twotlgcsbgsix4 +hcqtdzthfour2xvqmnmgrncjt51 +qhlpksvnntjq8 +3rtmfngqccktwovpppqfqdlxmk2 +sixfoureight9tqpdln3eightbjnqfldblnine +eight2sixthree +3plpm +6two3two2 +1cfszpnxgtk5fivefive8one +lxrdvls2 +sevenfqszrfhone5dxcqsq +42 +3dmpsix9nhgzhbmknfour19oneightlng +six2dfglxszbjone +eightone88 +9hffzxl7five4 +seven8fknjk +fivefoursevenllljzrvjf7 +eightmsxfkbszh2 +6fiveqhkttbsthreefghn4 +3eight98vsnzbkvzcjfive +spmzsdztzgcfbhvbzqlv5 +fourtwozlsst9sevenjjmbmqk4 +jtmlgrjcpkone2twockgc5four +one35five4 +four8tltpxqfour +57sevenbmhceightbhttrzxfvt +qlvrrlnxgvjgnine1four2two +sixoneseven3sevenm +fivejxfghfp81two +rkp3zbzfnrrqfour4eight +eightnine7tpflkbqpz +28fourlmxlhdzctxkrsix +2fiveeightnineninexhfourseven7 +mnlrszkr18tfive7l +3eight639 +gqpbkntddpeight22lxqjqqone +txxrdbx4bvsfxd +343nsctfvndmp93four2 +9lqjvtjcrrtthree +bsffrmtwo2fivesix +qltdtgl3eighttwo91mjq +rh4rddsfr +fourfive7seven +pbqmx7twoqdk +6onesixclklzfzsq992 +kzxkxvqzjffourdtm4onefive6xoneightsnl +k4snine4three39 +sevenone2xcnscqhcdplnonekcxmgt +seven7ninepmeighthqr8 +xpspdx3twoqpc3881 +5two5four8eightfive +sevenseven2bcbsf +1sevenrjstpdxfiveseven +2zsxfivefivesix43 +eightone5j99nhvbfqhzbvrv5 +onefive35m +2kfnqftkkcxtskj +twoeight8 +1one8bzzsmgvj2kmqcnqjrz4 +1one4sixsixbzbcglm +fiveqqhbmnjgz5ninerlrxkl2seven +4eight4two1xgkb91fdzgxlp +nine8onefive5scxlfrf +gbrqllhnine9 +1fouronesixfiveseven95 +7qjrprpseightshfzfxvn +2vkbbxfrthreenineeight +58three4 +lmfsgdzxnqfdbxtjsnp9 +zlbqglfseventprsqvsmt1one9 +fmksmtlc8dvhbtdvpfgdz +3six1 +mkdthree67jkprftqhdzvjxxftthree8 +bstlpptcfghsrrnine7bz +5m1qfscxncvkqgtf +62four16threeoneightg +twoxlrhpc8n9nine +q5sixfour +ninesix2ninepzvxxlpcbxsfpz28hxtccfzmdq +sevenccq4npgpkkb +k79four9fp +ssqptjqvld1pjfdjnkvsevenkjdzks +2bgpbgqfournine614 +16threeeightwot +five68jnhzdfqp2qlqbmnjmjdtfbj +vplnzg4545seven +two3two +zcbhzsvc68cnppjpqhfl5 +nine68seventwo8pfzgfzbsh +onethreethreeknngnmzhpmlnsd7 +46two +sixhdg748blmlkbdtjbtwobgpzzlhzqrbvl +2smcthmql84seveneighthnmdkmfg +5fourrpscd3 +sppzzjbckgsixone1sixfour +ltkzb3v3ltwo +four61nineeightdkgtcjfvds +eightd5nfcvvdxhkkddhb +four6q7thbpnz +5rknhshlhgnzz7sixone1six +327rkthreesixeight +cnbqtvptwo1qnsevenpzqh +threeqthreepmhgcqhseven2sevenggmpjcldz +ninedlvlgnglqf3 +4two993ninetwo +eightzpfournine72oneseven7 +ninejdfkznz62kflbvgpblcgchpzz +448 +6rktvxxjpfpqtntbsonefive +6lngttwodshgtworkvvsrnfhjmvpvvbseven +eight43gpssneight +6seven3threefourninesevenrnxx +three22rblfvqjr1four5six6 +xtdsqqbv43cxxvfpvtwoklhnqgjlkrrg +threevpvxgddmhl576 +3cxccdsevenmvzhqvpfn3btldbhbmfg +kklcmgptl931threenineeight +vj42ntvkrcjtq7sk6 +llsvqthreefive5 +xspgshknq3kpld2lfour6mhzrzvqf +4bfl38onesix9 +seven1vjzjmcrrvnh +7sixsevensix +gqnkgzmvpsnnzcvldlftrzhnpcbq6hzvbqbmnqvsix +5jvbldxsh +jrmvplfive7mfpbsmklzfivefivelsm +8seven5nppxjfjsevenbxrmzmdjnine +seveneightnrkconeqgjfkxjr532 +m9seven7 +vdn5hdghzvphfour +cpceightwo3 +sixtdxhninesevenmmzrpdqcp24 +tghjrkhltwojgrcnnbbq1 +cfrqlvsevengkthnsbtwo4twovffpv5six +two6pcxj4eightgbctk71 +five93nrqpshmxpbdnzssb2 +jnxjdzm2xcfhnzkxxz948twonejv +sixfive4four5nkdxzvd +twoqvnxzgcg883fivejgvltjq4 +7mzsqvrxlf6kpfjgvdpvj +tzhkjn813six7 +5qjbtklseven +rddmfnjgdlnkx5fourzkxlttqdfourrrjfdd +qtr2qrrqvhrkvmtqgbkdq +five56ninesschfzxone +lkb3 +3zmbbqdqqnineeightlvlfqqxleighttloneightv +7threetwofive168 +njxgnsqcpnine2 +zthreerfnvvone7 +three4one8 +8ppmjj983seveneight9 +p4 +8tshsgmkb516three6four +7seven8 +twosixthreenine6three +gvqz9 +n89ninethreesix8 +ptqrhhvztxsjbxfour81lncqpkjt +8flvhqljqpmlf6fivenine28 +zhbsl7seightwoczd +four1pspgxdvtbzdcd7vsbkzmt +fourj9sdnqtwotwonine3ftzrbzckqk +1fourkkfnndsdxnklrl +zpcdvrszc4ggjcpngkqeight +6twonxhgzcsrgxtwosixvblddxgfmsmqtfcthree +6pltsptthreefive5jjqtzncslmxrmbv7 +sixfourqfxtfour9onefivehsgdvpmdsfive +ksevensevenonebdxdxffive5threeeight +zztvdjzlnqtbrfccctsknppmx5seventhree9 +soneight716 +1fqnntfjhcj2threekmcpzqnbzlqps +twopcftkx8twofourcsixfour +8six2sixgxzzhpkv +four9nine4tgq +htfmtchrx634four5zsmkmdv +45dltlvdvv +dtl848three36 +nine7sixonetwo8vsix +twobxctmqvdnt96mnljbpxtsptjpznrjctgtwooneightqv +peightwosixeightseven4 +1seven8ds4five6pone +zjftdkvpkpfrhzj97nine56 +4sdcdr53beightwocjc +onezxmtfive7ttbbttjeighttwo +rlcjone3sixonezvbmzcgpk4eightwotnm +5ddmcsfzhntpnzntlllthreevqvct +twoeight9 +tfhmxsbf2foursqrrfourmfrzjffive6 +dhhnlbkjmfourthree6 +dxtkbxjlphpqcbmhpdfpqlmreight775bh +sixklvmtjgsevennine33qgvplfourb +gkjmcxsmhtwopkcszlrjd1onesevenseven +8xxvzzqvzszcn1onevmdfsrrtbbjgeighttgpmhh +eightpndprhrf7 +three7fpxtxghx +fivenssevengrrlntzldl87 +484sixjsxcmmtvbftrfive +t8onesevenvqsfc2k +sevenoneoneeightsevenfive71 +sevennvnvbtzsnqggrsrgq35sevenfive7 +feightfive12 +twoc846cf +1mtvlxhhxlsdbphgltlgzpl +xddrlslrdl9 +fiveqvfjvcqlcfour27 +9fjqp9rrkqbtpv3 +23fqccxsvsix94tkzsqmrhsg +6lvrsqnz +9four7hvlfl9 +gbgsnmkrxjxpgnj828 +56grzmb6onekf9six +87bjn4 +sjdzmqkrlkbsmxzsmn3 +seven91eightsix +svhfnxzdzqczc2 +vbnz92chjjfqftxfourqzzxseven +seventwofour5jbqvlmqknbznfbhtonefour +dqdmntkfsnbmjqxxgmkvm6vqpgpnnreight +one1431 +1five4 +twoone8thtxlrrdxbone +qftpltmjd1zpxckthreeeight +9xg +pjpdjrkltnrkkmd9five75rdctppdhjtghrffczdx +mtvbhnpzjfive7nine +thlzdgxcqvsknczrdslsh7 +eighteight4kkt7four5 +71ninekzfntxtjthreeone3 +gzseven2fssqrgmbj +52j +nsv16seven +stwone1 +twodbqgfivegsrrvxvone3 +jckhqbdlvgbgn7vtx3vggrdm +ntzftfhfeighteight2 +48eight6 +flzfqonezvskbf1668one6 +sevensix864eightfour3 +dnsdrsxvcxnsevengxrszqxfnd4fmnine +tjjngfourhdfzpfkh24 +foursmgvlqjxsqmz8ninekthktdhz +three435 +tkfqhpz8zjmcqbxcb46 +mmvstlmln3kxnkvjcmxtrdxp4seven +rmfour13vkgnnmbzbzgd +three6nnbljchmzthreeg +68onep9five1one2 +rbvzvgmkbmdrnmvone7kqtxtrtbone +three13six4 +qksfrmvgztsfournnvp66nine +34three +11fourpzkmqnfmjqkdgrlgqbsixsixcqtgdggbdx +nineone2seven4twoninesix +ninez6qpnnbpmcdhcr +sixbdbkhgntpsevencpn3 +1fivehvlrzpninemkfbfgtvfivesix3 +7kpeightzlvqsgkfjznpfpfsseven66 +c7hxrgkglfivebfctxk +5rfdxgshzmnzqscpqzlbnrhbg9strxdthree8kntkhdpdll +4gfzcjcjsm63fvxpvflv +nine8526 +6scslfpnrveight1seven5bdllknjj +seven94hnxddjv26s +two48seven3four58four +fourseven1smh5 +1zzdzmbjpjfzlhsvzgxf61gvtnklgx6 +ninefour63 +nine3nrfzn +gthreeseventwonine1eights +sdonejzdmtxtpl9onerzztvqr8 +eight15kqnjrggpblhsbdz1 +lkkxnzjrgsixsixthreeeighteight4twonem +d17two44 +6seveneight1fourthreesevenbdpvg +cjgchvhq4386five8 +1threefive426rsxmthree8 +sixnztppjtn9twossfjrdkzkrldztfbbv +threesevenlqrdmvzdcphmqj3four5three +fivethreepcfxdxmc3vdbprghd5sevenszprlbzrbn +threethree88xcgdmrcssevenrlflv39 +eightonezchscllpfone9 +zreight6sevennine +fmrhqrxr7 +sixnlqccjchpxpqg86five5 +sdpxjrxtk4sevenfivetmddbpqgtqffive2 +hrvrgjgvxt7vrsr +2zj8 +35fourspthreeseven3zgddrmbxmsz +four8kkxmtsscf +4six98 +five9four +four5one7pjbninefourbmss +4sixsixt138seven +fourxsevenseveneighthsgmmpdx5 +tonexhgcjxbjn8 +chbkd2183 +six8fivefourglszgngfgqthree +pghkzrftwo6 +fourpfx572 +62zfvzp +sixsixnzvtxdgsixzxsgmpz1zvtwo4oneightpg +425twothreebv4twoxbx +8nineeight55eightflkpggltsr4spl +seven45clkrkrxj +65six594twofive +4ktvpfjeight +nnslpmkqc5five5four +nineonetzmft8jcxqzrk +fivefivethree99 +2l2 +4mhdj +3eight7fivejqhvrszgh3 +5four7mbfz8 +one8sevenmltbgqcbq22 +1zgfnfvt9seven +2lhbfrndhmfiveone +fivekzgch424zbpgxhtkbjdljxkxvnz +1vd6vpmzjmnhhn +vlqcbhskb5onerqbql6 +six3tplqcxthreethreefoureightzldgvgxrthree +4fourtwo4 +cvznvxbxlszjpxvzbqn7gt2fjtxddzmjv +kjqthree67twosixfour4nine +dmjrhflfzslhkjmthreemfgqvzcpm9bcnfbpz +nfpcsevenone3two58 +eight4kdqczz96five1four +1mzfour +57tdcmtmns4 +bdxeightrjvkrddrm3nftmzxlftthree +2three2kvfourgrtvxmrzgdninecseven +threemxpfnthree5onehjdxfntvtzlxhr +8onelqtjpkmtwotwoseven91 +rzhzg1fouronecqkdpfkgdkkftsixhllvphvtjv +vxgrlptk48one14two +kqncz3znmkppxs3hlggbmsfj81 +ddrp3 +three8hjdccgthrtbd6lvhnbfivemzh +twomptzvkqmssix7bjvpsix6nine +phrdjxmzj3xxkmfour7dsix +5threeshtmlsjbmfzgdq +96eight +three6rqqxgzthreejphvs +69seven52kmnpbqmjdhtjvxcnlxfgldbs +veightwozbbcmqrdxv6hxxpdknf +nxbtwone1vktdvlbbhnfour +4five864 +2dn1fiveeightthree +two4twofoureight43 +1eight51 +71fourhjrnqssxqvf +sevenqxkccdxndfgqhctsfsx6 +xqgsjvdmnb31sixfourtksqshz5 +4ghkqfzxceighteight2eightfiveeightwotf +ninelsnldgslfxfqfsrc24six +3seven3ctbf9eightmshd +mbqpfourfive44sixbnmqrmkgxt +flgdrvjj4dks +oneqslfbjgfx8 +jmmssm2 +hjfbzsix1 +bvjdxseven8 +fivenhfccvg9 +four5sevengkvslppponerhlvfms +b9one +89znlhgbnkmmxsix3two +sixsqtjcdfbs87ninejvznvmeightfvst1 +sevenktnzdkcsrzzdqtb9jnbtwotgxsptxcd5 +6mqvbhsddnmb21sixskg8 +threenb2four74five1lcmdzrvq +ftvone7 +5msevenpdqgzncvzxeight +foursixpshnbrpm64 +six2twotwordzf +nine7lbnxsfjtbb1seven4ggt4 +zlnfkkconept36 +9sevenfqlxjmts94xpcxqseven +foursevenseven15ninedqff1kmzfgvnks +xktjdhb115 +threeeightcnlpzrb8 +91six +376kkgmlblrcbthree7jgxvgfcdv +9xpz3 +rrcvpkgtwo2one6vjfone24 +sevenhfour3three +pxfvzltqrg9twotwogqdtzbp +lrgseveneight5pmxvppjdhtwoone +97six +four8bjdhpmszdeightprkgone +mb6lfcdkcn +8fbvxnjone +z9vdthreethreesbsrkzgnsxp8 +sevengftjmm1onegqhpninesnr3 +f4fourrbbngrdm37five +ninerbmdqfvkfx9eightone8eight2 +rxdvclfr714 +oneggchmt2dgh7 +tvbfour9four +four474fourgmdtm +nffourpbxtlcs7ninethree3 +bpjlrztwo2sdttcghc +hfflhmdc18 +4ninepsrmtbqrfeightk3xxxf +433hdvcggkr1xjcntvtnvsc +7nine2nine6 +9zctwo +9vvfjvctgtzpjh7jtdjcrh +qrtgcd5six31khd5 +fourbjshrq845zg +ghconeight35jljdqgtg4fjdtxtsfiveone4 +one7kxscgcxnsx +43threethree54four +vmninetwo2onetqgblrsgcpfkrreightwokg +threefour38 +fivesixeights26three +jtmzzxvmxone2four9jgtxjrvpcthree +fdqgczkq8sevenvcnhpseven8three88 +7ninezone3 +frj4eighttwobgx1threesjckzsvvxlone +oneseven2cspzhqfsix4 +ljmnbbcnxffkmdn5 +tmzlnl8oneseven86ninelbrzjgqn +fthree3seven6sixtwo34 +6two8fivexteight +89seven5twosix63 +63pzsjcjzvbhseven +msqvppsgnfbjrjmdrrhbfxrjqdlkpfourjbrjks3dthree +eight6twoklkdfgvxzteighttctqz +4gjpfmqs233six +onefourninenxcnkgfour8rmmrzln +1sptlpstqb6eightqgfhzzgpgp24 +eightlrjlhqfoureightjvj937 +595oneighthpt +44five +two2sevenbtwo +7fivefivepxonebbrlthreefive +klxnlfjlsrgjcd7eightninefive +threeqzpptnzhjnkqfsixpvk3xxlrpl +mqkhsdtbqqzgjb7149ninesix +1dbrrvjsx34cbdxhqpzbfhtgpm9three +3onesix6eight +five34 +6qcv9nzngtsjv +9lttthreegttzjstt +four47 +95onetwoftdzmhsfmhbnblnine +chcsqhnp72qjdqtjxzc8fourfourfour +fourfive28 +81eighttwoqdjkmnleightdbmzz +vzzqpjx8 +qq1six +qbktqgrjcqq75 +772 +njvnhnzdz6threefivetwonelt +pcfzzjfhqkxhfpztpv7 +fivemztfourqjrtngrkpcbfc3qq +bfjhbm6ghtdpsmlvb86eight +94883 +6onegbxmcqmdfive +sevenonesixcngsrgcz9 +sevenzhxktd22fourgnr9 +tdxpzvggnlpdxxrcpsp3threexjrldrkmp +34kjtbsxppmxfoursixlbzgqxbltv +fivethreezfive2 +7seven1seven +4fhvxbg58eighteightone +631gqtwosix +xqn1chrcjjrqxp4threezjcd +jtssvppxlnsix49rfvjdzntwoone +sevencmpmdnczcfdprgfdbjnzzkgnine26 +hkbnggqfk7mfmfsone68sxpdmf +fourtlhsmksvzg4foursixseven +pprkj3sixseven +kzxjpdczxhxckxtgbbtwothreethree5dztmdfrlfivedgcfmmrt +hjvrdhnckspl5eight3three9 +74two95eightfourdkzzlkxszm +one7tbfour1cpjtrxsqgvbjtpbcct2 +fivefour4hsix8hjsxrmpqqxnkhmjseven +nine8fivehvmnxsfour7four75 +sjfrjr2ds +fivefourqt95vbndnzns665 +sixssbznthreethree6f8lnzcgpprl +ninepfbpfnflrfnpzhq9 +nh9fvrldpkjmq7six5p +75zsixnqbhrcbpmddshjfqthtq +sevennine377fourfrtvpqrseven6 +97eightnine +52fiveonetrq5 +threehgjqt7rvfsljtzkfour +tjkxc1 +jthreerqbpzpzmeightntjlrhdmfour2 +fourmgv2three4one +four91 +9bone +oneseven1sevenpdvdqhlq +xlhbqxcpfp7 +twothreefive43 +1ctjmfn9one2 +htfivesixcdkjrjbr45eightseven +onefour8rrhltfl897 +37ljvmcnjhonevxkqpjk +3891sevencfgjhh45 +twoone5tbznkdmv1fourpltvnnsvk19 +55bcnzbfggd2 +17zpskbgeight2dx3 +vbdshtdkxllttwo65 +tzvmcmltfphztpplrxjxpbnine3qvktlctfrpxncb +1sixppzlfvkbnm +eight1gdvlzrfkc +four74fivefseven +hlzlvnjrp9312jxeightnine1 +sixsevenkjpbz5sevencksb2 +9rtvlgdpfnmgzdzcjggsq7sevendxglftncmbninefive +eight8gxkrbkgcvbxbbxlonefivesevenjnffhjsk +99twobdmcnfthreevr +sevenlpjbbthree58 +eightthree32 +14fhxsqshmjbngrhdzvxvvhxgvqnlxnnvrsgsheightninenine +6twotwo +kr573eightseven78 +9six18 +2seven8six1qdvf +ones9three1lcqj2 +sixbfour6gbd +tfpvtbbjtwormxz6 +49eighttwoonesixeighteight +fcrhntggdvseventhreeeight9foureightxjxqvtb +oneone3rnngppxj8fzpsncjmzn +9fiveonejjdpthreetwo9 +sixsixjzckvmbbszsl1nrrfphj5 +zgjvnttth7sbmtxczggxbbqpzq467 +3mhslltk +9six16three79three +fxprlhbm3zljzd49gdsrtt +6eightoneseveneightfourrfive +fourfive11six +6gmrfxnsmnnljf8ninenlctx +seven5threehninecnhbkgbnvqbsfx +pxzccjqz8 +xgzpzljnfour7threethrxskjlz9 +fourseveneight292eightone +5bjpzjseven21four +xbtf88nine +6nfjllxh4 +67five4c8 +1qbzdkvmlrzgj3rzqczz4 +mjjzblg3 +x3five +jrpxsrqgr9hqsddmscmsrsbhkdc63eightxfscd +6eightsixone +5dggfbgclz7htvpcx1 +onethree46psdlfpgbsix +lqbnine978 +7nrrdzfksbtjlnbgfxttzfourstqkd +mtfptwo9six23hctpbrxtbx +eightfznvmmp7cllpkggknttwoxbbv +rggdrlsgcm2hdljxzjhjrfour83 +vhtmhvjdzzkzmzqgr7fourfourfourgzbqqpz +dfjctmlnkqzzjhhltpvhfmhsixvclfive7vgm9 +nine642sevenseven9mblrhxxktfhdhbcztvx +4rzrdfmtvlpthree86 +qkdoneighttwo1one3 +dnnvkvpcmn2cltbzc6five59s +sixsnzpnfplrn38hthhbfive4 +tsrxkzfxcdgckxrgzkmrctqvrngfnvdscnpc6jgszldglnhsg +vvtfhtgxjbdgznjjzqjjclfg1lvpdcpjsevenseven3 +xrhbrpg8zb8 +4nine5qfxlhmvzsjsbznmklseven +lffl2six733jtrfrs3 +7nbvpkdpzjtc8qckhbqfsqqgz +cfljnthreecninedt2xldzbgl5six +nrggf7four +hbkpxrxonetwo969fivethreegspmzcfr +jjpmzlzfvqbvbzqcz2eightninepfqjkjrkfivebzcthgrpqx +xsccsbmcninefive4kkrvrht +sgnzzschtwotwofzjt9seven +8tworpzncglnmninenjmf368 +2one1zjtgllvsone +7nine4nqqxnvvnsbsevenvddcvfdr +three117 +shcjhvrfourpthree12 +1zxcxninegpdfrfhzlbzg +7eight9gkkfbdhplnmjkksbqzp6htmbhg +sixeight76sixfive +5twonemt +three86 +4three52psgzhnlhgvgcsbzbleight5oneightkj +cnztwone1 +six9sgx +79clrpmeightninepkh39 +rmfplpsixsixlvrdbqgpljgl5onetwo3 +7ninelznqjxjgtwohhk6five +1659two7onefive +rskpnrmfbbghttvklkg773fourczdqeight +xftwo4 +2nine5ccrgsmfcseven9seven52 +8sixseven +k33threehgqtljcdqxkl +hfgdvngttzfivecflmcc31three +eightninethreensjxxlzhgk9b51x +ninejktfhnnphkkgm2dms5dpxrbcd +eight7skzllgxgmkd1three4thhdpsjtvnq +7ninehhhdngbxjvvxldvbrhzrbvntl2 +pxgsixone75llslx +31tgrvtvvlbhnshjfgnqc +knzgkjfckf2sevendfive +bmxcnznineeight9dvkbngzmxz +gzqdjfsxq9pbseven +212 +h3 +9sixfourbrfsfivekttxzhrmdsppps +3vxtbtrzqzxfhgsksbvqd +9lbxdjmckrhfgjqlnsrrfzqxktqkrmmjshfnine +7pjmmxdcffxgspeightgpdcftjtdxjgdrfthree +t84ninefive4 +fgfour63sevendmtrrc9 +64three +btjnc3g6f3one +pm9 +threefourvjmsx5four +14one2rtcccqc +jhcckpv84xntpzdn +rpjrhgddzfvrzpqnfg5twoseven3threehvcmnkreightwotl +74one +six4ninesnbxlonesix5three +kfxjzjone76xppxgddstgfhxphpffrjlone +sixthreedsdccpqff4 +4951 +zszgqjxbx7 +three4pqqvfzf622 +vc77threetd +sixlbglxqhn52 +1sgktgvxp +bdsonekxsevenpgssslcq3fgp7 +pvnxnhdjmndnhthreefive49 +kgvkszsixone4 +3mjvqjpglzhphg67ninehnnine +one6xvvnvkxp4dfcxv +eightfour7threesevenp +7ggdl1 +ztwonethree427ninetnmzntj4 +fttwone258seventwotwo +75sixseven59 +7kmfzqgjpqkpdhthjlseven674xdgmphfk +eighttwo6five7 +3eightwoxg +22434five +khjmcpzvfpr9 +3rrzqzlrljgcvdnxj6four8six +63qrgqklszpgthreefkpzx +574htclbtzfivetwo +jtwofqfpkflzt9 +xnjzxpmmdln4lzlmlk41 +6jdzjjmz7jt7seven8fourkgttztbsktwoneps +72s166zpslq5 +3553lhkdcxvhqbddrfdbc5two +4gktbmone +fouronefives3qhglmzttwoeightone +one87rxkkhfrjfrpdjjt485 +one437nine +119one +5lseven87nmxxqvhmn +pphfmcfhxlsevensqdmtvtpvq1 +18eightfivefour +three98 +4onephzhtq4qc5four +26zglkpjvz3twoeight +7mxkdrbpnk29 +ppeight15 +9jnprvtmscsixbbpsixfivecktgvdpf5 +lbftvcngvkvxf5cmmrqljjb471 +eight3knrvtwo +one6pvbpkqkpdsixbv +eight2onethree6eight +5rztcbtfjkb2twoeight39hxppvpxqg +8threemlllncmfourthree +vhtsmncssixbmlpggvmlzdxbczgc1fxrgvsbhsrbs +ninebnpv7575three +4mthree +fourtwo1qrbfourjrjmlxjr +3jbkcsrqznc8 +pcgrxgf4eight54 +seven5mjk +ninenine6vmcmlxmcrbvq1nine8 +sixone2ninesixrdqfgpxddzthreetcheight +899lfbzhgn151 +46nineone +7one2qthree +nine2hjnfourninesixvblnqbgctwoeight +qkggsnnthrxnrccbgs583 +351zkxqtmbd9sixthreegjjxt +zrchlhmqcthreeninesmxz9 +219fivejrxgbjvvcxkjtwoseven +8threebzzsxdx +nine249ninefmlhj8rfour +16zfljhfdcmkthree +7sixjvdqgpvhmndpmhhzsphceight +two2zjqc4nfd6732 +41threeseven1fourseven +296fourgnq7three +tbzdhbhs7ntshptcgrbkjspjdz +55qcrmclmcck9 +25mhmtb3dscmjbhgv3four +bjmhkxsffourhnxkxv1 +jvntlbn5fivegjdcjl +7gndbbbneight +357623chktvtfzvf +169plhsshseven +nhgsrxcdfktpbzf9vpppxzkznine9 +xrdnlbmtdeightone3threeeighttwo +bnnqzcfoneeight2hhdfkrrqzt +342tlmjgtfcnine +47rvtfqlzgmjlqbqthree +7gnmxplrjbvfour6 +mcgbldbhlh1eightnine +two9eightxnpdj61kzcdpnpnpfgsdrbcflh +6541fourpkdplksnkpvkjxpdnvfttlfdflz +kfour7 +x4tpbnnvnjlseven +55nineninesevenzttsztwo9nlcqjq +1drhjrzsbvpl +mpknzhj9vmqckrpznqthreesj9 +211zqgpdlmpn +4jxzrztg5onehnzvdbtcqdtsnkqtdvsd1fournine +bvcrcz5four4 +4nineninecfhgtdphone9 +zbkjgbshqqkrcb3qmtfmdrdcckcsxshjb2 +1eightrblhbhljvkpshmrxc5 +hjcrrdsvnbqktxrgmq9nqgcztbv +6lzsixl5one +twofivesevenfivesixonenine5seven +fourmldkgnzb8djlsdmjnzxbmmvpf59seven +8hnfkknnsrhm +three2krtqmmxqzs4jbrnrtrxzxsllblbkjmthcrlxxkdlh +mglfmvvnthreefour1 +onehxz4fourhqcfvdlhg +zrzqdgs5jsttkrone +sevenrdmhnldsmdnineqfrgjhmhnnqkztxzm7 +63seven +2seven3mrsltqb17 +fdbtvthmmrb5gbxvcmtwosixt5five +eightlzglvxfone5five7dlqpmseven5 +dmzdkbfive98onefivehhbljrnz +eight8ninefour +24nvmftwofive +seven3onefourrmgkxtcsfour +fgpxmqqsfdrk8eight8zhcrzvrzmdxbbfive +eightonetwo7ninesjsrlr +rrkrrtnkq941sixone +threeffspgv3eightfivesix5 +lthnrlgfcnine2scdcvnineseven +sx86 +cxklrckbz5lsqq28 +5seven298 +933five5cmddfj46 +hrhhs76343 +one3two4fourst4three +nine3three +dhtscvgm9foureight81vp +btpeightpzbtphdlcm8fiverknbrhthreelxndqcv +one96six45tm +fourninetkdrvnbznnine22 +vxeightwothree5cd3jcnine +seven5one4one7ninefive3 +nflkr2dlmtsrkrgkfvsixxvznjbvz3btxkhhqcc +eightrtz6jslqxsixoneeightnine +xmvxn5 +tgnlrmjtkjdpbnpmsixbxfnl7sixone +htwonezcshpqgsix73qlgdqnkjskjthree +nrlkxq6fnfourseven +zmrlngjdhc41four4fourptrhddthreenhzv +n9twogdrzkcsbk8hph6 +436sevens7cnkrrk +6qkdvkhtwo +mztkszm39 +fourtwo4mqhjkkdzgffhqfktwonine +hbthree2hvpbznlgrxfgkthfour8 +34prfzlx4three +29zzfdvghll9three6 +two83 +one982 +36hhgdf7 +seven6ninednnine9mbtzfm1 +one38 +seventhree5lsjxknqtdsbtxrkone +eightmfctkbc9jlxgdnchlq9one8nine +p371b +9ninejszqsnpkfbthree1h5xscpfzvl +three9ljd +fbbv9 +five582 +58dctdbhbninesixczhd +qp4 +6pfqdeight +3onethreekqnnlt +m4fgbmdtwo3 +twodkrmtqs4 +9three6 +six1798nineeightsqpvpsmcbmh +9qxxmrmbnine3fivefourfive3four +one7sevenone78ninetwozqps +973keight9seventwo +keightwothreethreeh6threeeightlnqdzhlt +five94 +mqlltnfive8eighttwoqhztggvqqkcxgvgmch +2kpnsevenfive6 +gtmszpsjmggr3 +pm126one3 +rvcqbtz9zjtndbxlrdcxzf3 +mkninekhmtxzbjpd8threeeight7eight +5274xm636 +bleightfive9vdddzjdntthreerxtvdslrvbcvf +9eight4sixdqzrltgpzlpxtcrzxbhmsmdtwothree +cpneightwofive3fourtwo +one61threejxbjvsltxzpntpv +19581 +six2qllhlxhr1foursixz8 +6278teight3three +8gstxqdngxzlxvnvphlsznr3kknftvzxcqqbrfteightthree +4jlzjvjfltwo7pv +7dvt +blhsm4xcrbrf68ninezvhhtqgphnzxlhl +9dvjvfourtcthree +onethreenfkgrvsevenkczctlgkt7 diff --git a/day_1/input_example_1.txt b/day_1/input_example_1.txt new file mode 100644 index 0000000..7bbc69a --- /dev/null +++ b/day_1/input_example_1.txt @@ -0,0 +1,4 @@ +1abc2 +pqr3stu8vwx +a1b2c3d4e5f +treb7uchet diff --git a/day_1/input_example_2.txt b/day_1/input_example_2.txt new file mode 100644 index 0000000..41aa89c --- /dev/null +++ b/day_1/input_example_2.txt @@ -0,0 +1,7 @@ +two1nine +eightwothree +abcone2threexyz +xtwone3four +4nineeightseven2 +zoneight234 +7pqrstsixteen diff --git a/day_1/src/main.rs b/day_1/src/main.rs new file mode 100644 index 0000000..c50a888 --- /dev/null +++ b/day_1/src/main.rs @@ -0,0 +1,78 @@ +fn part_1(input: &str) -> i32 { + input + .lines() + .map(|line| { + let characters_digits = line + .chars() + .filter(|&character| character.is_ascii_digit()) + .collect::>(); + + let first_digit = characters_digits.first().unwrap_or(&'0').to_owned(); + let last_digit = characters_digits.last().unwrap_or(&'0').to_owned(); + let number = format!("{}{}", first_digit, last_digit); + let number: i32 = number.parse().expect("Should parse as a number."); + number + }) + .sum() +} + +fn part_2(input: &str) -> i32 { + let numbers_spelled_out_with_letters = [ + "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", + ]; + + input + .lines() + .map(|line| { + let mut characters_digits: Vec = vec![]; + let mut temporary = String::from(""); + for character in line.chars() { + temporary += &character.to_string(); + + let mut temporary_spelled_number_index = None; + for (index, spelled_number) in numbers_spelled_out_with_letters.iter().enumerate() { + if temporary.contains(spelled_number) { + temporary_spelled_number_index = Some(index); + break; + } + } + if let Some(temporary_spelled_number_index) = temporary_spelled_number_index { + let number = temporary_spelled_number_index + 1; + characters_digits.push( + number + .to_string() + .chars() + .next() + .expect("Number should be single-character digit."), + ); + temporary = character.to_string(); + } + + if character.is_ascii_digit() { + characters_digits.push(character); + temporary = String::from(""); + } + } + + let first_digit = characters_digits.first().unwrap_or(&'0').to_owned(); + let last_digit = characters_digits.last().unwrap_or(&'0').to_owned(); + let number = format!("{}{}", first_digit, last_digit); + let number: i32 = number.parse().expect("Should parse as a number."); + number + }) + .sum() +} + +fn main() { + let input_example1 = include_str!("../input_example_1.txt"); + let input_example2 = include_str!("../input_example_2.txt"); + let input = include_str!("../input.txt"); + + println!("Answer Part 1 (example1): {}", part_1(input_example1)); + println!("Answer Part 1 (example2): {}", part_1(input_example2)); + println!("Answer Part 1: {}", part_1(input)); + + println!("Answer Part 2 (example1): {}", part_2(input_example1)); + println!("Answer Part 2 (example2): {}", part_2(input_example2)); + println!("Answer Part 2: {}", part_2(input)); +}