summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2021-12-03 13:10:34 +0000
committerTomasz Kramkowski <tk@the-tk.com>2021-12-03 13:10:34 +0000
commit3cb7cb2b73f7e1165b1e18985652f9eb06523f6b (patch)
tree966a96be303798048ec5178b17162668e85c19d8
parentd2d7ede396c4349db45615f05a11c38540a4040c (diff)
downloadaoc2021-3cb7cb2b73f7e1165b1e18985652f9eb06523f6b.tar.gz
aoc2021-3cb7cb2b73f7e1165b1e18985652f9eb06523f6b.tar.xz
aoc2021-3cb7cb2b73f7e1165b1e18985652f9eb06523f6b.zip
day 3: Remove Counter dependency
-rw-r--r--3.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/3.py b/3.py
index 2eed1b7..fdfe203 100644
--- a/3.py
+++ b/3.py
@@ -1,6 +1,5 @@
from typing import Generator
from collections.abc import Iterable
-from collections import Counter
Bits = tuple[bool, ...]
Input = list[Bits]
@@ -10,10 +9,12 @@ def column(rows: Iterable[Bits], n: int) -> Generator[bool, None, None]:
yield row[n]
def most_common(bits: Iterable[bool]) -> bool:
- freqs: list[tuple[bool, int]] = Counter(bits).most_common()
- if len(freqs) > 1 and freqs[0][1] == freqs[1][1]:
- return True
- return freqs[0][0]
+ count1: int = 0
+ length: int = 0
+ for b in bits:
+ if b: count1 += 1
+ length += 1
+ return count1 >= length - count1
def bits_to_int(bits: Bits) -> int:
ret: int = 0