Compare commits

..

1 Commits

Author SHA1 Message Date
bb74658f9c Day 8 part 2 2021-12-07 22:44:35 -08:00

View File

@ -156,10 +156,13 @@ fn build_lookup(input: &str) -> Result<HashMap<String, &str>> {
let one: HashSet<_> = map["1"].chars().collect(); let one: HashSet<_> = map["1"].chars().collect();
let four: HashSet<_> = map["4"].chars().collect(); let four: HashSet<_> = map["4"].chars().collect();
//let seven_int: HashSet<_> = s.intersection(&seven).cloned().collect();
//let eight_int: HashSet<_> = s.intersection(&eight).cloned().collect();
// 0, 6 or 9 have 6 segments: // 0, 6 or 9 have 6 segments:
// 9 contains 1 and 4 // 0 is missing an intersection w/ 4
// 0 intersects w/ 1 but not w/ 4 // 6 is missing an intersection w/ 1
// 6 is the left overs. // 9 is the left overs.
set.iter().filter(|s| s.len() == 6).for_each(|d| { set.iter().filter(|s| s.len() == 6).for_each(|d| {
let s: HashSet<_> = d.chars().collect(); let s: HashSet<_> = d.chars().collect();
let one_int: HashSet<_> = s.intersection(&one).cloned().collect(); let one_int: HashSet<_> = s.intersection(&one).cloned().collect();
@ -208,7 +211,6 @@ fn output(line: &str) -> Result<u64> {
Ok(out Ok(out
.split(' ') .split(' ')
.map(|s| { .map(|s| {
// Sort letters in string before looking up.
let mut s: Vec<_> = s.chars().collect(); let mut s: Vec<_> = s.chars().collect();
s.sort_unstable(); s.sort_unstable();
let s: String = s.iter().collect(); let s: String = s.iter().collect();