Post Reply 
Find the hidden path solver equation for 17b/19b/27s
06-30-2014, 11:34 PM (This post was last modified: 07-21-2014 12:07 AM by Don Shepherd.)
Post: #1
Find the hidden path solver equation for 17b/19b/27s
I've always wanted to write a program that requires the user to actually think to achieve a goal. This program does that. The calculator creates a path from left to right in an 8-by-8 grid. Your goal is to determine the location of the path in that grid by making guesses and recording and analyzing the feedback that you receive after each guess. The fewer number of guesses you make to determine the position of the path, the better. Eight guesses would, of course, be a perfect score, because each column contains exactly one point in the path. Each point in the path "touches" the point on the path in the preceding and following column.

The game is sort of like Battleship, with the addition of feedback. The feedback tells you how many points in the path are adjacent to your guess. You record the feedback on a template, listed below. By analyzing the feedback, you can sometimes determine where the next point has to be, or where the next point cannot be. That is the "thinking" part.

I first wrote the game for the Radio Shack PC-2 in BASIC, then for the HP-71b in BASIC, then for the HP-32sii in RPN keystroke, and finally for the 17b/19b/27s series solvers. The 17b version requires extra code to generate a random number; the 19b and 27s versions use the RAN# solver function for this.

I have attached information files to this article for the PC-2, HP-71b, and HP-32sii versions of this program. There are slight differences between these versions and the 17b version. The PC-2 information file contains only a code listing. I am reasonably sure that these versions work correctly on the corresponding machines, although I don't have a PC-2 or HP-71b to verify that since I trimmed back my calculator collection last year.

Note on entering solver equations:

Entering long solver equations can easily be very frustrating. Just take your time. These equations as listed will work, but it takes time to enter them. It helps greatly to do it in stages. For instance, begin by entering this:

IF(S(INIT):1-INIT:2-EVAL)

Then CALC the equation to make sure it is right.

Then, replace the 1 with everything under section A. Then CALC again to make sure everything has been entered correctly.

At this point, do a little testing. When you press INIT, variable A will contain 8 digits, the row numbers of the generated path. But you won't see A in the menu, so how can you check? You can add this code at the beginning of the equation:

0XA+ (X means times)

That will cause variable A to appear on the menu, and after you press INIT you can RCL A to verify that it contains a valid path. The 8 digits should be between 1 and 8 and each successive digit should be either the same as the previous digit or 1 greater or less. For example, these are valid values for A: 55,676,778, 22,334,565, 32,112,323, and so on.

Don't forget to remove 0XA+ unless you want to be able to get a perfect score every time, but that's not much fun frankly.

Once you verify that the equation is generating a valid path in variable A, then enter the B section part in place of the 2, then CALC the equation again to make sure it is correct.

The only spaces required in the equation are around the two OR operators toward the end of the equation; ANDs and ORs require spaces around them, but all other spaces are ignored. I suggest not entering any formatting spaces on the actual calculator, it will just increase the size of the equation unnecessarily.

To get a space, in ALPHA mode press the rightmost menu key (WXYZ) and then the menu key after Z (with a blank space above it). That will add a space.

To delete a character, press the left arrow key under the EXIT key. That will delete the character to the left of the flashing cursor.

If you get frustrated, take a break, or if you get stumped, post a message in the forum. Lots of people know lots about how the solver works.

Here is the solver equation for the 17b/17bii:

Code:

Find the Hidden Path for HP-17bii calculator

Usage:

1.  Press INIT until it says CALCULATING (should take about 5-6 seconds until INIT=0 displayed)
2.  Enter row.col of your guess, press GUESS
3.  Press EVAL to evaluate your guess
      Record feedback in your guess row.col:
        99 = put a dot, that point is on the path
        0 = no points adjacent to your guess are on the path
        1 = 1 point adjacent to your guess is on the path
        2 = 2 points adjacent to your guess are on the path
        3 = 3 points adjacent to your guess are on the path
4.  After you have correctly guessed the 8th point on the path, it will not display
    99, it will beep and display SOLUTION NOT FOUND.  Press RCL GUESS to see how 
    many guesses it took.

Variables used:

  INIT - solve for INIT at the beginning of the game
  GUESS - enter your guess as row.col and press GUESS button
  EVAL - solve for EVAL to evaluate each guess
  A - holds the 8 row numbers of the actual path
  B - random number
  J - holds the row number of the path in the previous column
  I - loop index while creating path
  N - used in random number generation
  NG - number of guesses
  NPT - number of points found

  GR - guess row
  GC - guess col
  PC - prior col
  NC - next col
  AR - actual row for guess col
  PR - prior row
  NR - next row



