2020 Day 06

This commit is contained in:
Akumatic 2020-12-06 11:55:05 +01:00
parent b868f63060
commit ade3df0901
5 changed files with 2325 additions and 1 deletions

89
2020/06/README.md Normal file
View File

@ -0,0 +1,89 @@
# 2020 Day 6: Custom Customs
Copyright (c) Eric Wastl
#### [Direct Link](https://adventofcode.com/2020/day/6)
## Part 1
As your flight approaches the regional airport where you'll switch to a much larger plane, [customs declaration forms](https://en.wikipedia.org/wiki/Customs_declaration) 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?**
## Part 2
As you finish the last group's customs declaration, you notice that you misread one word in the instructions:
You don't need to identify the questions to which **anyone** answered "yes"; you need to identify the questions to which **everyone** answered "yes"!
Using the same example as above:
```
abc
a
b
c
ab
ac
a
a
a
a
b
```
This list represents answers from five groups:
- In the first group, everyone (all 1 person) answered "yes" to **`3`** questions: `a`, `b`, and `c`.
- In the second group, there is **no** question to which everyone answered "yes".
- In the third group, everyone answered yes to only **`1`** question, `a`. Since some people did not answer "yes" to `b` or `c`, they don't count.
- In the fourth group, everyone answered yes to only **`1`** question, `a`.
- In the fifth group, everyone (all 1 person) answered "yes" to **`1`** question, `b`.
In this example, the sum of these counts is `3 + 0 + 1 + 1 + 1` = **`6`**.
For each group, count the number of questions to which **everyone** answered "yes". **What is the sum of those counts**?

36
2020/06/code.py Normal file
View File

@ -0,0 +1,36 @@
# SPDX-License-Identifier: MIT
# Copyright (c) 2020 Akumatic
#
# https://adventofcode.com/2020/day/6
def readFile() -> list:
with open(f"{__file__.rstrip('code.py')}input.txt", "r") as f:
return [line.split() for line in f.read().strip().split("\n\n")]
def count(groups: list, everyone: bool) -> int:
result = 0
for group in groups:
answers = {chr(c):0 for c in range(97, 123)}
for answer in group:
for letter in answer:
answers[letter] += 1
if everyone:
result += sum([1 for letter in answers if answers[letter] == len(group)])
else:
result += sum([1 for letter in answers if answers[letter]])
return result
def part1(groups: list) -> int:
return count(groups, False)
def part2(seat_ids: list) -> int:
return count(groups, True)
if __name__ == "__main__":
groups = readFile()
print(f"Part 1: {part1(groups)}")
print(f"Part 2: {part2(groups)}")

2197
2020/06/input.txt Normal file

File diff suppressed because it is too large Load Diff

2
2020/06/solution.txt Normal file
View File

@ -0,0 +1,2 @@
Part 1: 7128
Part 2: 3640

View File

@ -17,7 +17,7 @@ Collect stars by solving puzzles. Two puzzles will be made available on each day
| --- | --- | --- |---| --- | --- | --- |
| 01 | :white_check_mark: | :white_check_mark: || 02 | :white_check_mark: | :white_check_mark: |
| 03 | :white_check_mark: | :white_check_mark: || 04 | :white_check_mark: | :white_check_mark: |
| 05 | :white_check_mark: | :white_check_mark: || 06 | | |
| 05 | :white_check_mark: | :white_check_mark: || 06 | :white_check_mark: | :white_check_mark: |
| 07 | | || 08 | | |
| 09 | | || 10 | | |
| 11 | | || 12 | | |