From c7b599993c78209d3e5687879ea4463ad7594484 Mon Sep 17 00:00:00 2001 From: Kalle Struik Date: Sat, 3 Dec 2022 16:45:45 +0100 Subject: [PATCH] Day 3 --- input/03.txt | 300 ++++++++++++++++++++++++++++++++++++++++++++++++ src/bin/03_1.rs | 42 +++++++ src/bin/03_2.rs | 43 +++++++ 3 files changed, 385 insertions(+) create mode 100644 input/03.txt create mode 100644 src/bin/03_1.rs create mode 100644 src/bin/03_2.rs diff --git a/input/03.txt b/input/03.txt new file mode 100644 index 0000000..1bba85e --- /dev/null +++ b/input/03.txt @@ -0,0 +1,300 @@ +dWlhclDHdFvDCCDfFq +mGdZBZBwRGjZMFgvTvgtvv +jwwJrzdzGdSbGGnNlzWczHzPHPhn +cczcbMBszhzzDBTBPPPGjtvtlt +LqJLfpwdLnvQLRGQjGtj +gSgnSJJCGSGpGSrwgfhchmmmHzcrHDmbrmMm +bVjstCsSstCLCrbSLnMpdMndcLddcqcpHR +wPZJQJwtBfJZmgBwPTcpTdcnfHMppcGMdG +gmFJzwPJJtszvNhCNC +DmjZDMZWDqGRqqRpHmmRLTTNTPTfCQJQQLJHTClc +FtzfvrfFwVgtzztgBLJNcNlTcTVNNQLN +vgsdbzzrwtqWfWRpZDdZ +rJhqRhLHhdcQqdHqfQGfPGstgGPlWttM +DzCpDDmnNCmBZBZnVBmZzBGPfsbglfNPwgPGPMWsWWft +BZFnlmpBpBzDzVZmhFHFrrrchhRqTdrc +DWCCWFNqdGFdPVcb +HllttQsTRlJlsblrHlhdmPLVcVcTccndLvPLmL +HSlstHgJltghhRrzNBNDzSwMjNZwNb +dzGSHCWSsGVVSdHVHHWWVVDCgJDpQqLTTRJpgmTLRmJTTpTR +BvNjMPZMBtBBMvvNMNttlhLQqCJpLmhTRQqQJgRJLQQg +llNncBlMCwwMnwPZrGsVHzcfFGdHGFGs +JfZhphMMQmFzDTDjSdrQjQ +sqHCbCwBVtbqbCqtrWdjzlSJTlrTSWBn +bHcwbGCGRssNscwtHNbwvm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FdLjbfrrLsSfLNQtMllznBzJQZMQtMlZZnnF +frssSscssNfScCjfSCwjsDmRDpGmDRDvvvVcvRDvRp +LtlPZPjBTbWsWJVJVzdT +nnprqhrqmzfrSrphqfCChVVGVDJWgSHHWgWsRDVHWd +nrmppNqhcCrfMchcMCncqbzPZvlvlwbBNjPjtNjZjL +FPWsFdSspVbbbtWVvl +CCHnnfHHvCwtVMhzlzDllC +LrGnjGfgfvcwfgrLrBjrBLgwdBTSRBFsRZdRsSqFFSFSSPPp +whGCLqsrjgGhhGFqrCCFGCGzTRTZJcNnzlLTnznNHcnzTH +ddvVmbfvdvVbDVQdvvdSzpNcnJzlzSRHNJpnJcSc +BPdvfQdWtPDDPfDvDQVVPmbhssCGGMqgFCFMqGMWgMjrRw +PSLbGmWPSPLQbMTPWGFWltthdDdrmBDHhdDdczzDRh +VfCngVfgsZwCftrZdhcZrdNDzz +CjVJJJqnJwQhWPPLQlGj +ntnnQmTQTQGVWGNGNNlClG +jDffjMSvqjHzHHzwNVwNVcCddPVNdD +ZszJsrrZMjsHqqvZJLRQCbTRQbJmThbt +BgLHgFDsJNWgQgflWd +mnVVcCHnCGRcVnZSjmlthftMQddlfhQctNfW +qbSGqmHSTFprvpvTTL +dvdTMvvpdLpTcSLvdLLMmhfFBftwCNhRwRNjtCTRCf +lshQWgsgrHHqlFfRqFjRFfFwCB +rsgHQbJbrsGHHlgQHgJrlHrPZdhdpMZGDSDpdPLcZhdvhZ diff --git a/src/bin/03_1.rs b/src/bin/03_1.rs new file mode 100644 index 0000000..8e49d2f --- /dev/null +++ b/src/bin/03_1.rs @@ -0,0 +1,42 @@ +use std::{fs, collections::HashSet}; + +use anyhow::Result; +use itertools::Itertools; + + +fn main() -> Result<()> { + let input = fs::read_to_string("input/03.txt")?; + + let lines: Vec<&str> = input + .split("\n") + .filter(|s| *s != "") + .collect::>(); + + let result: i32 = lines + .into_iter() + .map(|s| s.split_at(s.len() / 2)) + .map(|(one, two)| (one.chars().collect::>(), two.chars().collect::>())) + .map(|(one, two)| one.intersection(&two).map(|c| c.clone()).collect_vec()) + .map(sum_priority) + .sum(); + // .for_each(|s| println!("{:?}", s)); + + println!("{:?}", result); + + return Ok(()); +} + +fn sum_priority(entries: Vec) -> i32 { + return entries + .into_iter() + .map(char_to_priority) + .sum(); +} + +fn char_to_priority(c: char) -> i32 { + if c.is_uppercase() { + return c as i32 - 65 + 27; + } else { + return c as i32 - 96; + } +} diff --git a/src/bin/03_2.rs b/src/bin/03_2.rs new file mode 100644 index 0000000..348e7dc --- /dev/null +++ b/src/bin/03_2.rs @@ -0,0 +1,43 @@ +use std::{fs, collections::HashSet}; + +use anyhow::Result; +use itertools::Itertools; + + +fn main() -> Result<()> { + let input = fs::read_to_string("input/03.txt")?; + + let lines: Vec<&str> = input + .split("\n") + .filter(|s| *s != "") + .collect::>(); + + let groups = lines + .into_iter() + .map(|s| s.chars().collect::>()) + .chunks(3); + + let badges = groups + .into_iter() + .map(|g| g.reduce(|acc, e| acc.intersection(&e).cloned().collect()).unwrap()) + .map(|g| g.into_iter().next().unwrap()) + .collect_vec(); + + let result: i32 = badges + .into_iter() + .map(char_to_priority) + .sum(); + + println!("{:?}", result); + + return Ok(()); +} + +fn char_to_priority(c: char) -> i32 { + if c.is_uppercase() { + return c as i32 - 65 + 27; + } else { + return c as i32 - 96; + } +} +