having fun with the HP-17b - 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: having fun with the HP-17b (/thread-185590.html) having fun with the HP-17b - Don Shepherd - 06-07-2011 How about a "guess the number 0-99" program for the 17b (and 17bii) solver. At first glance, you would think it might not be possible due to: lack of a random number function, lack of alpha messages to tell you if you are too high or too low, and lack of a "beep" instruction when you correctly guess the number. Plus, the 17b is not programmable, right? Lack of random number function is overcome by using current time (minutes, seconds) and the MOD function. Lack of alpha capability is overcome by returning -1 if your guess is too low and 1 if it is too high (yes, it's not ideal, but it works). A "beep" is generated by doing a Log(0) which generates an error message and halts evalution of the equation (AFTER saving the number of guesses in variable GUESS so it can be recalled). The equation works on the 17b and 17bii. It mostly works on the 17bii+ except the number of guesses is wrong due to the way the solver in the 17bii+ works (or doesn't work, actually). ``` IF(S(INIT): L(G:0)X L(N:MOD(10000XFP(CTIME)X111:100)) -INIT : 0XL(G:G(G)+1)+ IF(GUESS=G(N): L(GUESS:G(G))+ LOG(0) : IF(GUESS>G(N):1:-1) ) -EVAL ) ``` Press INIT a couple of times (not sure why that is necessary) then enter your guess and press GUESS. Then press EVAL to evaluate your guess: -1 means you are too low, 1 means you are too high, and a beep means you guessed the number so do a RCL GUESS to see the number of guesses it took. What is the maximum number of guesses it should take to identify the number from 0 to 99? Edited: 7 June 2011, 8:31 p.m. after one or more responses were posted Re: having fun with the HP-17b - Gerson W. Barbosa - 06-07-2011 Quote: What is the maximum number of guesses it should take to identify the number from 0 to 99? 7? (100 LN 2 LN /) Re: having fun with the HP-17b - Don Shepherd - 06-07-2011 yup! Re: having fun with the HP-17b - Gerson W. Barbosa - 06-07-2011 Implementing the TI 58/59 game described below on an RPN HP calculator is trivial. Now doing it on the HP-17B is not. Congratulations! From the TI Programmable 58/59 Master Library Manual, page 77: ```HI-LO GAME ML-21 In addition to recreational diversion, this program serves as a nontechnical demonstration of the library module. The game is easy to play, permitting almost immediate hands-on experience for any user. The object of the game is to guess a secret number (whole numbers only) from 1 to 1023 that has been generated in the calculator. The calculator responds with a "too high," "too low," or "correct" indica- tion to each of your guesses. Your score (number of guesses) is tallied by the calculator. Also, you may select a number in the range 1 to 1023 and the calculator will attempt to guess this number as you supply proper responses to each of its guesses. When the calculator has found the num- ber you selected, its score will be displayed. An exercise which often cast doubt on the "man over machine" axiom is to have the calculator guess the same number that it generated for you to guess. Now, follow the User Instructions and seed if you can uphold the superiority of man. USER INSTRUCTIONS STEP PROCEDURE ENTER PRESS DISPLAY 1 Select program 2nd Pgm 21 You Guess 2 Key in number (0 to 199017)* Number A Number 3 Generate secret number B 0. 4 Enter your guess (1 to 1023) Guess C Clue Clue: -1. if guess was low 1. if gues was high flashing 0. if your guess was correct 5 Repeat Step 4 as required 6 Display score D Score 7 For a new number, go to Step 3 Calculator Guesses 8 Select a number (1 to 1023) 9 Display calculator's first guess 2nd A' Calc. guess 10 If calculator's guess is Low 2nd B' Calc. guess High 2nd C' Calc. guess Correct 2nd D' Calc. guess 11 Repeat Step 10 as required 12 For a new game, go to Setp 8 *Each number you select will produce a different game. ``` Re: having fun with the HP-17b - Don Shepherd - 06-07-2011 The 17b solver is not the best platform for this particular game, I just wanted to see if it could be done in a way that wasn't too horrible. It is more intuitive on a regular RPN calculator; for example, you enter your guess and press R/S and it immediately tells you "too high" or "too low" (on models like the 30b that have alpha messages). The 17b requires another keypress to get that feedback. I like to discuss this problem with my students. They are always kind of amazed that a maximum of only 7 guesses can identify a selected number from 0 to 99 when I show them the advantages of splitting the groups in half each time, thus narrowing down the potential set of numbers. It kind of makes math interesting, if only for a moment! Hi-Lo Game with an interesting twist - Namir - 06-07-2011 I have used the hi-low guessing games in many programmings books that I wrote way back. I would present various versions, each a bit more sophisticated than the previous one. One interesting (and cunning) variation of the hi-low game is the percent of reliability for the feedback. Normally, the program would reliably tell you if your guess is higher or lower than the secret number. This special variant would introduce a level of doubt (say 10%) in that kind of answer, making thinks a bit more interesting. Namir Edited: 7 June 2011, 7:49 p.m. Re: Hi-Lo Game with an interesting twist - Gene Wright - 06-07-2011 I think "Jive Turkey" was the name the TI user group put on that variety of Hi-Lo game. Re: having fun with the HP-17b - Gerson W. Barbosa - 06-07-2011 Quote: They are always kind of amazed that a maximum of only 7 guesses can identify a selected number from 0 to 99 when I show them the advantages of splitting the groups in half each time, thus narrowing down the potential set of numbers. In the example at the next page in the TI manual the program is asked to find a secret number, 848. The program's guesses, following the user's correct clues, are 512, 768, 896, 832, 864 and 848, that is, 512, 512+256, 512+256+128, 512+256+128-64, 512+256+128-64+32 and 512+256+128-64-16. That's the principle behind the binary search algorithm. Once I used this technique to find a fault in an 800-meter long circuit in four or five steps. The idea occurred to me from having played this little game. Thanks for bringing it back :-) Re: Hi-Lo Game with an interesting twist - Gerson W. Barbosa - 06-07-2011 Quote: I would present various versions, each a bit more sophisticated than the previous one. Namir, Would you mind posting a couple of listings here? Thanks! Gerson. Re: Hi-Lo Game with an interesting twist - Namir - 06-07-2011 Here is a QBasic listing (also runs on 64-bit QB64): ```REM Hi-LO GUESSING GAME DIM Num AS INTEGER, Guess AS INTEGER DIM Iter AS INTEGER, MaxIter AS INTEGER DIM Trust AS DOUBLE RANDOMIZE TIMER MaxIter = 10 Num = INT(1000 * RND(1) + 1) Iter = 0 INPUT "Enter feedback trust (%) "; Trust Trust = Trust / 100.0 DO INPUT "Enter Guess"; Guess Iter = Iter + 1 IF Trust > RND(1) THEN REM TRUE FEEDBACK IF Guess > Num THEN PRINT "Your guess is high" ELSEIF Guess < Num THEN PRINT "Your guess is low" ELSE PRINT "You guess it!" END IF ELSE REM MISLEADING FEEDBACK!! REM (unless you guess the secret number) IF Guess < Num THEN PRINT "Your guess is high" ELSEIF Guess > Num THEN PRINT "Your guess is low" ELSE PRINT "You guess it!" END IF END IF LOOP UNTIL Num = Guess OR Iter > MaxIter IF Iter <= MaxIter THEN PRINT "Solved it in "; Iter; " guesses" ELSE PRINT "Time out! Secret number is "; Num END IF ``` Edited: 8 June 2011, 12:22 a.m. after one or more responses were posted Re: Hi-Lo Game with an interesting twist - Gerson W. Barbosa - 06-07-2011 Runs nicely! Thank you! Re: having fun with the HP-17b - Don Shepherd - 06-08-2011 Well, a little testing with VBScript has determined that the method I used to generate a random number between 0 and 99 is totally unacceptable. Whole series of numbers, such as 1-4, 12-15, 23-26, etc., are never generated by that method. So I came up with a new method using the first 2 digits of the fractional part of the square root of mmss returned by the CTIME function, and that method does generate every number from 0 to 99 in a more or less random method, good enough for an entertainment program. This is the new program: ``` IF(S(INIT): L(G:0)X L(N:IP(100XFP(SQRT(10000XFP(CTIME))))) -INIT : 0XL(G:G(G)+1)+ IF(GUESS=G(N): L(GUESS:G(G))+ LOG(0) : IF(GUESS>G(N):1:-1) ) -EVAL ) ``` Re: having fun with the HP-17b - Marcus von Cube, Germany - 06-10-2011 The 20b SDK by Cyrille and Tim is designed just around this game. :-)