Solution to problem 6 part 2 in Python (failed mypy :()

This commit is contained in:
David Doblas Jiménez 2021-11-21 18:05:21 +01:00
parent 8f819f9f36
commit 9368673b32

View File

@ -66,7 +66,7 @@ with open("files/P6.txt", "r") as f:
def part_1() -> None:
counts: int = 0
for answers_group in answers_groups:
q = len(
yes = len(
set(
[
answer
@ -75,10 +75,64 @@ def part_1() -> None:
]
)
)
counts += q
counts += yes
print(f"The sum of counts is {counts}")
# --- Part Two ---
# 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?
def part_2() -> None:
counts: int = 0
for answers_group in answers_groups:
yes = len(set.intersection(*map(set, answers_group)))
counts += yes
print(f"The sum of counts is {counts}")
if __name__ == "__main__":
part_1()
part_2()