summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2021-12-03 14:58:50 +0000
committerTomasz Kramkowski <tk@the-tk.com>2021-12-03 14:58:50 +0000
commitc45f9100f0ad8304bc46c0e2f956cb532df26ac0 (patch)
tree1c26f02b020e2fb9d7e5a87810b8cdeae8b8c922
parent3cb7cb2b73f7e1165b1e18985652f9eb06523f6b (diff)
downloadaoc2021-c45f9100f0ad8304bc46c0e2f956cb532df26ac0.tar.gz
aoc2021-c45f9100f0ad8304bc46c0e2f956cb532df26ac0.tar.xz
aoc2021-c45f9100f0ad8304bc46c0e2f956cb532df26ac0.zip
day3: shorter bits_to_int
-rw-r--r--3.py6
1 files changed, 1 insertions, 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])