diff options
-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 |