Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The 88th Puzzle by kurosawa4434
GOAL = (1, 2, 1, 0, 2, 0, 0, 3, 0, 4, 3, 4)
def puzzle88(state):
def rotate(n, st):
wk = list(st)
if n == 1:
wk[0], wk[3], wk[5], wk[2] = st[2], st[0], st[3], st[5]
if n == 2:
wk[1], wk[4], wk[6], wk[3] = st[3], st[1], st[4], st[6]
if n == 3:
wk[5], wk[8], wk[10], wk[7] = st[7], st[5], st[8], st[10]
if n == 4:
wk[6], wk[9], wk[11], wk[8] = st[8], st[6], st[9], st[11]
return tuple(wk)
def solve( st, step='', min_step = ''):
if min_step and len(step) >= len( min_step):
return min_step
if st == GOAL or len(step) >= 10:
if st == GOAL:
min_step = step
return min_step
for n in range(1, 5):
min_step = solve(rotate(n, st), step + str(n), min_step)
return min_step
return solve(state)
July 25, 2016
Comments: