27 lines
819 B
Rust
27 lines
819 B
Rust
fn main() {
|
|
let buf = std::fs::read_to_string("three.txt").unwrap();
|
|
|
|
let mut sum = 0u32;
|
|
|
|
for chunk in buf.split("\n").collect::<Vec<_>>().chunks_exact(3) {
|
|
let [line1, line2, line3] = chunk else { unreachable!() };
|
|
let mut seen_before = Vec::with_capacity(line1.len());
|
|
|
|
for c in line1.chars() {
|
|
if !seen_before.contains(&c) && line2.contains(c) && line3.contains(c) {
|
|
let priority = if c.is_ascii_uppercase() {
|
|
(c as u8) - 65 + 27
|
|
} else {
|
|
(c as u8) - 96
|
|
};
|
|
// dbg!(first, last, c, (c as u8), c.is_ascii_uppercase(), priority);
|
|
|
|
sum += priority as u32;
|
|
seen_before.push(c);
|
|
}
|
|
}
|
|
}
|
|
|
|
println!("{}", sum);
|
|
}
|