From 19710b72fd58989e25dec27884c99ac5b65272ff Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Fri, 3 Dec 2021 15:12:27 +0000 Subject: day 3 part 2: simplify complement --- 3.py | 4 +--- 1 file changed, 1 insertion(+), 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) -- cgit v1.2.3-54-g00ecf