47 lines
927 B
Rust
47 lines
927 B
Rust
|
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(),
|
||
|
)
|
||
|
}
|