Solve day 6

This commit is contained in:
Gabriel Augendre 2020-12-06 09:37:09 +01:00
parent f233d1121e
commit 6ab0ae77f2
No known key found for this signature in database
GPG key ID: 1E693F4CE4AEE7B4
4 changed files with 2121 additions and 0 deletions

View file

@ -0,0 +1,29 @@
from typing import List
def main(filename: str, expected_part_1: int = None, expected_part_2: int = None):
print(f"\n+ Running on {filename}")
with open(filename) as f:
groups = f.read().strip().split("\n\n") # type: List[str]
counter_part_1 = 0
counter_part_2 = 0
for group in groups:
counter_part_1 += len(set(group.replace("\n", "")))
people = group.split()
intersect = set.intersection(*list(map(set, people)))
counter_part_2 += len(intersect)
print(f"1. Found {counter_part_1}")
if expected_part_1:
assert expected_part_1 == counter_part_1
print(f"2. Found {counter_part_2}")
if expected_part_2:
assert expected_part_2 == counter_part_2
if __name__ == "__main__":
main("inputs/day06-test1", 11, 6)
main("inputs/day06-test2", 15, 8)
main("inputs/day06", 6170, 2947)

2057
2020/inputs/day06 Normal file

File diff suppressed because it is too large Load diff

15
2020/inputs/day06-test1 Normal file
View file

@ -0,0 +1,15 @@
abc
a
b
c
ab
ac
a
a
a
a
b

20
2020/inputs/day06-test2 Normal file
View file

@ -0,0 +1,20 @@
abc
a
b
c
ab
ac
a
a
a
a
b
ab
ab
abc
abd