Day 3, Part 1 & 2

This commit is contained in:
Aadi Desai 2023-10-12 11:28:58 +01:00
parent ce34bbb9b3
commit 9f6c7656d5
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM
2 changed files with 340 additions and 0 deletions

40
src/bin/d3.rs Normal file
View file

@ -0,0 +1,40 @@
use itertools::Itertools;
const INPUT: &str = include_str!("../input/d3.txt");
fn main() -> anyhow::Result<()> {
let p1 = INPUT
.split('\n')
.map(|s| s.split_at(s.len() / 2))
.map(|(l, r)| {
l.chars().find(|ch| {
r.contains(*ch)
}).expect("No common characters in rucksack")
})
.map(item_priority)
.sum::<usize>();
println!("{p1}");
let p2 = INPUT
.split('\n')
.batching(|it| {
it.next_tuple::<(&str,&str,&str)>()
})
.map(|(a, b, c)| {
a.chars()
.filter(|&ch| b.contains(ch))
.find(|&ch| c.contains(ch))
.expect("No common characters in 3 rucksacks")
})
.map(item_priority)
.sum::<usize>();
println!("{p2:?}");
anyhow::Ok(())
}
fn item_priority(item: char) -> usize {
match item {
'a'..='z' => item as usize - 96,
'A'..='Z' => item as usize - 38,
_ => unreachable!(),
}
}

300
src/input/d3.txt Normal file
View file

@ -0,0 +1,300 @@
VdzVHmNpdVmBBCpmQLTNfTtMhMJnhFhTTf
FgqsZbqDDFqRrhhJnsnLMTfhJG
bRRRPrRRwSwbDqgjvDZbRbQzpzmQVWCzzBdvQBFCzlWV
GcDdRdvhRssRhGDdShCRtqWjlQzqWgqzNfNjfQWWjt
mwwnnPFwmVrPmJmzfNzqCjQCbgVlgC
nPnHHLrHwmJTrCTJpThBscBSdSLGZvZBvRhZ
RVQQcVlcSRclfZCCCnMJJTSTnC
NdHwjdwjbBBZrrZrbJDZJJ
wmhjGGBGwwmjtjtdPlfRcpVQlhRppVJF
pplbNBPPrppllrFNbpvppSTcwqcWFhTTShhJDTchqd
RGzRfLjjmZmfmwLftTWhStStJWTdWmDm
nfsMjQssnpPvNnrPrw
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