minor day 8 tweak

This commit is contained in:
swaits committed 2021-12-13 23:26:17 -07:00
1 parent 7e5ea237db
commit 5dd0fc2862
1 file changed
+5 -1
+5 -1
View File
@@ -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