From 14b02942821c5d2ee2946d5e08a9e1f6adb7a676 Mon Sep 17 00:00:00 2001 From: Andrew Coleman Date: Mon, 5 Dec 2022 09:19:26 -0500 Subject: [PATCH] day 3 solution --- 2022/day3.txt | 300 ++++++++++++++++++++++++++++++++++++++++++ 2022/src/days/day3.rs | 60 +++++++++ 2022/src/days/mod.rs | 1 + 2022/src/main.rs | 5 +- 2022/tests/day3.txt | 6 + 5 files changed, 371 insertions(+), 1 deletion(-) create mode 100644 2022/day3.txt create mode 100644 2022/src/days/day3.rs create mode 100644 2022/tests/day3.txt diff --git a/2022/day3.txt b/2022/day3.txt new file mode 100644 index 0000000..1bba85e --- /dev/null +++ b/2022/day3.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 +JfZhphMMQmFzDTDjS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CmTsdWdHTd +vPvmTGgDPRvGpDPGPqGHQnWJQJMBBzJBlBQWlHWl +bfbwNsmwFdLjbfrrLsSfLNQtMllznBzJQZMQtMlZZnnF +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/2022/src/days/day3.rs b/2022/src/days/day3.rs new file mode 100644 index 0000000..c8f417f --- /dev/null +++ b/2022/src/days/day3.rs @@ -0,0 +1,60 @@ +use anyhow::Result; +use std::fs; +use std::collections::HashSet; + +fn get_priority(t: &char) -> u32 { + if t.is_ascii_uppercase() { + *t as u32 - 65 + 27 + } else if t.is_ascii_lowercase() { + *t as u32 - 96 + } else { + 0 + } +} + +pub fn run() -> Result<()> { + let file_contents = fs::read_to_string("day3.txt")?; + let lines = file_contents.lines(); + let mut rucksacks: Vec = Vec::with_capacity(1000); + let mut rucksacks2: Vec = Vec::with_capacity(1000); + + for line in lines { + let len = line.len(); + let mid = len / 2; + let left = line[0..mid].chars(); + let right = line[mid..len].chars(); + let leftmap: HashSet = HashSet::from_iter(left); + let rightmap: HashSet = HashSet::from_iter(right); + for dupe in leftmap.intersection(&rightmap) { + rucksacks.push(get_priority(dupe)); + /*if dupe.is_ascii_uppercase() { + let val = *dupe as u32 - 65 + 27; + rucksacks.push(val); + } else if dupe.is_ascii_lowercase() { + let val = *dupe as u32 - 96; + rucksacks.push(val); + }*/ + } + } + println!("part one priorities {}", rucksacks.into_iter().sum::()); + + let mut elves = file_contents.lines(); + loop { + if let Some(elf1) = elves.next() { + let elf2 = elves.next().unwrap(); + let elf3 = elves.next().unwrap(); + let elf1map: HashSet = HashSet::from_iter(elf1.chars()); + let elf2map: HashSet = HashSet::from_iter(elf2.chars()); + let elf3map: HashSet = HashSet::from_iter(elf3.chars()); + + for dupe in elf1map.iter().filter(|t| elf2map.contains(t) && elf3map.contains(t)) { + rucksacks2.push(get_priority(dupe)); + } + } else { + break; + } + } + println!("part two priorities {}", rucksacks2.into_iter().sum::()); + + Ok(()) +} diff --git a/2022/src/days/mod.rs b/2022/src/days/mod.rs index 4f29302..4e7d712 100644 --- a/2022/src/days/mod.rs +++ b/2022/src/days/mod.rs @@ -1,2 +1,3 @@ pub mod day1; pub mod day2; +pub mod day3; diff --git a/2022/src/main.rs b/2022/src/main.rs index 28f7db6..5d2c9ff 100644 --- a/2022/src/main.rs +++ b/2022/src/main.rs @@ -14,7 +14,10 @@ fn run_day(number: i32) -> Result<()> { } 2 => { days::day2::run()?; - } + }, + 3 => { + days::day3::run()?; + }, _ => return Err(anyhow!("Invalid day provided")), } Ok(()) diff --git a/2022/tests/day3.txt b/2022/tests/day3.txt new file mode 100644 index 0000000..f17e726 --- /dev/null +++ b/2022/tests/day3.txt @@ -0,0 +1,6 @@ +vJrwpWtwJgWrhcsFMMfFFhFp +jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL +PmmdzqPrVvPwwTWBwg +wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn +ttgJtRGJQctTZtZT +CrZsJsPPZsGzwwsLwLmpwMDw