From 5dd0fc28623deb7a2b6aaa916ef37b7f6554b9e1 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 13 Dec 2021 23:26:17 -0700 Subject: [PATCH] minor day 8 tweak --- src/day08.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/day08.rs b/src/day08.rs index dada94d..6eecfb8 100644 --- a/src/day08.rs +++ b/src/day08.rs @@ -5,7 +5,11 @@ use itertools::Itertools; // NOTE: this is O(n^2), but our input is tiny // a HashSet is better complexity, but the allocations will hurt us fn shared_chars(a: &str, b: &str) -> usize { - a.chars().filter(|c| b.contains(&c.to_string())).count() + if a.len() < b.len() { + a.chars().filter(|ch| b.contains(&ch.to_string())).count() + } else { + b.chars().filter(|ch| a.contains(&ch.to_string())).count() + } } // decode a set of 10 input + 4 output characters and return the output -- 2.45.2