From b4bf4e61ad2cb1acca569dd63219d331af183186 Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Sat, 3 Dec 2022 16:22:48 -0800 Subject: [PATCH] use bitand for sets --- 2022-aoc/src/d3.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/2022-aoc/src/d3.rs b/2022-aoc/src/d3.rs index d189729..eb4ebab 100644 --- a/2022-aoc/src/d3.rs +++ b/2022-aoc/src/d3.rs @@ -30,11 +30,11 @@ fn parse_input2(input: &str) -> Vec { let mut out = Vec::with_capacity(input.len() / 3); let lines: Vec<&str> = input.lines().collect(); for group in lines.chunks_exact(3) { - let [x, y, z] = group else {panic!()}; + let [x, y, z] = group else { panic!() }; let x: HashSet = HashSet::from_iter(x.chars()); let y = HashSet::from_iter(y.chars()); let z = HashSet::from_iter(z.chars()); - let xy: HashSet = x.intersection(&y).copied().collect(); + let xy = &x & &y; let common = xy.intersection(&z).next().unwrap(); out.push(get_priority(common)); }