The Museum of HP Calculators

HP Articles Forum

Couple of interesting HP-17bii solver programs

Posted by Don Shepherd on 19 Jan 2012, 10:58 a.m.

Here are a couple of HP-17bii solver programs that some might find interesting or useful.

The first program is the world famous Hi-Lo Game. The calculator thinks of a number from 0 to 99 and you have to guess the number. If you choose your guesses by using a binary search, it will never take more than 7 guesses. This is a great game to play to keep your mind sharp and avoid Alzheimer's disease.

Begin by pressing INIT until it says CALCULATING... This sets the guess count to zero and establishes the random number, 0 to 99. It would have been nice if the 17bii had the RAN# function, like the HP-27S, but it doesn't. Then enter your guess (0-99) and press GUESS. Then press EVAL to evaluate your guess. If your guess is less than the random number, the display will show EVAL=0 (you're too low). If your guess is greater than the random number, the display will show EVAL=99 (you're too high). If your guess is equal to the random number, the display will show how many guesses it took you to find it.

The second program is a bit weird. I have a theory that each person has "lucky" or "memorable" days based upon the days-between-dates from the person's birthdate to a given date being a prime number. I would like to say that I have proven this theory by looking at memorable dates in the past in my life (date I got married, date my only child was born, etc.) and determining that the theory held, but alas it does not. But it's still an interesting exercise in programming on the 17bii.

Begin this program by entering your birth date (like 4.121966 for April 12, 1966) and press DT1. If you want to see when your next "memorable" date is, then enter the current date and press DT2. Then press DT3. The program will search for the next date after or including DT2 for which the days-between-dates for that date and DT1 is a prime number. When it finds it, it will beep and display SOLUTION NOT FOUND. You should then RCL DT3 to see the lucky date.

Not a terribly useful program, especially if you don't believe in luck, but an interesting use of exiting a loop early on the 17bii.

Here are the program listings. These programs work on the HP-17b and HP-17bii but not on the HP-17bii+.

```Hi-Lo Game
HI~LO:IF(S(INIT):
L(G:0)x
L(N:IP(100xFP(1E4xSQRT(FP(CTIME)))))-INIT
:
0xL(G:G(G)+1)+
IF(GUESS=G(N):
G(G)
:
IF(GUESS<G(N):
0
:
99
)
)-EVAL
)
--------------------------------------------------------
Prime Day
PDAY:L(A:DDAYS(DT1:DT2:1))+IF(MOD(G(A):2)=0:L(A:G(A)+1):0)+
(I:G(A):G(A)+100:2:
L(P:1)+
(J:3:SQRT(I):2:
IF(MOD(I:J)=0:
L(P:0)
:
0
)
)+IF(G(P)=1:
L(DT3:DATE(DT1:I))+LOG(0)
:
0
)
)-DT3
```

Edited: 20 Jan 2012, 9:50 p.m.