Day 6
This commit is contained in:
parent
9dd918bad0
commit
d473797874
3 changed files with 2106 additions and 0 deletions
2054
2020/6/data.txt
Normal file
2054
2020/6/data.txt
Normal file
File diff suppressed because it is too large
Load diff
37
2020/6/main.py
Normal file
37
2020/6/main.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
from pprint import pprint
|
||||
|
||||
def load(filename):
|
||||
with open(filename, "r", encoding="utf-8") as f:
|
||||
rec = []
|
||||
for line in f:
|
||||
s = line.rstrip()
|
||||
|
||||
if not s:
|
||||
yield rec
|
||||
rec = []
|
||||
continue
|
||||
|
||||
rec.append(s)
|
||||
|
||||
yield rec
|
||||
|
||||
|
||||
data = list(load("data.txt"))
|
||||
|
||||
# Anyone answered yes
|
||||
nq = sum([len(set(c for r in rec for c in r)) for rec in data])
|
||||
print(f"Sum of counts: {nq}")
|
||||
|
||||
# Everyone answered yes
|
||||
a = 0
|
||||
for grp in data:
|
||||
resp = {}
|
||||
for q in grp:
|
||||
for c in q:
|
||||
if c not in resp:
|
||||
resp[c] = 0
|
||||
resp[c] += 1
|
||||
n = sum(1 for k, v in resp.items() if len(grp) == v)
|
||||
a += n
|
||||
|
||||
print(f"Sum of everyone: {a}")
|
15
2020/6/test.txt
Normal file
15
2020/6/test.txt
Normal file
|
@ -0,0 +1,15 @@
|
|||
abc
|
||||
|
||||
a
|
||||
b
|
||||
c
|
||||
|
||||
ab
|
||||
ac
|
||||
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
|
||||
b
|
Loading…
Reference in a new issue