Re: a challenge related to the 15 puzzle Message #1 Posted by Don Shepherd on 18 Jan 2011, 10:20 p.m.
Here is a BASIC version for the HP71b, one of my favorite calculators. It is much faster than the 32sii version, probably because it doesn't have to decode multiple numbers stored in a register.
HP 71b program to determine 15 puzzle solvability
10 destroy all
20 integer a(16)
30 data 11,5,14,7,15,2,9,4,6,0,1,13,10,3,12,8
40 for i=1 to 16
50 read a(i)
60 if a(i)=0 then let b=ip((i+3)/4)
70 next i
80 for i=1 to 15
90 for j=i+1 to 16
100 if a(j)<>0 and a(j)<a(i) then let b=b+1
110 next j
120 next i
130 if mod(b,2)=0 then disp "solvable" else disp "unsolvable"
140 disp "inversions = ";b
