2022 rust day 3
This commit is contained in:
parent
f581d92a97
commit
06cba882b9
|
@ -24,8 +24,8 @@ fn solve2(data: &Vec<(HashSet<char>, HashSet<char>)>) -> i32 {
|
||||||
.map(|(left, right)| left.union(right).cloned().collect())
|
.map(|(left, right)| left.union(right).cloned().collect())
|
||||||
.collect::<Vec<HashSet<_>>>()
|
.collect::<Vec<HashSet<_>>>()
|
||||||
.chunks_exact(3)
|
.chunks_exact(3)
|
||||||
.map(|chunks| {
|
.map(|chunk| {
|
||||||
convert_char(find_intersection(chunks))
|
convert_char(find_intersection(chunk))
|
||||||
})
|
})
|
||||||
.sum()
|
.sum()
|
||||||
}
|
}
|
||||||
|
@ -42,8 +42,9 @@ fn find_intersection(sets: &[HashSet<char>]) -> char {
|
||||||
iter.fold(set, |set1, set2| {
|
iter.fold(set, |set1, set2| {
|
||||||
set1.intersection(&set2).cloned().collect()
|
set1.intersection(&set2).cloned().collect()
|
||||||
})
|
})
|
||||||
|
.into_iter()
|
||||||
|
.next().unwrap()
|
||||||
})
|
})
|
||||||
.map(|x| *x.iter().next().unwrap())
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue