Day 6
This commit is contained in:
parent
5a03c12433
commit
8a285dcf05
27
2020/day6.py
Normal file
27
2020/day6.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
def main():
|
||||||
|
with open("day6.txt", "rt") as f:
|
||||||
|
text = f.read()
|
||||||
|
groups = text.split("\n\n")
|
||||||
|
|
||||||
|
# Part 1
|
||||||
|
count = 0
|
||||||
|
for g in groups:
|
||||||
|
letters = set(g)
|
||||||
|
count += len(letters)
|
||||||
|
if "\n" in g:
|
||||||
|
count -= 1
|
||||||
|
print("Total:", count)
|
||||||
|
|
||||||
|
# Part 2
|
||||||
|
count = 0
|
||||||
|
for g in groups:
|
||||||
|
common = None
|
||||||
|
answers = [set(p) for p in g.split("\n") if p]
|
||||||
|
for a in answers:
|
||||||
|
common = set(a) if common is None else common & set(a)
|
||||||
|
count += len(common)
|
||||||
|
print("Commons:", count)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in a new issue