1
Fork 0
advent-of-code/source/year_2020/day_06/mod.rs

47 lines
927 B
Rust
Raw Normal View History

2022-10-03 16:02:40 +00:00
use crate::prelude::*;
pub fn solution() -> Solution {
Solution::new(Day::new(6, 2020), part_1, part_2).with_expected(6437, 3229)
}
fn part_1(input: &str) -> Result<String> {
Ok(
input
.split("\n\n")
.map(|group| {
group
.replace('\n', "")
.chars()
.collect::<HashSet<char>>()
.len()
})
.sum::<usize>()
.to_string(),
)
}
fn part_2(input: &str) -> Result<String> {
Ok(
input
.split("\n\n")
.map(|group| {
let mut count = 0;
let possibilities =
group.replace('\n', "").chars().collect::<HashSet<char>>();
for character in possibilities {
if group
.trim()
.split('\n')
.all(|person| person.contains(character))
{
count += 1;
}
}
count
})
.sum::<usize>()
.to_string(),
)
}