use itertools::Itertools; use std::collections::HashMap; use std::collections::HashSet; fn main() { let mut sum = 0; for group in &include_str!("../../input").lines().chunks(3) { let mut membership: HashMap = HashMap::new(); for rucksack in group { let mut items: HashSet = HashSet::new(); for item in &rucksack.chars().chunks(2) { for c in item { items.insert(c); } } for c in &items { *membership.entry(c.to_owned()).or_default() += 1; } } for (item, value) in membership { if value == 3 { if item.is_lowercase() { sum += item as i16 - 96; } else { sum += item as i16 - 38; } } } } println!("{}", sum); }