From a0fa20b89afea02a863eab262099aee92019beae Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Fri, 3 Dec 2021 15:16:37 +0000 Subject: day 3: simplify most_common to always take a list --- 3.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to '3.py') diff --git a/3.py b/3.py index 0a7a0c0..c4f645c 100644 --- a/3.py +++ b/3.py @@ -1,15 +1,9 @@ -from collections.abc import Iterable - Bits = tuple[bool, ...] Input = list[Bits] -def most_common(nums: Iterable[Bits], n: int) -> bool: - count: int = 0 - length: int = 0 - for num in nums: - if num[n]: count += 1 - length += 1 - return count >= length - count +def most_common(nums: list[Bits], n: int) -> bool: + count = sum(num[n] for num in nums) + return count >= len(nums) - count def bits_to_int(bits: Bits) -> int: return sum(b * 2 ** i for i, b in enumerate(reversed(bits))) -- cgit v1.2.3-54-g00ecf