MoHP The Museum of HP Calculators


Master Mind for the HP-29C

This program is Copyright © 1978 by Philippe Legros and is used here by permission. This program was originally a part of his personal HP-29c library. This program was transcribed by Philippe Legros.

This program is supplied without representation or warranty of any kind. Philippe Legros and The Museum of HP Calculators therefore assume no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof.

Description

The object of the game is for the player to guess an integer that the calculator has chosen. Information is given after each guess to tell the player how close his guess is to the hidden number. This number is specified by the user to be from 1 to 9 digits, where each digit can range from 1 to 9 also specified by the user. When the proper number is finally found, the number of guesses required to discover it is displayed.

After the program has been keyed in, a seed is asked for initializing the random number generator. This seed must be manually be stored in register .0 and could have any value between 0 and 1.

The game starts after the number of digits and its range have been introduced. As long as the hidden number is not found, the player enters his guesses. The returned output is always of the form 'a.b' where 'a' is the number of digits of the guess that exactly match digits in the hidden number both in value and location; 'b' is the number of digits of the guess that match digits of the hidden number in value, but not in location. Digits are not counted twice; that is, digits counted as 'a' digits are not counted again as 'b' digits.

For example, if the hidden number is '15221', a guess of '54321' would yield '2.1', meaning that 2 numbers (the '1' and '2') match exactly the hidden number, but that 1 number (the '5') is out of place.

Remarks

Instructions

STEP INSTRUCTIONS INPUT DATA KEYS OUTPUT DATA
1 Key in the program.      
2 Key in s, a seed for the random number generator (0≤s<1): s [STO] . 0 s
3 Key in d, the number of digits of the hidden number (1≤d≤9): d [ENTER↑] d
  And its range between 1 and r (1≤r≤9): r [GSB] 0 0.0
4 To find the hidden number, key in g, the guess number: g [R/S]  
5a If g wasn't correct, you have the following information: a=number of correct digits at the correct place, b=number of correct digits on a wrong place. Go back to step 4.     a.b
5b If g was correct, the games ends and you get n, the number of guesses you took. For a new game, go to step 3.     'd.0'   n

Example

KEYSTROKES        OUTPUTS       COMMENTS

 0 [STO] .0        0.00         Store initial seed
 4 [ENTER↑]        4.00         Initialise for a hidden number of 4 digits
 6 [GSB] 0         0.0            in the range between 1 and 6
 1111 [R/S]        1.0          1st guess: 1 correct digit correct place
 1222 [R/S]        0.1          2nd guess: 1 correct digit wrong place
 3133 [R/S]        0.2          3rd guess: 2 correct digits wrong place
 4341 [R/S]        1.1          4th guess: 1 correct digit correct place
                                  and 1 correct digit wrong place
 5315 [R/S]        2.0          5th guess: 2 correct digits correct place
 6316 [R/S]        '4.0'        6th guess: 4 correct digits correct place
                   6.             and number of guesses

The Program

LINE   CODE       KEYS      COMMENTS

 01  15 13 00   g LBL 0     Start label
 02     23 .2     STO .2    Store range r in R.2
 03        21     X⇔Y
 04     23 .1     STO .1    Store number of digits d in R.1
 05     23 00     STO 0     Initialize loop counter to d
 06        34     CLX
 07     23 .3     STO .3    Reset number of guesses g (R.3)
 08  15 13 09   g LBL 9
 09     24 .0     RCL .0    Random number generator
 10     15 73   g π
 11        51     +
 12     15 63   g x2
 13     15 62   g FRAC
 14     23 .0     STO .0    Store new s (R.0)
 15     24 .2     RCL .2
 16        61     ×
 17     14 62   f INT
 18        33     EEX
 19        51     +         Digit between 1 and R.2
 20     23 22     STO i     Store it in Rd, Rd-1... R1
 21        32     CHS       Compute digits position hidden number
 22     15 43   g 10x
 23        51     +
 24     15 23   g DSZ       Next digit?
 25     13 09     GTO 9     Yes, loop to step 08
 26  23 51 01     STO + 1   No, store digits position hidden number
 27        34     CLX       Clear display
 28  15 13 01   g LBL 1
 29  14 11 01   f FIX 1     Display to 1 decimals
 30        74     R/S       Wait for guess numbers
 31     23 .4     STO .4    Store current guess (R.4)
 32        33     EEX
 33  23 51 .3     STO + .3  g=g+1 (new guess)
 34        34     CLX
 35     23 .5     STO .5    Clear current result ab (R.5)
 36     24 02     RCL 2
 37     14 62   f INT
 38     23 02     STO 2     Reset digits position guess number
 39     24 .1     RCL .1
 40     23 00     STO 0     Initialize loop counter to d
 41  15 13 08   g LBL 8
 42     24 22     RCL i     Recall hidden digit d, d-1... 1
 43     14 62   f INT
 44     24 .4     RCL .4    Extract guess digit d, d-1... 1
 45     14 62   f INT
 46        33     EEX
 47        01     1
 48  23 71 .4     STO ÷ .4
 49        71     ÷
 50     15 62   g FRAC
 51        33     EEX
 52        01     1
 53        61     ×
 54     14 61   f X≠Y       Hidden digit=guess digit?
 55     13 07     GTO 7     No, branch to step 59
 56        09     9         Yes, add 1 correct digit correct place to ab
 57  23 51 .5     STO + .5
 58        22     R↓
 59  15 13 07   g LBL 7
 60        32     CHS       Compute digits position guess number
 61     15 43   g 10x
 62  23 51 02     STO + 2   Store digits position guess number
 63     15 23   g DSZ       Next digit?
 64     13 08     GTO 8     Yes, loop to step 41
 65     24 .2     RCL .2
 66     23 00     STO 0     Initialize loop counter to r
 67     24 02     RCL 2     Recall digits position guess number
 68     24 01     RCL 1     Recall digits position hidden number
 69  15 13 06   g LBL 6
 70     15 62   g FRAC      Extract hidden position r, r-1... 1
 71        33     EEX
 72        01     1
 73        61     ×
 74        21     X⇔Y
 75     15 62   g FRAC      Extract guess position r, r-1... 1
 76        33     EEX
 77        01     1
 78        61     ×
 79     14 51   f X>Y       Correct digit wrong place=minimum
 80        21     X⇔Y       between both positions r
 81        31     ENTER↑
 82     14 62   f INT
 83  23 51 .5     STO + .5  Add it to ab
 84        22     R↓        Restore stack for next extraction
 85     15 23   g DSZ       Next range?
 86     13 06     GTO 6     Yes, loop to step 69
 87     24 .1     RCL .1    No, recall d (answer if hidden number=guess number)
 88     24 .5     RCL .5    Compute a.b=ab/10
 89        33     EEX
 90        01     1
 91        71     ÷
 92     14 61   f X≠Y       Correct number?
 93     13 01     GTO 1     No, go to step 28 for next guess
 94     14 74   f PAUSE     Yes, pause d.0 answer
 95     24 .3     RCL .3    Then display g, number of guesses
 96  14 11 00   f FIX 0     Set decimals to 0
 97     15 12   g RTN       End of game.

Register Use

 R0 = indirect / loop control
 R1 = d1.digits position (hidden number)
 R2 = d2.digits position (guess number)
 R3 = d3
 R4 = d4
 R5 = d5
 R6 = d6
 R7 = d7
 R8 = d8
 R9 = d9
 R.0 = seed (0≤s<1)
 R.1 = number of digits (1≤d≤9) R.2 = digit range (1≤r≤9)
 R.3 = number of guesses
 R.4 = current guess
 R.5 = ab, current result
 

GTO Go back to the software library
GTO Go back to the main exhibit hall