summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2021-12-03 15:12:27 +0000
committerTomasz Kramkowski <tk@the-tk.com>2021-12-03 15:12:27 +0000
commit19710b72fd58989e25dec27884c99ac5b65272ff (patch)
treeb037d5484165889157cbbf50614f37a526b73ec1
parent782d739bdff1c53dce069676e2622a8a2231963b (diff)
downloadaoc2021-19710b72fd58989e25dec27884c99ac5b65272ff.tar.gz
aoc2021-19710b72fd58989e25dec27884c99ac5b65272ff.tar.xz
aoc2021-19710b72fd58989e25dec27884c99ac5b65272ff.zip
day 3 part 2: simplify complement
-rw-r--r--3.py4
1 files changed, 1 insertions, 3 deletions
diff --git a/3.py b/3.py
index 8d27cf2..29cae70 100644
--- a/3.py
+++ b/3.py
@@ -28,9 +28,7 @@ def part1(nums: Input) -> int:
def part2_impl(nums: Input, complement: bool, bit: int = 0) -> Bits:
if len(nums) == 1:
return nums[0]
- target: bool = most_common(column(nums, bit))
- if complement:
- target = not target
+ target: bool = most_common(column(nums, bit)) ^ complement
nums = list(filter(lambda n: n[bit] == target, nums))
return part2_impl(nums, complement, bit + 1)