From 3cb7cb2b73f7e1165b1e18985652f9eb06523f6b Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Fri, 3 Dec 2021 13:10:34 +0000 Subject: day 3: Remove Counter dependency --- 3.py | 11 ++++++----- 1 file 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 -- cgit v1.2.3-54-g00ecf