HP Forums
Re: a challenge related to the 15 puzzle - Printable Version

+- HP Forums (https://archived.hpcalc.org/museumforum)
+-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html)
+--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html)
+--- Thread: Re: a challenge related to the 15 puzzle (/thread-177225.html)



Re: a challenge related to the 15 puzzle - Don Shepherd - 01-18-2011

Here is a BASIC version for the HP-71b, 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




Re: a challenge related to the 15 puzzle - Allen - 01-18-2011

Nice-- and easy on the eyes.. I started a 50g program that uses PUT,PUTI,GET, LOC and REPL. It's compact, but incomplete as yet.