-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path06.py
executable file
·52 lines (40 loc) · 1.51 KB
/
06.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
import math # math.floor
# Eingabe lesen
today = __file__.rsplit("/", 1)[-1].removesuffix(".py")
with open(f"input/{today}.txt") as infile:
input = infile.read().split("\n\n")
class groupAnswerParser:
def __init__(self, groupDefinition):
self.people = groupDefinition.splitlines()
def parseAllAnswers(self):
allAnswers = []
for person in self.people:
for answer in person:
if not answer in allAnswers:
allAnswers.append(answer)
return len(allAnswers)
def parseAnswersThatEveryoneAnswered(self):
allAnswers = {}
for person in self.people:
for answer in person:
if not answer in allAnswers:
allAnswers[answer] = 1
else:
allAnswers[answer] += 1
numAnswersThatEveryoneAnswered = 0
for answer, occurences in allAnswers.items():
if occurences == len(self.people):
numAnswersThatEveryoneAnswered += 1
return numAnswersThatEveryoneAnswered
# Teil 1
numAnswers = 0
numAllAnswers = 0
for groupDefinition in input:
answerParser = groupAnswerParser(groupDefinition)
numAnswers += answerParser.parseAllAnswers()
numAllAnswers += answerParser.parseAnswersThatEveryoneAnswered()
# 6625
print(f"Teil 1: Anzahl beantworteter Fragen: {numAnswers}")
# 3360
print(f"Teil 2: Anzahl Fragen, die alle beantwortet haben: {numAllAnswers}")