Solve 2021 day 20, 21, 23, 25
This commit is contained in:
27
2021/d22.py
Normal file
27
2021/d22.py
Normal 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.
|
||||
Reference in New Issue
Block a user