(HP67/97) a little fun with the fifteen puzzle

12032016, 09:26 PM
(This post was last modified: 12062016 03:29 PM by Don Shepherd.)
Post: #1




(HP67/97) a little fun with the fifteen puzzle
Everyone knows the fifteen puzzle; fifteen little numbered tiles, 115, in a little 4 by 4 container with one position empty, usually interlocking pieces that cannot be removed from the container. But what if the pieces are not interlocking and are removable, allowing you to setup your own random start position? Is every such configuration solvable (solvable meaning being able to arrange the pieces, by sliding only, into order 115)? Surprisingly, the answer is, "no." It turns out that half of the possible initial configurations are not solvable. How can you tell if a given initial configuration of the tiles is solvable? That's what this program is about.
There is this thing called "number of inversions." If the number of inversions is an even number, the configuration is solvable, else it is not. How do you determine the number of inversions? You run this program! Imagine all 15 tiles in a single row. Start at the tile in the leftmost position; how many tiles to its right have values that are less than this tile? Those are called inversions. If the leftmost tile was number 7, then the number of inversions for the first tile would be 6, obviously. Then move to the second tile; how many tiles to its right are less than its value? Keep doing this for all tiles, and that sum is the number of inversions (plus the row number of the empty space). I have a nice wooden fifteen puzzle that came with a great book describing everything about the puzzle. The pieces are removable, so this program will let me create an initial configuration that is solvable. To run the program, press A (initialization). Then enter the tile piece in the leftmost position of the first row, followed by pressing B. Then continue along the first row, pressing B for each of the other 3 values. Then enter the first number in the second row and press B, and so on. For the empty space, press 0 then B. After all 16 values are entered, press C. The program will run for about two and onehalf minutes before it displays the number of inversions. If this number is even, great, the puzzle is solvable. If the number is odd, simply switch any two tiles with each other and it will be solvable. I always wanted to create this program for my HP65, but it was impossible due to only 9 variables (really 8 unless you have no conditionals) and lack of indirect addressing. The HP67 works fine, however, with its extended programming capabilities. I am aware of the fact that, in the time the program takes to run, you could have calculated the number of inversions manually. But I generally make a mistake when I do it that way, and the program never makes a mistake, like all good computers. Remember, A is initialization, B enters the 16 values, and C calculates the number of inversions. Code:


12052016, 09:51 PM
Post: #2




RE: (HP67/97) a little fun with the fifteen puzzle  
12052016, 10:07 PM
Post: #3




RE: (HP67/97) a little fun with the fifteen puzzle
The X NE 0 or X <> 0 conditional is f + or yellow shift +.
It is the X < Y ? conditional that is not on the keyboard. Unless Don meant that one to be X <= Y ? :) The best approaches to supplying the missing conditionals are found in this PPC booklet: Better Programming on the HP67/97 

12062016, 12:24 AM
(This post was last modified: 12062016 03:38 PM by Don Shepherd.)
Post: #4




RE: (HP67/97) a little fun with the fifteen puzzle
Thanks Dieter and Gene. I changed the x<y to x<=y in the code above.
Yes, I remember as I was entering the program that there was no x<y, so as Gene suggested I tried x<=y and that worked (it works because, in this instance, the two values in x and y can never be equal). I created the HP67 program from a solver equation I had on the 17b which runs much faster than the 67 code (20 seconds versus 2 and a half minutes). Thanks for that link Gene, it appears to be a treasure trove of good information on the 67. I plan on studying that document over the holidays. 

12062016, 01:43 AM
Post: #5




RE: (HP67/97) a little fun with the fifteen puzzle
Maybe post the 17b solver equation if anyone shows an interest? {hint}
SlideRule 

12062016, 03:46 AM
Post: #6




RE: (HP67/97) a little fun with the fifteen puzzle
(12062016 01:43 AM)SlideRule Wrote: Maybe post the 17b solver equation if anyone shows an interest? {hint} Sure, SlideRule, here it is: Code:


12062016, 05:14 AM
Post: #7




RE: (HP67/97) a little fun with the fifteen puzzle
Here is a link to a version of the fifteen puzzle that has removable pieces. It includes a small book that is very well illustrated and gives the interesting history of the puzzle.
book 

12062016, 07:06 AM
Post: #8




RE: (HP67/97) a little fun with the fifteen puzzle
(12052016 10:07 PM)Gene Wrote: The X NE 0 or X <> 0 conditional is f + or yellow shift +. Ah, so this is supposed to be a *test*! I read this as an X exchange R0 command! (12052016 10:07 PM)Gene Wrote: The best approaches to supplying the missing conditionals are found in this PPC booklet: Better Programming on the HP67/97 Thank you for the link. The technique itself (two or more consecutive tests) is well known, I once wrote about this in the old forum. Dieter 

12062016, 12:52 PM
Post: #9




RE: (HP67/97) a little fun with the fifteen puzzle  
« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)