giving up

This commit is contained in:
Tyrel Souza 2022-12-18 12:06:24 -05:00
parent 5e8b272801
commit a172a101ab
3 changed files with 156 additions and 43 deletions

View File

@ -108,6 +108,7 @@ def part2(rows):
print("possible:", possible_count)
print(maxZ,maxY,maxX)
print()
#shared.render_cubes(maxX+2,maxY+2,maxZ+1, [x for x in _cubes])
air_nx = {}
for a in air:
@ -119,51 +120,63 @@ def part2(rows):
# loop row by row
inside = []
for z in range(0,maxZ+1):
for z in range(0,maxZ+2):
seen = set()
seen.add((0,0,z))
for y in range(0,maxY+1):
for x in range(0,maxX+1):
xyz = (x,y,z)
if xyz in _cubes:
#print(xyz,'is cube')
continue
ns = get_flat_neighbors_from(x,y,z, air)
for neigh in ns:
if neigh in seen and neigh not in _cubes:
seen.add(xyz)
this_level = air_in_row(air, z)
print(this_level, seen)
print(len(this_level), len(seen))
inside.extend([x for x in this_level if x not in seen])
#print()
#print(inside)
#print()
actually_inside = []
for i in inside:
ns = get_neighbors(*i)
# check for surrounded 100% by rock
rock_count = 0
for n in ns:
if n in _cubes:
rock_count +=1
if rock_count == 6:
print("in rock")
actually_inside.append(i)
continue
#check for surrounded 100% by air
air_count = 0
for n in ns:
if n in air:
air_count +=1
print("in air")
break
actually_inside.append(i)
#print(actually_inside)
tot, _, _, _, _, _ = surface_area(actually_inside)
print(tot)
print(potential - tot)
shared.render_cubes(maxX,maxY,maxZ, [x for x in actually_inside])
mx = matrix.matrix_of_size(maxX+2,maxY+2)
for x,y in matrix.spiral_generator(maxX+2, maxY+2):
xyz = x,y,z
mx[y][x] = "#"
if xyz in _cubes:
continue
ns = get_flat_neighbors(x,y,z)
for neigh in ns:
if neigh in seen:
seen.add(xyz)
this_level = set(x for x in air_in_row(air, z))
for (x,y,z) in seen:
mx[y][x] = 0
for x,y,z in this_level:
if (x,y,z) not in seen:
mx[y][x] = "o"
print(matrix.ppmx(mx, pad=False,space=False))
print()
#print(len(this_level), len(seen))
#inside.extend([x for x in this_level if x not in seen])
#print(seen)
#shared.render_cubes(maxX+2,maxY+2,maxZ+1, [x for x in seen])
#shared.render_cubes(maxX+2,maxY+2,maxZ+1, [x for x in this_level-seen])
##print()
##print(inside)
##print()
#actually_inside = []
#for i in inside:
# ns = get_neighbors(*i)
# # check for surrounded 100% by rock
# rock_count = 0
# for n in ns:
# if n in _cubes:
# rock_count +=1
# if rock_count == 6:
# print("in rock")
# actually_inside.append(i)
# continue
# #check for surrounded 100% by air
# air_count = 0
# for n in ns:
# if n in air:
# air_count +=1
# print("in air")
# break
# actually_inside.append(i)
##print(actually_inside)
#tot, _, _, _, _, _ = surface_area(actually_inside)
#print(tot)
#print(potential - tot)
def air_in_row(air, z):
x = []

View File

@ -373,3 +373,53 @@ def out_of_bounds(mx, row, col, shape=None):
return True
return False
def spiral_generator(width, height):
k = 0
l = 0
m = height
n = width
''' k - starting row index
m - ending row index
l - starting column index
n - ending column index
i - iterator '''
while (k < m and l < n):
# Print the first row from
# the remaining rows
for i in range(l, n):
yield (i,k)
#print(a[k][i], end=" ")
k += 1
# Print the last column from
# the remaining columns
for i in range(k, m):
yield (n-1,i)
#print(a[i][n - 1], end=" ")
n -= 1
# Print the last row from
# the remaining rows
if (k < m):
for i in range(n - 1, (l - 1), -1):
#print(a[m - 1][i], end=" ")
yield (i, m-1)
m -= 1
# Print the first column from
# the remaining columns
if (l < n):
for i in range(m - 1, k - 1, -1):
#print(a[i][l], end=" ")
yield (l,i)
l += 1

View File

@ -0,0 +1,50 @@
1,1,1
2,1,1
3,1,1
4,1,1
5,1,1
6,1,1
1,2,1
2,2,1
3,2,1
4,2,1
5,2,1
6,2,1
1,3,1
2,3,1
3,3,1
4,3,1
5,3,1
6,3,1
1,1,2
2,1,2
3,1,2
4,1,2
5,1,2
6,1,2
1,2,2
6,2,2
1,3,2
2,3,2
3,3,2
4,3,2
5,3,2
6,3,2
1,1,3
2,1,3
3,1,3
4,1,3
5,1,3
6,1,3
1,2,3
2,2,3
3,2,3
4,2,3
5,2,3
6,2,3
1,3,3
2,3,3
3,3,3
4,3,3
5,3,3
6,3,3