Part 2 done

This commit is contained in:
Daniel Flanagan 2022-12-02 23:37:44 -06:00
parent a5e78315cf
commit 412c1c08fd
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4

View file

@ -1,6 +1,7 @@
mod common;
use std::collections::HashSet;
use std::iter::FromIterator;
fn main() {
let input = common::day_input(3);
@ -33,11 +34,25 @@ fn part1(input: &str) -> i32 {
n += 1
}
}
return r;
r
}
fn part2(input: &str) -> i32 {
0
let mut r = 0_i32;
for t in input.lines().collect::<Vec<&str>>().chunks_exact(3) {
let a: HashSet<u8> = HashSet::from_iter(t[0].bytes());
let b: HashSet<u8> = HashSet::from_iter(t[1].bytes());
let c: HashSet<u8> = HashSet::from_iter(t[2].bytes());
let ab = HashSet::from_iter(a.intersection(&b).cloned());
let b = ab.intersection(&c).next().unwrap();
if *b >= 97 && *b <= 122 {
r += (*b as i32) - 96;
} else {
r += (*b as i32) - 65 + 27;
}
println!("+{} = {}", b, r);
}
r
}
#[cfg(test)]
@ -58,6 +73,6 @@ CrZsJsPPZsGzwwsLwLmpwMDw";
#[test]
fn test_part2() {
assert_eq!(part2(TEST_INPUT), 0)
assert_eq!(part2(TEST_INPUT), 70)
}
}