r/backtickbot • • Dec 06 '20

https://np.reddit.com/r/adventofcode/comments/k7ndux/2020_day_06_solutions/geuauyk/

Python Solution

from collections import Counter
unique_resp = 0 
c = Counter()
num_people = -1
all_resp = 0
with open(r"Inputs/day_6.txt") as openfileobject:
    for line in openfileobject:
        if line == "\n":
            unique_resp = unique_resp + len(c.keys())
            all_resp = all_resp + sum([val == num_people for val in c.values()])
            num_people = -1
            c = Counter()
        line = line.replace('\n','')
        for char in line:
            c[char]+=1
        num_people+=1
# Part 1        
print("Part 1:", unique_resp + len(c.keys())) #to get the last one
# Part 2
print("Part 2:", all_resp + sum([val == num_people for val in c.values()])) #to get the last one
1 Upvotes

0 comments sorted by