Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for The 88th Puzzle by gyahun_dash
GOAL = (1, 2, 1, 0, 2, 0, 0, 3, 0, 4, 3, 4)
ROT, STARTS = (0, 3, 5, 2), (0, 1, 5, 6)
ACTIONS = [{s + ROT[i]: s + ROT[i - 1] for i in range(4)} for s in STARTS]
def puzzle88(initial):
states = {'': initial}
while True:
history = min(states, key = len)
state = states.pop(history)
shortages = {g for g, s in zip(GOAL, state) if 0 < g != s}
if not shortages: return history
for index in shortages:
act = ACTIONS[index - 1]
newstate = tuple(state[act.get(i, i)] for i in range(12))
states[history + str(index)] = newstate
Aug. 7, 2014
Comments: