From 4a0a7563235445666c38fd63bff069d85537c4f6 Mon Sep 17 00:00:00 2001 From: Tobias Berger Date: Thu, 27 Apr 2023 11:38:21 +0200 Subject: [PATCH] Rust Day 2 --- rust/Cargo.toml | 4 + rust/src/day02/input.txt | 1000 +++++++++++++++++++++++++++++++ rust/src/day02/main.rs | 56 ++ rust/src/day02/part_1.rs | 30 + rust/src/day02/part_2.rs | 42 ++ rust/src/day02/sample_input.txt | 3 + 6 files changed, 1135 insertions(+) create mode 100644 rust/src/day02/input.txt create mode 100644 rust/src/day02/main.rs create mode 100644 rust/src/day02/part_1.rs create mode 100644 rust/src/day02/part_2.rs create mode 100644 rust/src/day02/sample_input.txt diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 67efdd7..e85cf3a 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -26,3 +26,7 @@ codegen-units = 1 [[bin]] name = "day01" path = "src/day01/main.rs" + +[[bin]] +name = "day02" +path = "src/day02/main.rs" diff --git a/rust/src/day02/input.txt b/rust/src/day02/input.txt new file mode 100644 index 0000000..91aaa4a --- /dev/null +++ b/rust/src/day02/input.txt @@ -0,0 +1,1000 @@ +17-19 p: pwpzpfbrcpppjppbmppp +10-11 b: bbbbbbbbbbbj +17-19 c: ccccccccccfrcctcccjc +8-10 k: kkkkkkkfkkks +13-14 l: lvllvllllslllv +8-9 n: nhhcnnnknnqnb +1-3 d: pdbdfbws +5-6 v: vvvgvb +7-8 x: gxcxtwbl +2-15 r: xlgrwqpcsqtrvfrrt +9-14 l: glnldlllllllln +2-3 r: vxnw +8-9 g: gfggczgkgggjgg +4-5 d: ddddh +6-9 t: zttttbhbttttftd +3-6 k: kkkzwnmv +2-7 w: sgmvplwwjx +11-13 h: hhhvhhhhhhvhh +9-10 f: mhfdfffffmlffsfvts +17-18 l: llllllllllllllllrzl +4-5 c: crcccccccvc +9-12 q: qqqqqpqrqqlcq +7-8 n: nnnnnndn +3-5 f: ffqnfpffhf +3-4 j: djpj +17-18 q: qqqqqqqmqqsqqqqqjq +8-15 j: bjmjbbqfjjrgjgfkjj +2-11 d: xdgdmxgwzdpdxdhjwd +8-9 p: bppppppmp +10-11 t: ttttttttttb +5-8 v: vhxvfcsvvxjvvvpgwdv +9-17 q: mqqqqqqqqqjvqqqqzlq +1-2 t: tptbbn +9-11 q: gqqqqqqfwqqqq +8-9 h: hsdsfkgphxglmsjndhh +2-3 z: mzgz +4-16 n: nxnsqmrnnnpfvnfnb +1-3 r: rbzcrkjrqrrnjxj +1-5 c: ccccccq +4-11 m: mmmgmmmmmmm +8-9 z: zlzvzzzpzz +1-18 h: xzqhmkzhhrtxpljptbc +3-4 p: pbpg +16-20 j: jrfjjzjjjrjjgvjkzjjj +6-9 t: ctdtthtlttttpt +3-4 h: mfhj +5-10 t: tgtxttqhtl +1-3 w: fwgw +6-7 q: qvqlrqp +12-13 m: mmmmmmmmrmmmplm +12-14 r: rrrrhrrrrrrrrbrc +4-6 b: ljzbqgwxcdmdjfbcwd +7-10 g: gggggggmgpg +2-3 c: mbcc +7-8 k: kbkkkktkckc +7-8 p: pppppppbp +5-8 w: twwwwwwgvvwvdttmh +13-17 p: ppppfppppppppppppp +8-12 x: xxxcxxxbjxxxxk +9-18 b: hhbbqcbbbsblbgpwbbhf +6-8 h: hhhhfhhchhjhhch +7-11 g: ggtnwvcdgctkrggxj +5-8 k: kknhndzm +4-5 z: zzznz +2-4 p: pbtp +16-18 r: rrrrtrrrrrrrrrrhrr +15-16 r: rhrrrrrrrrrrrrrx +7-10 l: lllklmhxzlxcdljz +7-8 q: qqpwsqqb +9-13 k: qkknkkxlzkrkkkkkpk +4-8 h: wlrhfbth +6-8 q: vppqqqgntfqqgqq +19-20 g: ggggggggggggggggggfg +4-5 m: shmzmsdm +3-4 k: kkhkk +4-7 b: cbsqkcpnkcfzhmpvfvgz +18-19 l: lllllllnllltdlwgllxl +14-15 z: zztzzzthdzzzzzn +9-10 s: ksssbsssstss +2-10 t: mltjpttttthpttttz +3-9 n: pqnpfxgfnzqxv +7-11 d: ndddddhdddddddd +11-13 v: vkvbwrchzvhhvpc +13-15 l: llllllllllllllll +10-13 c: ccclwbcbccbxvcrdzctc +8-9 w: klvwtwwwbwhww +2-4 j: mnmb +10-14 w: wwwmwwwwwwwwlnwsw +14-17 x: xxxxxxxxxxxxxlxxkxx +3-7 r: bxrqzxsrfmclfdrqrtpf +7-14 b: bbbbqbbbbbbbbbbbbbb +7-13 p: wwvhwdprjxppwnhsbp +2-3 h: hqhh +8-11 n: nnnnnnnjcnn +5-12 l: cwzxlpvwlsfjqrgk +3-5 v: vvphwvv +5-16 d: dpdrdfdrhwdrrqdqxd +14-18 z: zzzzzzzzzzzzzzzzzkzz +2-5 h: hcjlh +12-13 w: wwwwwwwwwbwlw +15-16 c: ccccccccccccccxc +4-7 b: lbbsbbwhb +2-5 z: qtwmzhzmwqw +5-6 d: drjddc +7-9 q: qqqqjqqfdqq +14-15 r: rvrqrrrrrwsrrmrrd +16-17 h: hhhhhhhhhhhhhhhhlh +10-16 f: fvhgfzffchmffgfff +3-7 q: qcqlvdvgrqtqcq +7-9 x: xxsxxrxxpsx +3-10 h: hjhjthhrthcdhhhhxz +15-16 t: tttttttztwbwptjt +3-5 x: xrlxqx +3-4 b: bbbp +1-4 n: jnhnndn +3-6 c: ccccfm +7-8 v: tvtvdvspvvv +6-8 l: lljlllgsglcsw +2-13 h: jhzzcgpxhbgqsbwhf +17-18 j: jjjjjjjjjjjjjjjjhc +2-3 c: ctcchxklnbrqc +3-14 w: wwcwwwwwwwcwww +1-3 k: kcxf +9-14 t: ttttkttlnttmtttt +2-4 x: xkxxqzxvck +5-6 h: dgmxghjxjnhs +4-12 f: fvhlffxnfjhfffqxfcf +1-10 b: pfsbflbbkbqk +8-9 s: qzkfszjss +1-14 m: mmmmmsmmxmqmmmmmmmm +11-13 w: nsgwwwwwwpbwvwww +2-15 t: sprsbpztsznslst +3-4 d: tqscgnrjxrqdwqd +5-17 x: xqrzxxxxfxzxrzxxxw +8-9 m: mkmhmgdmq +6-8 q: qqqqqqqxq +2-5 m: mmmmmf +4-13 v: gvvvsvfmmmvvx +13-16 t: ttttttttgtvtwttntt +8-16 c: ccccccczccccccccc +10-11 b: bbbbbbkbbvbbbbb +1-12 n: pnnnnbnhnnbng +5-6 b: qbbbbb +4-6 z: zzzzzvjzzznxdzx +2-3 p: dwxqpjp +4-6 w: wwwxwq +2-3 x: pvpdh +5-8 n: pqnnkncnnfnnnnnn +10-12 w: drqwwxrwwkwwwswwl +2-4 g: rbggfslgjqqhj +9-19 r: pzxhrcfrrrqjqfkhrhjz +3-6 n: rngtnnnnn +4-14 t: tttttttttttftgttttht +6-8 q: qqdtqqmrgqcqqqqc +3-14 t: tttnttttttttqk +9-10 w: qqwcjzwgjnqdrdxwjwl +10-12 t: tthtthtktvtttt +2-7 v: vzvvvvv +5-17 p: zzpsmpgpprdmhxprsvs +8-9 t: ttttttvnt +4-8 v: vvvfvvvvvvvvvvv +7-15 h: cwkhdzmththzjnh +7-9 v: vjvlwzvvmv +1-2 c: hchw +7-8 f: ffpfffsfqf +5-8 s: xlssskszb +2-15 x: fxzpbvqzmkxvtlljjrg +1-3 s: hsss +7-14 m: xmmtmmmgmrmmxzmxm +10-13 z: dnzztzzzzzfszxzczg +3-8 h: rhthhnhh +6-9 g: hbggggggggbg +13-15 z: zzzzpzbzzzzzfzzz +5-15 l: llllwlllllllllll +3-5 m: dhmmm +2-13 h: hrrhgqhhnhkhhhhb +1-5 p: kpppp +2-13 m: fmqjmrzhskzwdnt +7-8 q: bqxvzqqsjpqqqq +2-13 d: ddhdddddddddbddddd +5-9 s: nhkmxssqsjssjs +2-11 b: vlrtxpzkqwb +6-7 q: qqqqqcq +7-9 n: nnnnnknnmgn +3-9 n: qfkxknwnn +15-16 d: dddddddddddddddgd +12-13 h: hhhhhhhhhjmvhhh +3-4 w: tbfw +8-9 f: fkffbfhtf +2-4 q: qjsqqf +2-11 t: ttttpdgtlxhtx +7-10 k: dkkkkkkkkh +6-7 c: hccccxcgv +6-7 j: sjcbfmj +1-2 w: vtrwjcgndvwx +12-13 m: mmmcmmmmmmmms +3-7 h: hhhhhhw +9-13 g: gghgwgrrkgcgg +12-13 g: gggggggggggfgggg +13-16 s: sssssssfsssssszb +2-17 p: pbpmpmwpnqppppppphbd +2-9 c: cmrcwfnjcdcxccccrzc +8-12 j: jvjjjcjxjjdqjjjr +6-9 m: mgjxmcfdm +2-5 l: klmxlx +2-10 x: jvxwxpxrxx +2-3 r: rrzrp +2-12 v: cbfrnctdmzwvlbvjmdgg +2-9 r: wrbrrrrzm +12-13 h: fhsbhhhhhhhwhhhhhh +5-8 d: ddhqdddddp +4-5 l: djnlnlllbl +2-9 t: tdtgttddtwwj +16-20 t: tttttttttttttttttttt +5-8 z: zzzszzzmszz +8-13 d: dddddddbdzwddd +9-10 z: zzztzzzhzxgz +10-12 p: wppcppxpppgpppzr +4-5 w: wkwtwwzww +3-9 m: dmmmrmmmm +1-4 g: gvmr +8-9 d: frxndpdzwd +17-20 q: qqqqqqnqqqqqqqqqhqqq +7-13 w: pwfwwrwwwkwww +3-5 q: qqpqw +11-13 p: pplpppppppppb +4-12 g: glggjmsggggjrgbgm +3-7 p: cfphqrxpsgthp +12-15 f: gfnrhffgftnbggfwtbp +16-18 p: pppppppppppppppppm +3-4 l: lllzn +1-2 d: dddd +8-12 n: nnnnxnnhnnnn +2-4 z: zzzzz +1-4 s: sssms +2-4 h: hghhh +1-10 l: nhtnzhdtmslxqskf +5-13 j: bpzjjrrqzndjtw +1-2 x: xxchn +1-16 v: vjvrxvdbdnvvkzvg +9-10 b: xbvzbbmfmbqbbvbbrb +8-12 k: ktnkfbgkkkkbkmkk +7-9 h: hhhhhhwhh +16-17 g: sgggmggggggggggvggg +3-10 q: qmlqqqqqqq +11-14 h: hhhxhhhhhchhwkh +9-14 f: kqwqcftkfdxgmsd +12-13 p: pppppppppppph +7-8 f: dkfnjfff +5-6 f: jtfrrfxckhfmfffszggg +6-8 n: jzhpkszn +8-10 c: cccccnckcxmrchjc +14-15 d: dddjdjdddddddpp +8-10 f: cfshmqfffwtffltfzff +3-4 b: bdbq +2-6 b: cfqkbtvmn +15-16 z: zgzzqzjhzzmnzkzvzz +4-6 r: krrrrlm +3-6 c: dcczrfr +8-9 s: ssssssfws +11-12 s: mssssssssssq +1-2 r: zrznpmzrs +10-11 k: kkkkkkkkkfk +3-9 k: kbkkkkgkk +1-4 w: lwwtw +3-4 t: ttkt +2-3 m: htvmjk +2-4 p: mdpp +10-17 s: ssssssssssssssssws +1-2 m: gmmc +5-9 d: dddbvjkdd +5-8 z: tmnfplzz +7-14 s: ssssssssssssstkss +2-7 q: gqbcxnqcvszwbxqkz +6-17 b: btbxlbbbbbbbbbvtbkd +6-9 l: lllllllld +11-12 q: nqqjjrhgxgqp +6-9 n: nlnnfnnjb +13-17 x: xnxxxxxxxxbdbxxrc +5-13 w: wwtwrwzwwwqfwtkwtwbw +5-10 g: gggxbgmgrgggggg +13-16 h: mhhhhmshhchhhhhl +2-3 f: flff +2-4 k: kkhr +2-6 m: mmmqmml +6-7 p: ppppppp +2-6 k: ksktkkk +2-4 m: gkml +5-6 h: hhvqhjz +2-5 h: hkhqhfh +3-4 z: zzglz +2-3 f: zhfn +10-11 m: mmzmmmmmmfmm +3-13 d: ddwzdmmddmddz +1-2 h: hvkhm +4-5 n: nnnnb +5-7 f: fjppbffffz +2-4 g: tmlp +15-16 q: bqfvqqqcptqqzqqx +18-19 g: lpgqgcgsdtngfddbggnp +3-5 z: kjzkq +1-6 q: qjkqqzqq +3-4 m: bpmmjgmmfmj +2-5 k: jkvkz +11-14 q: qqqbjqqqqqgqqq +6-17 q: bfqqtlqqfjgqtqtqs +5-16 s: ssdzfbsdhsszspssvs +1-7 n: nhnvmhb +4-5 b: hbbrk +9-14 f: fffbffkfftcfnfgf +1-3 n: nznxndpb +3-4 k: qkktw +3-8 r: rrprrgrrr +2-5 l: sqmllls +6-7 n: njnknvnnpvlbnx +3-5 t: hbrtmcttt +5-9 j: fjjnjcgjhnkcpqjbc +2-4 l: jllx +7-8 d: dddddndd +3-6 t: gtsttjnt +9-11 m: cbmgjlqcbsmllm +1-2 l: vllfcckl +10-11 p: ppppzppppplp +2-4 m: slzmmrw +3-8 h: bhhgmpbs +7-14 t: tttttthttttttttt +1-3 r: rrvvrrprwrfrcr +5-15 w: gwbhwjwwwkswcsww +2-5 v: zvtls +1-4 v: vsvv +10-15 z: zzzzzzzzzztrjzr +3-5 v: vvvjhdvv +3-12 s: wqssnmdlwlws +2-3 r: djrftptcrskpzrz +1-3 p: nbppgkmfnjp +17-18 w: wwwwwwwwtwwwwwwwrw +2-5 l: xqntklqlt +2-5 g: gtkggghcvgl +18-19 z: zzzzzzgzzzzzzzzzzztz +16-17 x: xxcxxwxxblpxzkfxzj +15-19 f: frffffstcwffccffffff +3-4 n: npnm +2-3 d: zvddd +7-9 x: xzxxctxxl +13-14 s: hhsxbzssdtssfss +4-5 m: vbpmhmrmvrjnmhlsbmm +3-6 z: zzzzzwdzzzzzzzzzz +18-19 g: gggggggggggggggggng +14-15 x: fxxjxxxxxxmxxwxxnxb +10-12 m: xmmmmfmdmmkh +3-4 b: bbgbgb +11-13 c: cclcccbcxcccqcczc +10-17 w: wwwwwwwswwwwwwnwpw +5-7 l: blllqll +4-10 n: nnnnnnnnntn +9-10 z: fzzztzczwzzgkzzn +4-5 x: gxjhxbxxx +3-6 p: plhxppk +10-19 p: mpgpmxdvqphrcckpvqw +3-14 p: kfdwtqxpstpcfpgcfmp +2-6 k: gnxkkkjrzkknskmpbsj +8-10 l: lzllklldplllzl +16-17 n: nnnsnnnnnnnnpnnjnnn +1-14 c: kccccccccgccccc +2-11 s: lsqghkzwsgsbdmgq +6-7 p: pcpgqrcpqpptpm +1-11 h: lhhhhhhhhqhhxbhhfhhh +11-12 r: rrhjrbrrvrrrrdrrr +5-8 c: cccccwck +6-8 w: wwwwwwwb +12-15 n: htvxnnhvnpnnknnhnt +1-2 c: jcct +2-10 v: vsvvvvvvvvv +4-5 x: xhxtx +3-4 f: ffxf +5-8 v: wprmvflppqwvwfwpkq +5-7 n: znnnnnxblcrn +8-9 n: zljnjjbnn +10-11 m: mzwkrvmzrdc +3-7 h: hxkhfhcqhr +6-13 j: vhcmljdxwkqnfcvmjjb +1-6 g: gvgggthkr +6-10 l: bldnllklkllllclslm +6-7 g: gggggng +1-4 x: xxxxxpnsv +15-16 q: qqqqqsqqqqqqqqqbq +6-7 q: qnqqqdqqq +5-6 p: ppppspppp +3-5 k: kkskkk +1-2 j: jrjjjjj +8-9 d: ddpzdlldmddhdhdd +5-8 t: ttsljtnt +2-4 w: qwwmwwhwwwwwwww +6-8 c: clcccccv +1-8 f: ffbfqfpfbfb +5-13 r: rrrrkrrrrrrrrr +15-18 v: vvvvvvvvjvvvvvvvvvvv +7-8 r: xjwxkzqrrxr +7-10 d: kddddddddbddd +1-8 k: kkkkkkkkk +4-6 q: rhdkjsqjqvzqcpsnq +1-2 t: tdtt +5-6 l: lllwlh +3-5 f: pdzfff +7-8 s: qsswssks +3-5 d: dcdddd +1-12 r: rvlrrrwdtkrcxffr +2-7 d: rddcdlqtnffbdd +5-9 t: phmtdzfjtdb +9-12 x: jxxxxxxxxxxcx +14-16 c: fcclccccmcnccwccqccv +4-5 p: zxpzk +15-19 t: ttttttttttttfkttttl +5-10 k: kdmjgkkkkkblkvkkkk +6-15 q: wqgmcqcmcjlgxkqrdstw +6-7 r: rrrrrrr +2-6 n: ksnnnnnzn +16-17 g: ggggggggggggggghgg +11-13 k: nsgkkkkzckxtkn +2-5 q: jqvkqm +2-10 q: lpqqmqlqqqqqtqqw +10-20 k: dkztkkkkshkkkkkkkkdk +4-7 d: fddddxd +3-5 v: vvvvs +7-9 b: bbbbbbrzb +4-14 z: nbnzkbxbwhqpjsdlzz +3-14 x: xxvxxxnxxxxxxxdxktxx +7-9 z: qqpzzxzvsgzfzdzz +14-15 c: ccccccccccccccmc +11-12 k: kkkkkkkkkskv +15-16 d: ddddddddddddddddd +6-8 x: xkjhxwgxxzxxnzwxcxk +2-6 t: tmwttc +7-8 w: jwcwwwql +5-14 d: jdpddtkddrdddpq +9-14 t: mwctmnjxmztckt +4-8 l: llnlxlmjn +3-6 s: sssskvk +4-8 c: ccchcrctczt +4-6 s: wssnlsnsss +8-18 s: sfkssssbswshsvshms +6-7 b: bbkbcffmwblcmp +8-15 w: fwwmswcwwhlwjwvtlq +2-9 n: wnnnnmqhdpsnzn +1-7 x: xkzzxpz +5-8 x: txxxxmlxkrxsxzsx +7-10 t: lchndztdttgk +1-2 q: tqqq +1-9 z: nzzzzzzzz +1-2 l: djfmfwpnjclt +2-6 x: xxxxxmxxs +2-4 p: ppcv +4-10 d: dddpddddddd +8-11 n: nnnnnnnxnnnn +17-18 v: vvvvnvtvvvjvvvvvzzvv +5-8 h: hhhhhhhfhh +9-16 v: vvvvvvvbvvvvsvtq +3-4 r: hrhrrtrgrr +11-17 g: mvgggwggggggwggxw +3-6 r: rrnrrgrrrr +8-10 n: rgjntnrmkn +6-7 f: sffftmm +4-5 b: bbddn +4-9 d: cdrbqddsqqpzkdd +9-17 n: nnnnnnnnrnnnnnnnjn +1-4 n: knnn +15-16 k: kkkhkkkkkkkkkkkv +15-17 v: jkrddvtmgfqvqvvxk +10-16 j: jjjjjjjjgpsjhjjljjj +9-10 d: jdndwddvdrhndddd +5-7 x: bxxxxwmcb +5-7 r: mlrrdsrrrnrgwrrq +14-17 h: hhhlhhhhhhhhhhhhm +1-12 n: zpnwtpnnnnxzm +11-19 k: ccktkhkwthkkklkvhkmk +6-14 s: sfssxsscssgssqhsnssl +17-18 g: ggdgggggggggfgggrggg +4-13 k: dwddvztkhjnzk +17-19 k: kkkkkkkkkkkkkkkkkkx +5-8 q: qmqzqqqqqqqqqcqq +2-4 q: vqqqqhxd +1-13 c: fjccqcmrcjxgccdvbzr +8-12 h: hkhhhhhhhvhhch +4-10 w: jmwfwxwwkwwcnbwwftrc +8-11 f: fffffffbffdf +12-18 b: bbbbbbbbbbbcbbbbbbb +2-8 k: rdwwjvrkcs +13-14 p: pppphpnppppphpppp +1-3 d: nddddddddddd +5-8 m: mmfdkmnfmqm +2-9 x: xjgwxxxxxl +1-2 v: vhvsvv +11-17 r: tlrgrrrrrwrzrrrrsrr +1-7 c: lcclcvgk +3-5 s: slnkss +3-4 w: hqwbw +11-19 l: lfxllllllldlllllllq +4-5 t: tttbt +10-12 g: gggggggggsgfg +6-8 k: kkmkkkkmk +10-11 q: qqqqqqpqqpsqd +5-17 k: pxwkmdxkskthkkkkn +14-16 m: mmmmmmmmmmmmmpmmmmmm +14-15 k: kkkkkkkkkjkkkkt +13-14 c: ccccccdccccccccccccc +1-2 v: gvmqqnkpln +4-6 k: lwkkkjgwkkk +1-12 h: mhhthhghhhhhhhhh +6-7 t: ptxtwtg +3-9 j: zsjkcjlzj +5-8 q: cpzhqfhvsjx +5-11 s: ssbsskssgssdss +4-12 t: ltkttnzdvxttllttt +4-5 j: jjfjh +4-5 r: rrrprjdtrfr +4-8 d: ccwqskmd +2-9 p: npzptdhsxxpkpk +6-17 x: cxnxxpmxxxxhxxfhxxxx +1-7 q: nqqzqnqqqf +15-17 v: vvvvmkvjvwvscvvvv +12-16 d: mddddbdddjddxddbd +3-7 f: fxpfffff +6-7 d: dgdwrddwhprchmvdr +5-17 h: whhphdbxzwcdhhshwkkh +5-7 f: ffffffjw +10-12 s: grcsbsnssbfs +6-10 z: zzzzzrzzzzzjz +14-15 m: kdmmcmmmmmdmldm +6-7 m: mcxmmcmm +5-6 l: lmlllrlw +3-16 q: qqwqqqqcmqqqqqxqbqq +14-16 p: pppzspppppnppbppwwpp +10-12 q: qqqqqqqqqqqqqq +1-5 j: rjkjvjj +3-9 d: fhqwddjrdzpkgdkd +2-4 v: vlvw +1-4 w: qwcww +6-12 r: rhhzkrzhrwrxrkvrcbmr +3-5 t: xxbtr +5-6 x: xxxpxx +2-5 q: qhqqq +8-16 n: nnnnnknnnnnnnnnt +8-10 g: gdzvghxcnbq +4-19 m: rgmmbqmljmzswbkpkcn +8-12 g: ggggggmhggrgbtghg +13-15 t: ttttttttttttttxttt +1-3 n: nntn +3-4 h: hhxh +6-7 f: ffffffbf +2-3 t: bgtt +7-9 n: nnnnnnjnn +2-4 j: ljgj +12-15 c: ccccdcccccccccfccc +4-9 s: wssssssqlcssz +1-2 z: ljzjgcvg +6-7 q: qqqqqqs +1-6 d: xpddgd +4-14 f: ffffffffdzfffmf +13-14 r: rrrrrrrrrrrrwrrr +6-7 r: rrrcgbrrr +9-15 b: lkkbbbbhbsbgxpgpbb +3-4 f: qzfzwnffv +4-14 m: rkksnmbgjmqmmmc +8-13 n: fjnbrnnnqnnnnn +13-17 h: hhhhhhchhhhhhhhhz +8-9 n: rbtknnmpng +1-6 c: qgtfhqtjkw +2-8 m: wzfmmmmmflmdk +5-7 v: cnvvvvvvv +10-15 n: nxnnnjnsnnnnngnnknrt +12-13 d: ddjddddddddddddd +4-5 n: jncnnh +6-10 z: zzzznbzzzczzl +4-5 s: bsjsv +9-11 g: hvkccbpfxkg +1-2 b: bbqb +7-16 l: lllllllllllllllplll +1-5 l: llllml +3-4 f: fmsf +2-4 g: tgshjbgg +2-7 h: vlzzhhhhhphhf +8-9 p: pnpppppqh +9-11 w: wrxlwdtwnwwtqwpwxgw +8-10 m: mmmmmmmnmm +1-5 p: dpnpppzpp +3-5 l: bllflklcmp +11-19 j: jkjjjvmjjjkjljjjjfj +6-9 k: kkkkkkkbkk +2-4 r: njprlsrmtr +9-10 d: dxhdddddfdd +3-8 z: dmrqpzwzghmznc +2-8 r: tlgqwxcrdpj +10-11 z: zzzzzzzzzzhz +1-10 q: qqqqqqqqqsqqqqqqqq +2-4 x: xrwxx +10-11 s: zssssssssfz +3-9 z: rszsgfzzz +6-13 x: zsxwxxqtgxvbcxxbn +10-16 s: smsssgssshsspwxsq +1-2 g: ngqgc +4-8 l: xllllngb +4-7 h: rhhhhhghbm +1-7 v: vqvslhm +2-7 z: jjfmnmz +1-10 v: vvvvvvvvvqv +11-13 g: ggpgrgggggggggg +3-6 p: tpgqnpphpl +1-3 d: sddddd +8-9 g: gggggggvg +2-6 w: wtvwnw +1-4 m: kmmwm +3-4 h: mhvh +1-4 h: cnjhxvhkdch +7-8 w: wwwwwfwww +6-9 r: rlrrrgrrr +2-4 h: lggh +10-11 q: qqqqqqqqqlh +4-5 l: llllgl +13-16 k: kmffmjbzrpprcdkxglk +1-3 f: ffpf +19-20 n: nnnnnnnbnnnnnnnnnnnv +3-7 h: hhpmhjhwdhzhm +1-5 k: hlkkrkzkf +2-4 s: sssxssssssssssssssss +12-13 d: dddgdddddqndtdkd +3-14 c: cccczvcxchccccclctcl +2-5 b: mbgbb +6-8 j: jjtrtbsjnj +5-6 s: sssqsk +8-16 l: lfrlllllctllqxrpllll +6-12 g: grxlwlnggxvg +16-17 j: jjjjjjjjjjjjjjjjp +6-10 q: nqmzqflbhqqb +12-19 j: jjjjjjwjjjjkjjjjjjgt +8-10 s: sscssssssp +11-12 s: ssssssssssds +2-5 n: hswqnqldwwbbmnnrnht +4-7 p: ztpvbqpwsxrgrkp +3-9 h: hhlhhcjrkhwnhq +10-12 k: kkkkkkkkklkwk +14-15 w: wwwwwvwwwwkwwqwnw +16-20 b: bbbbbbbbbbbbbbbhbbbt +2-5 t: tttttftttttt +3-12 l: qswhtwvnfmfwn +11-12 b: bbbbbbbbbjgvbbbbbbz +8-13 w: wwwwtwwvwwwww +5-6 f: kgjfhfffv +7-17 g: qpxgkvgttkhxjhzxnv +2-3 n: rhffpsqknv +2-10 p: pkpppppppppp +3-15 p: rnpqjpgmcpgzkxcppk +12-13 d: nhdddldxdddddndpdddj +14-16 h: hhhhhhhhhhhhhbrhhhhh +4-9 r: rpzrcnrrrlx +2-14 f: ffffzfzffffffjfff +1-9 s: snhfksssxssss +1-14 n: bnnnnnnnnlnnnn +2-3 c: cwtccc +10-12 k: kkkkkkkkcskkkdkk +2-5 r: qrqsrkrk +3-11 k: nlkqkszttxk +2-3 d: vqdgpwnjprgsgsdrxwk +7-12 k: hkkkkkkdkkkrk +6-8 r: smmfvtxrhzvnrj +8-10 l: llrllllllmll +5-10 l: bpwgqlnktt +4-6 f: flfvjfff +13-14 b: bbbbbbbbbbfbqzzb +5-6 m: rmhmqmkmtkmjnmvdx +10-16 j: jtjjjjjjjdkjgjjjj +3-4 c: cpcc +10-11 v: vxgbfvqftvmc +5-12 n: knqlnbhdphpw +7-13 r: rrrrrtrrrrrrrrr +4-7 n: nbnnffkjnwpqnhvqnr +4-13 r: htrkdwrcmcndrxngd +1-8 h: dhhhhjhdxhh +4-8 b: bbbcbbbg +1-7 b: zqpzzqbfbwbwcbbbp +6-7 l: jlhllllmljvl +9-11 w: hwpwlcwkwcwjgkt +14-17 m: mmmmmmmmmmmmmmmmjm +6-11 r: rrrrrbrrrrr +1-6 c: fccxxc +14-15 j: jjkjjjbjjjfjjljfjj +15-17 q: qqqqqqqqvqqjqqqqz +11-14 j: qjjsjjjjjjcjjjj +11-13 m: mfhjhnsshfxmmm +6-9 z: wrsjtzzzj +6-19 b: lbkksbnggbcdpffqjxbb +1-5 w: wwwwwww +3-5 h: htdhh +5-15 n: nlfdnkvknxgbqlw +3-4 z: pzrz +7-9 h: hhslhhkhhhhh +11-13 n: wqnrnbnnlnjnd +15-17 f: ffsfffffffffffbfff +1-2 m: pmmt +8-9 z: zzzzzzzmzz +2-12 q: qqftqqqklxjc +12-13 p: pppppppppppbp +8-9 q: qqqqxqqlqqqqq +3-5 m: mhmfbq +3-5 j: ckpkjjf +7-11 k: kgkkkkkkkkkkkk +2-3 n: pnnnnmmnkl +1-6 l: lnvqjlflmp +3-14 t: nhzvstnltttdftt +2-3 s: hsrscsz +9-12 b: bbdbbbsbbjbgb +1-10 h: mlkcgnrkwhpgwjvflhgx +5-7 p: spnpmppwp +2-3 h: hrhh +8-11 g: fggsggqhgpg +5-8 n: nsxnvnlpnvn +9-11 f: fvffffjfffrcfff +6-9 q: qqqpzqmqpstrk +8-12 v: vmvvvvpzvrvvv +2-4 x: cnbx +3-5 h: hhqrhhh +6-13 t: ttttttttttttltvttt +2-4 v: zqvvgrxwtw +6-8 v: vdbvvfjv +16-19 g: gggggggggggggggjggg +4-6 m: mmwmstmpmj +1-11 b: bnxzhlbbgbpdvp +7-16 n: txfjncnhsxgbjvhh +5-8 m: mmtvmkmvfkmzmpmd +3-6 g: ggjgggg +8-12 l: lslllglqcnlwlll +2-4 l: llpqjdwxq +6-7 b: bbbbbvb +6-12 b: bbbnbbbbbkrq +17-18 s: msfggsssfsrdvssssdr +3-5 m: mmmmb +4-7 g: ggrwgbgggg +5-6 z: zzzzjpz +1-3 l: mrvclxrpvgnrl +11-13 g: gggjgggggggbgg +1-6 q: qqqqqjqqqz +3-5 d: dndnpzdmqcjrdgd +8-11 g: gggggggbggqggggggg +1-7 k: dkkkkkfkkkkkkrk +3-9 p: slbxznfwvjpnj +12-14 t: kbthtttfttrttt +3-6 x: xxbxxkxx +4-5 z: zzzdz +6-13 c: ccbcjccpcnscqc +11-14 x: xxxgmnxxxxfxhx +2-4 b: gjbrwk +3-4 l: bwmlzldj +10-13 d: qdcxdbrdrdddkdnddd +7-9 d: dddflddbwnmddd +12-14 f: rkgdfbdkqhnfsqjltntx +5-14 x: xxxxxxxxxxxxxxx +8-18 r: rrrrrrrlrrrrrrrrrr +1-19 q: qqqqqqqqqqqqqqqqqqdq +7-11 c: kscqhtcccctprbc +3-5 h: dchjkntfhrbmmkkjpnh +2-9 l: lllllllln +1-6 c: sqczzcnkpwrcgvctlrc +6-16 f: wcnppfpffjxpthhfxf +16-17 x: xxxxcxxxrxsfxxpxfq +7-9 q: qqqqqqqqt +4-6 h: hxhhkgg +12-20 v: pwvzsxtvvslvfxhvcvtz +12-17 k: tkkkkkkkcfktknkkkk +2-3 b: bpqr +4-5 m: mhppm +4-9 g: jrgxgqjqgrrpj +7-12 h: hhswhqwhhqhhhlhtkhzw +5-19 l: llllhlllllllllllllll +2-3 n: mqncngfps +6-15 q: qqqqqnhqqqqqqqtqq +1-8 k: kfkkkkkkr +5-10 f: pmpffbdkfpffgffcf +3-8 b: bbsbcbbb +9-12 h: hwhhhxhshhhhhc +1-5 r: nhcrrbrrrj +2-4 q: qqqsq +13-17 h: lrlngvrhpsdmhkhzt +8-17 m: rmmmmmmlmmmmqmsmmqm +4-8 n: njnsnkjkhnkgblg +9-10 d: pdwdkgcdrdzqdd +3-4 p: pppp +10-12 j: zcjjjjqwjrjj +1-9 d: mddgrxsdk +2-4 v: gsvvjv +5-7 h: hhhbbhjh +15-16 w: wwjwwwwwwwwwwwbw +8-10 b: cbczjdpbkhdbkpbztn +7-10 z: skfvjzzxzt +15-16 m: mmmmmmrmjzxmmmbtmmm +2-6 j: rjjgqb +4-16 d: dptndnvddgtpqdddd +7-8 j: jjhjjjbd +2-3 w: bwdr +4-6 g: jgngnmgggfpgcn +2-3 p: ppkp +7-8 m: mmmmmmnm +5-6 l: lfllln +3-4 r: rrrm +6-7 s: ssssssss +4-15 g: kdtgzznwrczjzgx +11-12 w: jhwwrwwpwwwmwwfwgww +13-15 w: wwwwcjjwwwwwgwwwwwf +4-11 f: fffxffffffff +3-7 g: ggggggpg +3-10 m: mmnmmmmmmm +9-11 h: hfhhhqhhhchhhwh +4-5 j: jjqjq +13-14 x: jmxnxbjrklnvxtn +5-6 f: zzkqnzchtfnvffqd +4-8 j: cxcjvfjjkjz +8-14 s: sssssswnrsssscsss +6-12 t: dftrtdvtxttt +3-4 p: ppmp +1-5 z: zzgszfrg +1-8 g: wbgwggdgtswrlllj +2-4 f: fffpf +16-17 t: tttrktsmtmpttttttnt +6-11 m: mqsxmmtfthmfwn +2-3 c: mcbs +1-3 j: xmjj +15-16 j: jtjjjjjjjjjjjjjxj +6-8 k: kkrkktckk +9-11 l: ltlllllsllmlz +17-18 s: sxmssqtjrhmzhssssk +9-13 k: kkkkkkkkkkkkkkkhk +6-9 g: kpnhsggmqklvtttgcxvl +5-7 z: vzrxbmzzwglvczz +4-10 k: khkkdkkckkkkkzkk +2-6 q: qsqqnqq +1-3 x: qxsxxxx +10-14 x: xxzxxtxxxjcxxx +4-6 z: dzzzvz +1-2 c: cccv +9-12 h: hhhhhhhhhhhc +13-15 z: zzgzzzzzzmzzqzzkzz +3-6 h: pgvjdhtpmthbz +10-13 x: mxqbxxwxxxhxfrxxchxx +2-5 b: qbbmpzrzkcjqqwbj +3-14 q: ltxhrqqqqzfqqq +6-10 j: jjjjprjkqj +9-15 c: dsncxxlqwvzccwc +12-16 m: nxrmdgmmxmscmhnm +4-5 p: ppppthp +10-13 d: ddddddddddddb +2-6 x: bxkwbtsx +5-7 j: jjjjqjjjjjj +8-10 d: wzdddddtdddd +6-9 z: dlzzzzzvwz +2-3 h: hhhh +11-13 t: ttttjtttttttxtt +4-5 s: sdbps +2-10 x: dcmxxxlxxhgxftrjbp +9-15 h: hhhhhhhzjzhwhrkhh +2-6 f: ftxhffff +4-5 k: kkfrkwnbkkh +3-5 m: mmdmm +5-10 z: znvxzzldzvhqztr +7-8 r: rrrrrrcr +14-16 k: kkkkkkvkkkkkkbkk +4-10 x: cxsxzxxxxxxxxn +12-13 s: ssssssssssssss +7-9 s: sswssssshs +1-3 c: ncccrc +7-9 r: rrrwrrtwr +13-14 v: vvvvvvvvvvvvnv +4-6 k: bkkkkx +7-10 r: rrrrrrrrrrrrr +7-8 l: llllllzll +3-11 v: vqvvmnkvvswgkqvmvd +8-10 c: cccccdcccm +1-9 s: sssksqsshsj +5-8 c: cccchmcccc +5-6 h: hsqhhghrhk +4-5 z: czzzrzlzn +2-4 f: fzfffj +14-17 p: pppppppppppppppmpp +4-5 x: ldqxq +12-16 g: gtgggggggggpgggggt +13-14 v: zfbmrhphzmrvqv +6-10 p: ppppppppphppkp +10-12 l: xlllklllllkwlcl +4-6 v: qvbvgdw +6-12 q: qqqsqlqqqqqq +3-5 s: rssgpssnb +1-2 g: gzlpcmbsmgrq +2-9 w: lpmbmfvpwggfvmzmmw +4-6 n: nqtfzz +3-4 f: fftf +13-17 n: nnnznkgmnnnnpnngnfn +8-10 p: ppppxppppppppprppsp +10-12 g: ggnggkggggcvg +3-8 l: lxrcbjnddcbpg +6-7 q: qkjqfqqdkkkqrqqqc +5-8 p: wpbpmpwpfsblpplmpp +2-7 n: bbrtwnhhttntqhnr +1-2 p: pcdxzjwmnkfjkpbj +1-15 n: nnnnnnnnnnnnnnznn +18-20 s: ssmsssssssssssssrssw +1-12 h: vhxhmhhhhhhhd +3-7 r: qkkvhvr +3-5 k: xkpkkkzbtwkv +2-4 z: zfzz +1-2 t: ktttt +2-3 p: pbwp +2-4 j: ljjj +14-15 t: pzpcktthttfttttt +3-4 n: nwnj +8-10 l: lzllllllln +1-12 q: qqqqqqqqqqqqq +6-12 z: xxltbzrpwzzmw +15-16 q: qqqqqqqqqqqvqqqjq +4-5 r: rhmrkrd +7-10 r: rrrrrrlrrrrrr +16-18 t: ttttwttttttttttttn +9-17 m: bmmmmmmzmmpmmhmrw +9-13 r: rrxfrrxrrrrrrr +13-18 p: ppdxprpqppbpppprpz +5-8 p: rprmpfpxgjphfktszplp +5-7 h: hhhhhhnh +3-7 h: rwhpshznhhh +9-10 x: xwxzbrxxgxrxxdxxs +6-7 h: hvhhhhng +5-6 b: bbbbwhbb +4-5 g: gbgggg +3-9 g: gsbggghggpgdgg +1-3 r: rxrhh +3-4 c: rccn +4-8 z: zpzzznzzzwz +14-17 b: bbbbbbbbbbbbbbbbbzb +2-4 w: rwvwrdn +3-6 p: pfpsgp +2-12 p: zpwkjpppbppjrppknh +5-9 t: tmttgtttn +2-3 v: wvvcv +3-5 h: bnbhhtjhk +15-17 f: tffwftdskgfxgfffpk +16-17 h: hphhhhdhhhhhxhhhrhh +7-8 d: ddddddtnd +9-20 t: tqttttttttttttttbttw +1-11 v: vxcgzvvvkrlqvg +2-6 r: ghrbwrtfksqkxx +8-10 w: wwwswwwmvwww +4-10 m: mqmmmtmmfq +2-3 g: gkgtgv +9-11 w: wwwwsqwwpwwxrwww +3-4 w: zwxwtcscwmwmndcw +8-9 q: xsqqqqzxfqfv +2-4 w: wwhh +9-18 d: ddddddhddddddddddq +3-4 s: sssjsvs +15-16 p: wphpxpppppppppppppvp +10-12 t: qftttqhtvttt +1-2 b: vbfxqgbzrktjm +3-4 k: lkkr +9-11 d: dddddkdqdttddd +9-11 m: mwngbfmhmcvwx +2-5 b: scbxbb +6-9 z: zzzzzzzzzzz +1-3 z: zzvhz +5-7 x: xxxxxxkxx +1-5 s: ssscshss +1-7 s: csrfvfsqjss +16-17 k: fwdkkkckkkkrrkkck +3-4 h: hhhs +4-8 w: wwwswwwx +1-10 f: fffskffsdfcfvfff +7-15 r: rrrrrrrrrrrrrrxr +1-2 k: kvxbzdcnsqrskhmx +2-4 s: wbvsfs +2-7 q: rbgqpqdq +15-16 f: fffffffffffffffq +1-3 c: bccpkm +5-11 g: fsvgthpglgg +3-5 f: ffffwf +5-16 j: djmwqfxsbzwjdwtj +3-4 p: pprpp +5-6 n: nhnnwj +8-12 s: tssssssrsssksss +5-8 p: pppppppppppp +10-15 w: wgfwwcwtmwwgwpwwh +12-15 l: lllllllllllplll +1-8 c: ccccqccd +3-4 z: zzzvzkzgc +2-10 h: swwbtfkvfhrjztdzx +2-7 z: zhbzkzlzz +2-9 q: ddqdqpkcjqkfgqtcjqq +9-10 l: lllmllkltlll +2-3 n: ngwn +2-3 r: rrnr +5-10 n: ltnnnknnvcnnn +7-9 p: jtpptpllpj +2-5 s: slssssszssssssss +16-17 d: dddddddddddddddlp +2-5 q: bbwqqbkmdhqmjhn +7-10 m: qmpgmmsmmmmkmmkj +4-7 g: vczggdgbgxgg \ No newline at end of file diff --git a/rust/src/day02/main.rs b/rust/src/day02/main.rs new file mode 100644 index 0000000..3fec5f9 --- /dev/null +++ b/rust/src/day02/main.rs @@ -0,0 +1,56 @@ +const INPUT: &str = include_str!("input.txt"); + +mod part_1; +use part_1::part_1; +mod part_2; +use part_2::part_2; + +use std::str::FromStr; + +#[derive(Debug)] +pub struct ParseError(String); +#[derive(Debug)] +pub struct Password { + pub first_num: usize, + pub second_num: usize, + pub letter: char, + pub password: String, +} + +impl FromStr for Password { + type Err = ParseError; + + fn from_str(line: &str) -> Result { + let parts = line.split(" ").collect::>(); + + if parts.len() != 3 { + return Err(ParseError(line.into())); + } + let mut nums_iter = parts[0].split('-').map(|s| s.parse().unwrap()); + let first_num = nums_iter.next().unwrap(); + let second_num = nums_iter.next().unwrap(); + + let letter = parts[1].chars().nth(0).unwrap(); + let password = parts[2].into(); + + Ok(Password { + first_num, + second_num, + letter, + password, + }) + } +} + +pub fn parse_input(input: &'static str) -> Vec { + input + .lines() + .map(|line| Password::from_str(line).unwrap()) + .collect() +} + +pub fn main() { + let input = parse_input(INPUT); + part_1(&input); + part_2(&input); +} diff --git a/rust/src/day02/part_1.rs b/rust/src/day02/part_1.rs new file mode 100644 index 0000000..6a361e4 --- /dev/null +++ b/rust/src/day02/part_1.rs @@ -0,0 +1,30 @@ +pub(crate) fn part_1(input: &[crate::Password]) -> usize { + input.iter().fold(0, |acc, password| { + let num_letters = password + .password + .chars() + .filter(|&char| char == password.letter) + .count(); + dbg!(password, num_letters); + if num_letters >= password.first_num && num_letters <= password.second_num { + acc + 1 + } else { + acc + } + }) +} + +#[cfg(test)] +mod tests { + const SAMPLE_INPUT: &str = include_str!("sample_input.txt"); + + #[test] + fn test_with_sample_solution() { + assert_eq!(super::part_1(&crate::parse_input(SAMPLE_INPUT)), 2); + } + + #[test] + fn test_with_solution() { + assert_eq!(super::part_1(&crate::parse_input(crate::INPUT)), 620); + } +} diff --git a/rust/src/day02/part_2.rs b/rust/src/day02/part_2.rs new file mode 100644 index 0000000..0aa58cd --- /dev/null +++ b/rust/src/day02/part_2.rs @@ -0,0 +1,42 @@ +pub(crate) fn part_2(input: &[crate::Password]) -> usize { + input.iter().fold(0, |acc, password| { + let first_char = password + .password + .chars() + .nth(password.first_num - 1) // 1-indexed + .unwrap_or_default(); + let second_char = password + .password + .chars() + .nth(password.second_num - 1) // 1-indexed + .unwrap_or_default(); + dbg!( + &password.password, + password.letter, + password.first_num, + first_char, + password.second_num, + second_char + ); + if (password.letter == first_char) != (password.letter == second_char) { + acc + 1 + } else { + acc + } + }) +} + +#[cfg(test)] +mod tests { + const SAMPLE_INPUT: &str = include_str!("sample_input.txt"); + + #[test] + fn test_with_sample_solution() { + assert_eq!(super::part_2(&crate::parse_input(SAMPLE_INPUT)), 1); + } + + #[test] + fn test_with_solution() { + assert_eq!(super::part_2(&crate::parse_input(crate::INPUT)), 727); + } +} diff --git a/rust/src/day02/sample_input.txt b/rust/src/day02/sample_input.txt new file mode 100644 index 0000000..2eab335 --- /dev/null +++ b/rust/src/day02/sample_input.txt @@ -0,0 +1,3 @@ +1-3 a: abcde +1-3 b: cdefg +2-9 c: ccccccccc \ No newline at end of file