From 06cba882b96a00dfa18d74b63d3c8e46a4deb444 Mon Sep 17 00:00:00 2001 From: Maciej Jur Date: Sat, 3 Dec 2022 13:49:41 +0100 Subject: [PATCH] 2022 rust day 3 --- 2022/rust/src/solutions/day03.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/2022/rust/src/solutions/day03.rs b/2022/rust/src/solutions/day03.rs index 16e354e..7afe213 100644 --- a/2022/rust/src/solutions/day03.rs +++ b/2022/rust/src/solutions/day03.rs @@ -24,8 +24,8 @@ fn solve2(data: &Vec<(HashSet, HashSet)>) -> i32 { .map(|(left, right)| left.union(right).cloned().collect()) .collect::>>() .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 { 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() }