Day 6 part 1 solution.

This commit is contained in:
Bill Thiede 2020-12-06 09:49:37 -08:00
parent 59f67f1c64
commit 60a4950f24
3 changed files with 2317 additions and 0 deletions

2237
2020/input/2020/day6.txt Normal file

File diff suppressed because it is too large Load Diff

79
2020/src/day6.rs Normal file
View File

@ -0,0 +1,79 @@
//! --- Day 6: Custom Customs ---
//! As your flight approaches the regional airport where you'll switch to a much larger plane, customs declaration forms are distributed to the passengers.
//!
//! The form asks a series of 26 yes-or-no questions marked a through z. All you need to do is identify the questions for which anyone in your group answers "yes". Since your group is just you, this doesn't take very long.
//!
//! However, the person sitting next to you seems to be experiencing a language barrier and asks if you can help. For each of the people in their group, you write down the questions for which they answer "yes", one per line. For example:
//!
//! abcx
//! abcy
//! abcz
//! In this group, there are 6 questions to which anyone answered "yes": a, b, c, x, y, and z. (Duplicate answers to the same question don't count extra; each question counts at most once.)
//!
//! Another group asks for your help, then another, and eventually you've collected answers from every group on the plane (your puzzle input). Each group's answers are separated by a blank line, and within each group, each person's answers are on a single line. For example:
//!
//! abc
//!
//! a
//! b
//! c
//!
//! ab
//! ac
//!
//! a
//! a
//! a
//! a
//!
//! b
//! This list represents answers from five groups:
//!
//! The first group contains one person who answered "yes" to 3 questions: a, b, and c.
//! The second group contains three people; combined, they answered "yes" to 3 questions: a, b, and c.
//! The third group contains two people; combined, they answered "yes" to 3 questions: a, b, and c.
//! The fourth group contains four people; combined, they answered "yes" to only 1 question, a.
//! The last group contains one person who answered "yes" to only 1 question, b.
//! In this example, the sum of these counts is 3 + 3 + 3 + 1 + 1 = 11.
//!
//! For each group, count the number of questions to which anyone answered "yes". What is the sum of those counts?
//!
use std::collections::HashSet;
use aoc_runner_derive::aoc;
#[aoc(day6, part1)]
fn solution1(input: &str) -> usize {
input
.split("\n\n")
.map(|group| group.chars().filter(|c| c != &'\n').collect::<HashSet<_>>())
.map(|set| set.len())
.sum()
}
#[cfg(test)]
mod tests {
use super::*;
const INPUT: &'static str = r#"abc
a
b
c
ab
ac
a
a
a
a
b"#;
#[test]
fn part1() {
assert_eq!(solution1(INPUT), 11);
}
}

View File

@ -3,6 +3,7 @@ mod day2;
mod day3;
mod day4;
mod day5;
mod day6;
use aoc_runner_derive::aoc_lib;