IF(S(INIT):  A below  - INIT :  B below  - EVAL)


A  this section creates the path and stores it in A and 
   initializes number of guesses and number of points found to 0


L(A:L(J:L(NG:L(NPT:0)))) X L(B:1E4 X FP(CTIME)) 
X SIGMA(I:1:8:1:
          L(J:0XL(N:2)+
            IF(G(J)=0:1+0XL(N:8):IF(G(J)=1:1:IF(G(J)=8:7:G(J)-1+0XL(N:3))))
            +MOD(IP(1000 X FP(SQRT(G(B)))):G(N))
           )
           X L(A:G(A)+G(J) X 10^(8-I))
           X L(B:G(B)+1079)
        )





B  this section evaluates the guess and provides feedback


0 X(L(NG:G(NG)+1)
  + L(GR:IP(GUESS))
  + L(GC:10 X FP(GUESS))
  + L(PC:G(GC)-1)
  + L(NC:G(GC)+1)
  + L(AR:IP(10 X FP(G(A)/10^(9-G(GC)))))
  + L(PR:IP(10 X FP(G(A)/10^(9-G(PC)))))
  + L(NR:IP(10 X FP(G(A)/10^(9-G(NC)))))
   )
+ IF(G(GR) = G(AR):99 + 0 X L(NPT:G(NPT)+1)
                  :IF(ABS(G(AR)-G(GR))>1:0:1)
                   + IF(G(PC)=0 OR ABS(G(GR)-G(PR))>1:0:1)
                   + IF(G(NC)=9 OR ABS(G(GR)-G(NR))>1:0:1)
    )
+ IF(G(NPT)=8:L(GUESS:G(NG))/0:0)

Here is the solver equation for the 19b/19bii/27s (using RAN# solver function)

Code:

Find the Hidden Path for HP-19b and HP-27s calculators (using RAN# function)

Usage:

1.  Press INIT until it says CALCULATING (should take about 5-6 seconds until INIT=0 displayed)
2.  Enter row.col of your guess, press GUESS
3.  Press EVAL to evaluate your guess
      Record feedback in your guess row.col:
        99 = put a dot, that point is on the path
        0 = no points adjacent to your guess are on the path
        1 = 1 point adjacent to your guess is on the path
        2 = 2 points adjacent to your guess are on the path
        3 = 3 points adjacent to your guess are on the path
4.  After you have correctly guessed the 8th point on the path, it will not display
    99, it will beep and display SOLUTION NOT FOUND.  Press RCL GUESS to see how 
    many guesses it took.

Variables used:

  INIT - solve for INIT at the beginning of the game
  GUESS - enter your guess as row.col and press GUESS button
  EVAL - solve for EVAL to evaluate each guess
  A - holds the 8 row numbers of the actual path
  J - holds the row number of the path in the previous column
  I - loop index while creating path
  N - used in random number generation
  NG - number of guesses
  NPT - number of points found

  GR - guess row
  GC - guess col
  PC - prior col
  NC - next col
  AR - actual row for guess col
  PR - prior row
  NR - next row



IF(S(INIT): (A below) - INIT : (B below) - EVAL)


A  this section creates the path and stores it in A and 
   initializes number of guesses and number of points found to 0


L(A:L(J:L(NG:L(NPT:0))))
X SIGMA(I:1:8:1:
          L(J:0XL(N:2)+
            IF(G(J)=0:1+0XL(N:8):IF(G(J)=1:1:IF(G(J)=8:7:G(J)-1+0XL(N:3))))
            +MOD(IP(1000 X RAN#):G(N))
           )
           X L(A:G(A)+G(J) X 10^(8-I))
       )




B  this section evaluates the guess and provides feedback


0 X(L(NG:G(NG)+1)
  + L(GR:IP(GUESS))
  + L(GC:10 X FP(GUESS))
  + L(PC:G(GC)-1)
  + L(NC:G(GC)+1)
  + L(AR:IP(10 X FP(G(A)/10^(9-G(GC)))))
  + L(PR:IP(10 X FP(G(A)/10^(9-G(PC)))))
  + L(NR:IP(10 X FP(G(A)/10^(9-G(NC)))))
   )
+ IF(G(GR) = G(AR):99 + 0 X L(NPT:G(NPT)+1)
                  :IF(ABS(G(AR)-G(GR))<=1:1:0)
                   + IF(G(PC)<>0 AND ABS(G(GR)-G(PR))<=1:1:0)
                   + IF(G(NC)<>9 AND ABS(G(GR)-G(NR))<=1:1:0)
    )
+ IF(G(NPT)=8:L(GUESS:G(NG))+LOG(0):0)
Find all posts by this user
Quote this message in a reply
Post Reply 




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