Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
bfs solution in Clear category for The 88th Puzzle by flpo
GOAL = (1, 2, 1, 0, 2, 0, 0, 3, 0, 4, 3, 4)
MOVES = [(0, 3, 5, 2), (1, 4, 6, 3), (5, 8, 10, 7), (6, 9, 11, 8)]
def rotate(state, move):
l = list(state)
x, y, z, w = MOVES[int(move) - 1]
l[x], l[y], l[z], l[w] = l[w], l[x], l[y], l[z]
return tuple(l)
def puzzle88(state):
visited = set()
stack = [('', state)]
while stack:
path, state = stack.pop(0)
if state == GOAL:
return path
for m in '1234':
r = rotate(state, m)
if r not in visited:
visited.add(r)
stack.append((path + m, r))
Jan. 9, 2018