From 9ae635bdacab67600b4728789e28b282345cfdd5 Mon Sep 17 00:00:00 2001 From: kamoshi <18511281+kamoshi@users.noreply.github.com> Date: Sun, 6 Dec 2020 09:29:30 +0100 Subject: [PATCH] Update day06.py --- 2020/Python/day06.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/2020/Python/day06.py b/2020/Python/day06.py index 3db253b..5a8acbf 100644 --- a/2020/Python/day06.py +++ b/2020/Python/day06.py @@ -1,3 +1,6 @@ +import functools + + def parse_input() -> list[list[str]]: groups = [[]] @@ -17,13 +20,10 @@ def solve_p1(groups: list[list[str]]) -> int: def count(group: list[str]) -> int: chars = set() - counted = 0 for line in group: for char in line: - if char not in chars: - counted += 1 - chars.add(char) - return counted + chars.add(char) + return len(chars) return sum(map(count, groups)) @@ -37,9 +37,7 @@ def solve_p2(groups: list[list[str]]) -> int: for char in line: new_set.add(char) sets.append(new_set) - result_set = sets[0] - for i in range(1, len(sets)): - result_set = result_set.intersection(sets[i]) + result_set = functools.reduce(set.intersection, sets) return len(result_set) return sum(map(count_intersection, groups))