2022 rust day 3

This commit is contained in:
Maciej Jur 2022-12-03 13:49:41 +01:00
parent f581d92a97
commit 06cba882b9

View file

@ -24,8 +24,8 @@ fn solve2(data: &Vec<(HashSet<char>, HashSet<char>)>) -> i32 {
.map(|(left, right)| left.union(right).cloned().collect())
.collect::<Vec<HashSet<_>>>()
.chunks_exact(3)
.map(|chunks| {
convert_char(find_intersection(chunks))
.map(|chunk| {
convert_char(find_intersection(chunk))
})
.sum()
}
@ -40,10 +40,11 @@ fn find_intersection(sets: &[HashSet<char>]) -> char {
iter.next()
.map(|set| {
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()
}