Day 20 (works for any square puzzle size with 10x10 tiles)

This commit is contained in:
Sebastian Seedorf
2020-12-29 15:42:56 +01:00
parent 79087a9199
commit 259eb24308
3 changed files with 37 additions and 123 deletions

View File

@@ -36,7 +36,7 @@ for line in lines:
tile[lnr] = a
lnr += 1
add_tile(num, tile)
WIDTH = int(np.sqrt(len(tiles)))
# find top left corner
edges = defaultdict(int)
@@ -63,13 +63,13 @@ for x in range(4):
corner_tile = np.rot90(corner_tile)
# prepare plane
plane = np.zeros(((10-1)*12+1, (10-1)*12+1), dtype=np.int8)
plane = np.zeros(((10-1)*WIDTH+1, (10-1)*WIDTH+1), dtype=np.int8)
plane[:10, :10] = corner_tile
used_tiles = {corner}
# orientate and add tiles to plane
for idx in range(1, len(tiles)):
x, y = (idx % 12) * (10-1), (idx // 12) * (10-1)
x, y = (idx % WIDTH) * (10-1), (idx // WIDTH) * (10-1)
next_tile_top = None if y == 0 else borders[edge_to_bin(plane[y, x:x+10])]
next_tile_left = None if x == 0 else borders[edge_to_bin(plane[y:y+10, x].T)]
if next_tile_top is None: