Day 18
This commit is contained in:
23
day18/part2.py
Normal file
23
day18/part2.py
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
lines = (x.strip() for x in open("input.txt"))
|
||||
queue = [(0, 0, 0)]
|
||||
cnt = 0
|
||||
visited = set()
|
||||
cubes = set()
|
||||
|
||||
for line in lines:
|
||||
x, y, z = map(int, line.split(","))
|
||||
cubes.add((x, y, z))
|
||||
|
||||
while queue:
|
||||
x, y, z = queue.pop(0)
|
||||
for xn, yn, zn in ((1, 0, 0), (0, 1, 0), (0, 0, 1), (-1, 0, 0), (0, -1, 0), (0, 0, -1)):
|
||||
neighbor = (x+xn, y+yn, z+zn)
|
||||
if neighbor in cubes:
|
||||
cnt += 1
|
||||
elif neighbor not in visited and -2 <= neighbor[0] < 22 and -2 <= neighbor[1] < 22 and -2 <= neighbor[2] < 22:
|
||||
queue.append(neighbor)
|
||||
visited.add(neighbor)
|
||||
|
||||
print(cnt)
|
||||
Reference in New Issue
Block a user