diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-03 15:12:27 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2021-12-03 15:12:27 +0000 |
commit | 19710b72fd58989e25dec27884c99ac5b65272ff (patch) | |
tree | b037d5484165889157cbbf50614f37a526b73ec1 | |
parent | 782d739bdff1c53dce069676e2622a8a2231963b (diff) | |
download | aoc2021-19710b72fd58989e25dec27884c99ac5b65272ff.tar.gz aoc2021-19710b72fd58989e25dec27884c99ac5b65272ff.tar.xz aoc2021-19710b72fd58989e25dec27884c99ac5b65272ff.zip |
day 3 part 2: simplify complement
-rw-r--r-- | 3.py | 4 |
1 files changed, 1 insertions, 3 deletions
@@ -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) |