Part 2 done
This commit is contained in:
parent
a5e78315cf
commit
412c1c08fd
|
@ -1,6 +1,7 @@
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
use std::iter::FromIterator;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let input = common::day_input(3);
|
let input = common::day_input(3);
|
||||||
|
@ -33,11 +34,25 @@ fn part1(input: &str) -> i32 {
|
||||||
n += 1
|
n += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return r;
|
r
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(input: &str) -> i32 {
|
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)]
|
#[cfg(test)]
|
||||||
|
@ -58,6 +73,6 @@ CrZsJsPPZsGzwwsLwLmpwMDw";
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_part2() {
|
fn test_part2() {
|
||||||
assert_eq!(part2(TEST_INPUT), 0)
|
assert_eq!(part2(TEST_INPUT), 70)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue