From 84b83d27a06fa3447bc8c9e5acf726c5331ed87a Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 6 Dec 2020 07:22:41 +0100 Subject: [PATCH] 2020: d06: ex1: add solution --- 2020/d06/ex1/ex1.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 2020/d06/ex1/ex1.py diff --git a/2020/d06/ex1/ex1.py b/2020/d06/ex1/ex1.py new file mode 100755 index 0000000..ff38b71 --- /dev/null +++ b/2020/d06/ex1/ex1.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python + +import sys +from collections import defaultdict +from typing import DefaultDict, List, Set + + +def solve(raw: List[str]) -> int: + answers: DefaultDict[int, Set[str]] = defaultdict(set) + group = 0 + for line in raw: + if line == "": + group += 1 + continue + answers[group] |= {char for char in line} + return sum(len(answer) for answer in answers.values()) + + +def main() -> None: + input = [line.strip() for line in sys.stdin.readlines()] + print(solve(input)) + + +if __name__ == "__main__": + main()