DEV Community

Discussion on: Advent of Code 2020: Python Solution Day 6

Collapse
r0f1 profile image
Florian Rohrer

Here is my Python solution:

from collections import Counter

with open("input.txt") as f:
    grps = [x.strip().split() for x in f.read().split("\n\n")]

print(sum([len(Counter("".join(g))) for g in grps]))
print(sum([len([v for v in Counter("".join(g)).values() if v == len(g)]) for g in grps]))
Enter fullscreen mode Exit fullscreen mode

Github Link

Collapse
qviper profile image
Viper Author

So simple yet so tricky.

Collapse
philippurwoko profile image
Philip Purwoko

This is my solution using python for part 1 ( Not using python list comprehension version )

answers = []

with open('input.txt') as file:
    answer = []
    for i in file.readlines():
        if i != '\n':
            for q in i[:-1]:
                if q not in answer:
                    answer.append(q)
        else:
            answers.append(len(answer))
            answer = []
    answers.append(len(answer))

print(sum(answers))
Enter fullscreen mode Exit fullscreen mode
Collapse
qviper profile image
Viper Author

Still it is awesome. Thanks for sharing.