idk what i'm doing
This commit is contained in:
parent
0f7be9ae3a
commit
e530373823
|
@ -85,23 +85,87 @@ def find_corner_id(graph):
|
|||
if len(adjacency_list) == 2:
|
||||
return key
|
||||
|
||||
def get_tile_edges(tile):
|
||||
edgelist = []
|
||||
top = tile[0]
|
||||
bottom = tile[-1]
|
||||
left = ""
|
||||
right = ""
|
||||
for row in tile:
|
||||
left += row[0]
|
||||
right += row[-1]
|
||||
edgelist.append(top)
|
||||
edgelist.append(bottom)
|
||||
edgelist.append(left)
|
||||
edgelist.append(right)
|
||||
return edgelist
|
||||
|
||||
def get_image(tiles):
|
||||
edges = get_edges(tiles, flip=True)
|
||||
graph = find_adjacent(edges)
|
||||
tile_id = find_corner_id(graph)
|
||||
tile_id0 = find_corner_id(graph)
|
||||
visited = set()
|
||||
import math
|
||||
n = int(math.sqrt(len(tiles)))
|
||||
image = [[0] * n] * n
|
||||
i = 0
|
||||
j = 0
|
||||
|
||||
tile0 = tiles[tile_id]
|
||||
tile1, tile2 = graph[tile_id]
|
||||
t0, b0, l0, r0 = get_edges(tile0)
|
||||
t1, b1, l1, r1 = get_edges(tile1)
|
||||
t2, b2, l2, r2 = get_edges(tile2)
|
||||
tile0 = tiles[tile_id0]
|
||||
tile_id1, tile_id2 = graph[tile_id]
|
||||
tile1 = tiles[tile_id1]
|
||||
tile2 = tiles[tile_id2]
|
||||
t0, b0, l0, r0 = get_tile_edges(tile0)
|
||||
t1, b1, l1, r1 = get_tile_edges(tile1)
|
||||
t2, b2, l2, r2 = get_tile_edges(tile2)
|
||||
|
||||
if t0 == t1:
|
||||
image[i][j] = flip(rotate(rotate(tile0)))
|
||||
image[i+1][j] = tile1
|
||||
elif t0 == b1:
|
||||
image[i][j] = rotate(rotate(tile0)))
|
||||
image[i+1][j] = rotate(rotate(tile1))
|
||||
elif t0 == l1:
|
||||
image[i][j] = rotate(rotate(tile0))
|
||||
image[i+1][j] = rotate(tile1)
|
||||
elif t0 == r1:
|
||||
image[i][j] = rotate(rotate(tile0))
|
||||
image[i+1][j] = flip(rotate(rotate(rotate(tile1))))
|
||||
elif b0 == t1:
|
||||
image[i][j] = tile0
|
||||
image[i+1][j] = tile1
|
||||
elif b0 == b1:
|
||||
elif b0 == l1:
|
||||
elif b0 == r1:
|
||||
elif l0 == t1:
|
||||
elif l0 == b1:
|
||||
elif l0 == l1:
|
||||
elif l0 == r1:
|
||||
elif r0 == t1:
|
||||
elif r0 == b1:
|
||||
elif r0 == l1:
|
||||
elif r0 == r1:
|
||||
elif t0 == reversed(t1):
|
||||
elif t0 == reversed(b1):
|
||||
elif t0 == reversed(l1):
|
||||
elif t0 == reversed(r1):
|
||||
elif b0 == reversed(t1):
|
||||
elif b0 == reversed(b1):
|
||||
elif b0 == reversed(l1):
|
||||
elif b0 == reversed(r1):
|
||||
elif l0 == reversed(t1):
|
||||
elif l0 == reversed(b1):
|
||||
elif l0 == reversed(l1):
|
||||
elif l0 == reversed(r1):
|
||||
elif r0 == reversed(t1):
|
||||
elif r0 == reversed(b1):
|
||||
elif r0 == reversed(l1):
|
||||
elif r0 == reversed(r1):
|
||||
visited.add(tile_id0)
|
||||
visited.add(tile_id1)
|
||||
# remove borders of each tile
|
||||
# reconstruct image and return
|
||||
return image
|
||||
|
||||
def part2(tiles):
|
||||
image = get_image(tiles)
|
||||
|
|
Loading…
Reference in a new issue