2022-12-19 14:12:35 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
S = set() # cubes
|
|
|
|
for l in sys.stdin.read().splitlines():
|
2023-06-12 10:49:11 +00:00
|
|
|
(x,y,z) = list(map(int,l.split(','))) # makes type of tuple explicite for codon
|
|
|
|
S.add((x,y,z))
|
2022-12-19 14:12:35 +00:00
|
|
|
|
|
|
|
A = 23
|
|
|
|
L = set() # water
|
|
|
|
for x in range(-2,A+1):
|
|
|
|
for y in range(-2,A+1):
|
|
|
|
L.add((x,y,-2))
|
2023-06-12 10:49:11 +00:00
|
|
|
|
2022-12-19 14:12:35 +00:00
|
|
|
more = True
|
|
|
|
while more:
|
2023-06-12 10:49:11 +00:00
|
|
|
more = False
|
2022-12-19 14:12:35 +00:00
|
|
|
for x in range(-2,A+1):
|
|
|
|
for y in range(-2,A+1):
|
|
|
|
for z in range(-2,A+1):
|
|
|
|
if (x,y,z) not in S and (x,y,z) not in L: # water can only expand in air
|
|
|
|
for (i,j,k) in [(0,0,1),(0,0,-1),(0,1,0),(0,-1,0),(1,0,0),(-1,0,0)]:
|
|
|
|
if (x+i,y+j,z+k) in L: # if neighbour is water
|
|
|
|
L.add((x,y,z)) # water expand
|
2023-06-12 10:49:11 +00:00
|
|
|
more = True
|
2022-12-19 14:12:35 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
N = 0
|
|
|
|
for (x,y,z) in S:
|
|
|
|
for (i,j,k) in [(0,0,1),(0,0,-1),(0,1,0),(0,-1,0),(1,0,0),(-1,0,0)]:
|
|
|
|
if (x+i,y+j,z+k) in L:
|
|
|
|
N += 1
|
|
|
|
print(N)
|
|
|
|
|
2023-06-12 10:49:11 +00:00
|
|
|
# ~/.local/programs/codon/bin/codon build --relocation-model=static --release -o part2 part2.py
|