From c45f9100f0ad8304bc46c0e2f956cb532df26ac0 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Fri, 3 Dec 2021 14:58:50 +0000 Subject: day3: shorter bits_to_int --- 3.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/3.py b/3.py index fdfe203..7750fa1 100644 --- a/3.py +++ b/3.py @@ -17,11 +17,7 @@ def most_common(bits: Iterable[bool]) -> bool: return count1 >= length - count1 def bits_to_int(bits: Bits) -> int: - ret: int = 0 - for i, b in enumerate(reversed(bits)): - if b: - ret += 2 ** i - return ret + return sum(b * 2 ** i for i, b in enumerate(reversed(bits))) def part1(nums: Input) -> int: nbits: int = len(nums[0]) -- cgit v1.2.3-54-g00ecf