import math, copy
def get_current_z0(pocket):
return len(pocket)//2
def increase_dimension(pocket):
for z_slice in pocket:
current_len = len(z_slice[0])
for y_slice in z_slice:
y_slice.insert(0,'.')
y_slice.append('.')
z_slice.insert(0, ['.' for _ in range(current_len+2)])
z_slice.append(['.' for _ in range(current_len+2)])
pocket.insert(0, [['.' for _ in range(current_len+2)] for _ in range(current_len+2)])
pocket.append([['.' for _ in range(current_len+2)] for _ in range(current_len+2)])
return pocket
def count_cubes(pocket):
return sum([1 for z_slice in pocket for y_slice in z_slice for x_slice in y_slice if x_slice=="#"])
def check_if_surrounded(i, j, k, lines):
is_surrounded_list = [check_occup(i+delta_i, j+delta_j, k+delta_k, lines) for delta_i in [-1,0,1] for delta_j in [-1,0,1] for delta_k in [-1,0,1] if not abs(delta_i)+abs(delta_j)+abs(delta_k)==0 and check_range(i+delta_i,j+delta_j,k+delta_k, lines)]
return is_surrounded_list
check_occup = lambda i,j,k,lines: lines[k][j][i] == "#"
check_range = lambda i,j,k,lines: k in range(0, len(lines)) and j in range(0, len(lines[0])) and i in range(0, len(lines[0][0]))
def hyper_increase_dimension(pocket):
current_len = len(pocket[0][0])
current_z = len(pocket[0])
for w_slice in pocket:
increase_dimension(w_slice)
pocket.insert(0, [[['.' for _ in range(current_len+2)] for _ in range(current_len+2)] for _ in range(current_z+2)])
pocket.append([[['.' for _ in range(current_len+2)] for _ in range(current_len+2)] for _ in range(current_z+2)])
return pocket
def hyper_check_if_surrounded(i, j, k, w, lines):
is_surrounded_list = [hyper_check_occup(i+delta_i, j+delta_j, k+delta_k, w+delta_w, lines) for delta_i in [-1,0,1] for delta_j in [-1,0,1] for delta_k in [-1,0,1] for delta_w in [-1,0,1] if not abs(delta_i)+abs(delta_j)+abs(delta_k)+abs(delta_w)==0 and hyper_check_range(i+delta_i,j+delta_j,k+delta_k, w+delta_w, lines)]
return is_surrounded_list
hyper_check_occup = lambda i,j,k,w,lines: lines[w][k][j][i] == "#"
hyper_check_range = lambda i,j,k,w,lines: w in range(0, len(lines)) and k in range(0, len(lines[0])) and j in range(0, len(lines[0][0])) and i in range(0, len(lines[0][0][0]))
def hyper_count_cubes(pocket):
return sum([1 for w_slice in pocket for z_slice in w_slice for y_slice in z_slice for x_slice in y_slice if x_slice=="#"])