1
0
Fork 0

day 3 solution

main
Andrew Coleman 2022-12-05 09:19:26 -05:00
parent cc843cba6b
commit 14b0294282
5 changed files with 371 additions and 1 deletions

300
2022/day3.txt Normal file
View File

@ -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
bHcwbGCGRssNscwtHNbwvmRFvpFFJFvLZMmPLFfv
qBCrzznVmDCmMMDNgrgcrvHHcgbQcW
TTTsdJRTRhhlsgbvbdCFdbWvbQ
JhGGlfRlJsnCMDMqjmfV
rqLLvDLtStDLQhQDQrQhhNdsmWdmmjjnssPnTMnTzfTsWT
ZRFFpgCgppcBcnjTsjTMTfPFMP
GCZpGlwJwBgGHcJhSSHLDDrN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HnnfHHvCwtVMhzlzDllC
LrGnjGfgfvcwfgrLrBjrBLgwdBTSRBFsRZdRsSqFFSFSSPPp
whGCLqsrjgGhhGFqrCCFGCGzTRTZJcNnzlLTnznNHcnzTH
ddvVmbfvdvVbDVQdvvdSzpNcnJzlzSRHNJpnJcSc
BPdvfQdWtPDDPfDvDQVVPmbhssCGGMqgFCFMqGMWgMjrRw
PSLbGmWPSPLQbMTPWGFWltthdDdrmBDHhdDdczzDRh
VfCngVfgsZwCftrZdhcZrdNDzz
CjVJJJqnJwQhWPPLQlGj
ntnnQmTQTQGVWGNGNNlClG
jDffjMSvqjHzHHzwNVwNVcCddPVNdD
ZszJsrrZMjsHqqvZJLRQCbTRQbJmThbt
BgLHgFDsJNWgQgflWd
mnVVcCHnCGRcVnZSjmlthftMQddlfhQctNfW
qbSGqmHSTFprvpvTTL
dvdTMvvpdLpTcSLvdLLMmhfFBftwCNhRwRNjtCTRCf
lshQWgsgrHHqlFfRqFjRFfFwCB
rsgHQbJbrsGHHlgQHgJrlHrPZdhdpMZGDSDpdPLcZhdvhZ

60
2022/src/days/day3.rs Normal file
View File

@ -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<u32> = Vec::with_capacity(1000);
let mut rucksacks2: Vec<u32> = 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<char> = HashSet::from_iter(left);
let rightmap: HashSet<char> = 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::<u32>());
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<char> = HashSet::from_iter(elf1.chars());
let elf2map: HashSet<char> = HashSet::from_iter(elf2.chars());
let elf3map: HashSet<char> = 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::<u32>());
Ok(())
}

View File

@ -1,2 +1,3 @@
pub mod day1;
pub mod day2;
pub mod day3;

View File

@ -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(())

6
2022/tests/day3.txt Normal file
View File

@ -0,0 +1,6 @@
vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw