diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-03 14:58:50 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-03 14:58:50 +0000 |
commit | c45f9100f0ad8304bc46c0e2f956cb532df26ac0 (patch) | |
tree | 1c26f02b020e2fb9d7e5a87810b8cdeae8b8c922 | |
parent | 3cb7cb2b73f7e1165b1e18985652f9eb06523f6b (diff) | |
download | aoc2021-c45f9100f0ad8304bc46c0e2f956cb532df26ac0.tar.gz aoc2021-c45f9100f0ad8304bc46c0e2f956cb532df26ac0.tar.xz aoc2021-c45f9100f0ad8304bc46c0e2f956cb532df26ac0.zip |
day3: shorter bits_to_int
-rw-r--r-- | 3.py | 6 |
1 files changed, 1 insertions, 5 deletions
@@ -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]) |