Not much to report today.. so I’llreach back to last weekend for something that happened then.. On my birthday in February, Diane got me this puzzle.. I love puzzles.. but this one is really diabolical.. With only 9 pieces it has over 300,000 possible answers.. and only 1 is right.. well.. actually there are four correct answers.. but I’m getting ahead of myself
Everybody in the house took terms beating their head against this puzzle for several days.. but.. no luck…
Finally in a huge fit of procrastination … (i had tons of work, work to do).. I wrote the following.. actually.. I wrote this in my head when I should have been listening to a feldenkreis class..
it went something like this (in badly formed Python)
# solve that @#%@ing puzzle pieces = [ [-4,4,1,-1], [-2,-3,1,3], [-3,3,4,-4], [-1,-1,3,4], [-1,1,3,-4], [-3,-4,2,4], [-3,2,4,-2], [-3,-1,2,2], [-1,3,2,-2]] placed = [-1,-1,-1,-1,-1,-1,-1,-1,-1] r = [0,0,0,0,0,0,0,0,0] md = 0 trys=0 def showplace(): global trys for i in range(len(placed)): if placed[i] > -1: print ' %2i ' % pieces[placed[i]][(r[i]+1)%4], print "" for i in range(len(placed)): if placed[i] > -1: print '%2i %2i ' % (pieces[placed[i]][(r[i]+0)%4],pieces[placed[i]][(r[i]+2)%4]), print "" for i in range(len(placed)): if placed[i] > -1: print ' %2i ' % pieces[placed[i]][(r[i]+3)%4], print "" print "trys=", trys print "" def place( unplaced, depth, spaces): global md global trys trys = trys + 1 if depth > md : md = depth for i in range(len(unplaced)) : runplaced = unplaced[:] p = runplaced.pop(i) placed[depth] = p for j in range(4) : r[depth] = j if (depth % 3 ==0) or pieces[placed[depth]][r[depth]]+pieces[placed[depth-1]][(2+r[depth-1]) % 4] == 0: if (depth<3) or pieces[placed[depth]][(r[depth]+1)%4]+pieces[placed[depth-3]][(3+r[depth-3]) % 4] == 0: if len(runplaced) > 0: ret=place( runplaced, depth + 1, spaces + " ") else : showplace() exit placed[depth] = -1 r[depth] = 0 unplaced = [0,1,2,3,4,5,6,7,8] place(unplaced, 0, " ")
5 seconds later I had the solution
3 4 2 1 1 3 4 2 4 -1 4 -4 1 -1 2 -1 3 -3 3 -3 4 2 -3 3 -2 2 -2 -1 -1 -3 -4 -2 -4 -4 -1 -3 trys= 1048 2 -1 -1 3 -3 -4 2 -3 -1 -4 4 -4 1 -1 3 -1 2 -2 1 -1 4 -3 4 -4 3 -3 2 -3 3 4 -2 3 1 -2 4 2 trys= 1732 -3 -1 -4 -4 -2 -4 -3 -1 -1 -2 2 -2 3 -3 2 4 -3 3 -3 3 -1 2 -1 1 -4 4 -1 4 2 4 3 1 1 2 4 3 trys= 2289 2 4 -2 1 3 -2 4 3 -3 2 -3 3 -4 4 -3 4 -1 1 -2 2 -1 3 -1 1 -4 4 -4 -1 -3 2 -4 -3 3 -1 -1 2 trys= 2458Actually.. 4 solutions.. since the puzzle can be solved on all 4 directions
I then tore up the answer so no one else was tempted to cheat..
so.. what do you think.. cool innovation ?.. or unsportsemanlike conduct..
you decide,..
nite all nite sam
# solve that @#%@ing puzzle
pieces = [ [-4,4,1,-1], [-2,-3,1,3], [-3,3,4,-4], [-1,-1,3,4],
[-1,1,3,-4], [-3,-4,2,4], [-3,2,4,-2], [-3,-1,2,2], [-1,3,2,-2]]placed = [-1,-1,-1,-1,-1,-1,-1,-1,-1]
r = [0,0,0,0,0,0,0,0,0]
md = 0
trys=0def showplace():
global trys
for i in range(len(placed)):
if placed[i] > -1:
print ‘ %2i ‘ % pieces[placed[i]][(r[i]+1)%4],
print “”
for i in range(len(placed)):
if placed[i] > -1:
print ‘%2i %2i ‘ % (pieces[placed[i]][(r[i]+0)%4],pieces[placed[i]][(r[i]+2)%4]),
print “”
for i in range(len(placed)):
if placed[i] > -1:
print ‘ %2i ‘ % pieces[placed[i]][(r[i]+3)%4],
print “”
print “trys=”, trys
print “”def place( unplaced, depth, spaces):
global md
global trys
trys = trys + 1
if depth > md :
md = depth
for i in range(len(unplaced)) :
runplaced = unplaced[:]
p = runplaced.pop(i)
placed[depth] = pfor j in range(4) :
r[depth] = jif (depth % 3 ==0) or pieces[placed[depth]][r[depth]]+pieces[placed[depth-1]][(2+r[depth-1]) % 4] == 0:
if (depth<3) or pieces[placed[depth]][(r[depth]+1)%4]+pieces[placed[depth-3]][(3+r[depth-3]) % 4] == 0:
if len(runplaced) > 0:
ret=place( runplaced, depth + 1, spaces + ” “)
else :
showplace()
exit
placed[depth] = -1
r[depth] = 0unplaced = [0,1,2,3,4,5,6,7,8]
place(unplaced, 0, ” “)