Solve 2021 day 20, 21, 23, 25

This commit is contained in:
2024-11-27 17:31:52 -05:00
parent 4acc229c5a
commit a2a6ca52d1
8 changed files with 388 additions and 1 deletions

27
2021/d22.py Normal file
View File

@@ -0,0 +1,27 @@
from lib import get_data
from lib import ints
data = get_data(__file__)
limit = 50
ps = set()
for i, line in enumerate(data.splitlines()):
x_min, x_max, y_min, y_max, z_min, z_max = ints(line)
for x in range(max(x_min, -limit), min(x_max, limit) + 1):
for y in range(max(y_min, -limit), min(y_max, limit) + 1):
for z in range(max(z_min, -limit), min(z_max, limit) + 1):
if line.startswith("on"):
ps.add((x, y, z))
elif line.startswith("off"):
if (x, y, z) in ps:
ps.remove((x, y, z))
else:
assert False
print(len(ps))
# For part 1, we were limited to an area of -50..50 for all three directions.
# For part 2, this limitation is no longer in place. That means we cannot keep
# track of all the points individually. Instead, it will be necessary. To keep
# track of regions. Ultimately, we then have to perform arithmetic on the
# regions. This is not trivial enough for me right now.