diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-03 15:16:37 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-03 15:16:37 +0000 |
commit | a0fa20b89afea02a863eab262099aee92019beae (patch) | |
tree | 9d38146be9cf5282b769168a0497e287ac41c101 | |
parent | f7debaca045f37410bd040531f45398bfeaaf735 (diff) | |
download | aoc2021-a0fa20b89afea02a863eab262099aee92019beae.tar.gz aoc2021-a0fa20b89afea02a863eab262099aee92019beae.tar.xz aoc2021-a0fa20b89afea02a863eab262099aee92019beae.zip |
day 3: simplify most_common to always take a list
-rw-r--r-- | 3.py | 12 |
1 files changed, 3 insertions, 9 deletions
@@ -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))) |