summaryrefslogtreecommitdiffstats
path: root/3.py
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2021-12-03 15:16:37 +0000
committerTomasz Kramkowski <tk@the-tk.com>2021-12-03 15:16:37 +0000
commita0fa20b89afea02a863eab262099aee92019beae (patch)
tree9d38146be9cf5282b769168a0497e287ac41c101 /3.py
parentf7debaca045f37410bd040531f45398bfeaaf735 (diff)
downloadaoc2021-a0fa20b89afea02a863eab262099aee92019beae.tar.gz
aoc2021-a0fa20b89afea02a863eab262099aee92019beae.tar.xz
aoc2021-a0fa20b89afea02a863eab262099aee92019beae.zip
day 3: simplify most_common to always take a list
Diffstat (limited to '3.py')
-rw-r--r--3.py12
1 files changed, 3 insertions, 9 deletions
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)))