diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-03 13:10:34 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-03 13:10:34 +0000 |
commit | 3cb7cb2b73f7e1165b1e18985652f9eb06523f6b (patch) | |
tree | 966a96be303798048ec5178b17162668e85c19d8 | |
parent | d2d7ede396c4349db45615f05a11c38540a4040c (diff) | |
download | aoc2021-3cb7cb2b73f7e1165b1e18985652f9eb06523f6b.tar.gz aoc2021-3cb7cb2b73f7e1165b1e18985652f9eb06523f6b.tar.xz aoc2021-3cb7cb2b73f7e1165b1e18985652f9eb06523f6b.zip |
day 3: Remove Counter dependency
-rw-r--r-- | 3.py | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -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 |