Re: a challenge related to the 15 puzzle


I figured out that, rather than have two loops to calculate the inversion count (which takes about 40 seoonds on the 32sii), you can actually do it while you are entering the numbers if you keep track of the numbers you have previously entered. Then, when you enter the last number, you can see the inversion count immediately. This 32sii program implements that algorithm.

This version of the 15 puzzle solvability program is for the 32sii and not the 32s
because it uses the exchange x with a register command which is not on the 32s.
Since I got the 32sii I've been looking for a reason to use this command
and this is it!

This version calculates the cumulative inversion count as the 16 numbers are entered, so
once you enter the last number it tells you the inversions instantly, with no waiting.


enter first number
enter second number
enter 16th number

it then displays the inversion count; even number means the puzzle can be solved.


A-O - set to 1 when the corresponding number is entered
P - inversion count (even means solvable)
Q - main loop index
i - indirect addressing and second loop index


lbl a entry point
1.016 initialize loop to enter 16 numbers
sto q main loop index
lbl b begin main loop
r/s enter the next number (0 for empty space)
x=/=0 if empty space, calc row number and update P
goto c for 1-15
sto+p update inversion count with row # of empty cell
goto x iterate main loop
lbl c handle 1-15
x<->i move # to i
sto (i) put a 1 in A-O when number is found
x<->i get number back in x
1 add x-1 to p, max possible inversions
x=0 if 0 this is number 1, so nothing can be to it's left
goto x so iterate main loop
1000 otherwise loop from 1 to (x-1) and subtract what
/ you find there from p
sto i so input number 7 would cause loop from 1 to 6
lbl d begin loop
rcl(i) will be 0 or 1
sto-p subtract from inversion count
isg i iterate loop
goto d
lbl x iterate main loop now
isg q
goto b continue main loop to enter next number
rcl p display inversion count
rtn all done

Possibly Related Threads...
Thread Author Replies Views Last Post
  Good puzzle for kids to solve on 35s? snaggs 11 1,269 09-18-2013, 10:40 PM
Last Post: David Hayden
  Second Batch of HP-15 LE calculators Namir 6 856 07-02-2013, 12:27 PM
Last Post: Kimberly Thompson
  HP-15 LE Key repair question Namir 2 506 06-10-2013, 10:42 PM
Last Post: Namir
  Party Puzzle: for your amusement hugh steers 2 460 05-28-2013, 03:00 PM
Last Post: hugh steers
  HP 41 Mcode related Questions Michael Fehlhammer 4 668 05-10-2013, 07:09 PM
Last Post: Michael Fehlhammer
  The answer to the second semi-mathematical puzzle Mike Reed 3 511 02-18-2013, 02:40 AM
Last Post: Derek Walker (UK)
  Answer to Mathematical Puzzle Mike Reed 2 456 02-08-2013, 12:11 AM
Last Post: LHH
  OT: a semi mathmatical puzzle 4 u Mike Reed 6 771 02-05-2013, 07:50 PM
Last Post: Mike Reed
  Calculator O.T., instead HP related. Luiz C. Vieira (Brazil) 1 395 08-17-2012, 06:57 AM
Last Post: Frank Boehm (Germany)
  A new firmware beyond 2.15 for 50g ever? mr-scorpio 3 522 07-24-2012, 07:25 AM
Last Post: Keith Midson

Forum Jump: