//! Day 06 of 2020. use crate::prelude::*; /// Get the solution for day 06 of 2020. pub fn solution() -> Solution { Solution::new(Day::new(6, 2020), part_1, part_2).with_expected(6437, 3229) } /// The logic to solve part one. fn part_1(input: &str) -> Result { Ok( input .split("\n\n") .map(|group| { group .replace('\n', "") .chars() .collect::>() .len() }) .sum::() .to_string(), ) } /// The logic to solve part two. fn part_2(input: &str) -> Result { Ok( input .split("\n\n") .map(|group| { let mut count = 0; let possibilities = group.replace('\n', "").chars().collect::>(); for character in possibilities { if group .trim() .split('\n') .all(|person| person.contains(character)) { count += 1; } } count }) .sum::() .to_string(), ) }