52 lines
1.0 KiB
Rust
52 lines
1.0 KiB
Rust
//! 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<String> {
|
|
Ok(
|
|
input
|
|
.split("\n\n")
|
|
.map(|group| {
|
|
group
|
|
.replace('\n', "")
|
|
.chars()
|
|
.collect::<HashSet<char>>()
|
|
.len()
|
|
})
|
|
.sum::<usize>()
|
|
.to_string(),
|
|
)
|
|
}
|
|
|
|
/// The logic to solve part two.
|
|
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(),
|
|
)
|
|
}
|