-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday22_task1.py
More file actions
64 lines (51 loc) · 1.98 KB
/
Copy pathday22_task1.py
File metadata and controls
64 lines (51 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
###############################################################################
# Day x, Task y #
###############################################################################
import aoc_util
day = 22
data_str = """on x=-20..26,y=-36..17,z=-47..7
on x=-20..33,y=-21..23,z=-26..28
on x=-22..28,y=-29..23,z=-38..16
on x=-46..7,y=-6..46,z=-50..-1
on x=-49..1,y=-3..46,z=-24..28
on x=2..47,y=-22..22,z=-23..27
on x=-27..23,y=-28..26,z=-21..29
on x=-39..5,y=-6..47,z=-3..44
on x=-30..21,y=-8..43,z=-13..34
on x=-22..26,y=-27..20,z=-29..19
off x=-48..-32,y=26..41,z=-47..-37
on x=-12..35,y=6..50,z=-50..-2
off x=-48..-32,y=-32..-16,z=-15..-5
on x=-18..26,y=-33..15,z=-7..46
off x=-40..-22,y=-38..-28,z=23..41
on x=-16..35,y=-41..10,z=-47..6
off x=-32..-23,y=11..30,z=-14..3
on x=-49..-5,y=-3..45,z=-29..18
off x=18..30,y=-20..-8,z=-3..13
on x=-41..9,y=-7..43,z=-33..15
on x=-54112..-39298,y=-85059..-49293,z=-27449..7877
on x=967..23432,y=45373..81175,z=27513..53682"""
def task(data_set: list[str]) -> int:
cubes = set()
for r in data_set:
instruction, coords = r.split(" ")
x, y, z = coords.split(",")
xmin, xmax = x[2:].split("..")
xmin, xmax = max(int(xmin), -50), min(int(xmax), 50)
ymin, ymax = y[2:].split("..")
ymin, ymax = max(int(ymin), -50), min(int(ymax), 50)
zmin, zmax = z[2:].split("..")
zmin, zmax = max(int(zmin), -50), min(int(zmax), 50)
if instruction == "on":
for x in range(xmin, xmax + 1):
for y in range(ymin, ymax + 1):
for z in range(zmin, zmax + 1):
cubes.add((x, y, z))
else:
for x in range(xmin, xmax + 1):
for y in range(ymin, ymax + 1):
for z in range(zmin, zmax + 1):
cubes.discard((x, y, z))
return len(cubes)
aoc_util.run_with_data_str(task, data_str)
aoc_util.run_with_data_set(task, day)