add remaining code and input files from 2020
This commit is contained in:
1 parent
c10382b0c0
commit
23b2e01280
41 files changed
+11320
-37
No files matched your search
@@ -0,0 +1,32 @@
|
||||
|
||||
|
||||
# count answers in that group
|
||||
def count_answers(line):
|
||||
my_list = list(line)
|
||||
my_set = set(my_list)
|
||||
length = len(my_set)
|
||||
return length
|
||||
|
||||
|
||||
# count which answers were answered by all
|
||||
def count_answers_all(group):
|
||||
answers = group.split('\n')
|
||||
|
||||
z = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
|
||||
'u', 'v', 'w', 'x', 'y', 'z'}
|
||||
intersect = z.intersection(* [set(answer) for answer in answers if answer != ''])
|
||||
return len(intersect)
|
||||
|
||||
|
||||
with open(r"C:\Users\Maya\Desktop\Uni\WS_2021\AoC\input06") as f:
|
||||
lines = f.read()
|
||||
|
||||
# count answered letters
|
||||
lines1 = lines.replace("\n\n", '\t').replace("\n", "").split("\t")
|
||||
count = sum(count_answers(l) for l in lines1)
|
||||
print(count)
|
||||
|
||||
# count answered by all
|
||||
groups = lines.split("\n\n")
|
||||
count2 = sum(count_answers_all(g) for g in groups)
|
||||
print(count2)
|
||||
Reference in new issue
Block a user