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

View File

@ -373,3 +373,53 @@ def out_of_bounds(mx, row, col, shape=None):
return True return True
return False 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