Sphynx

# Sphynx for the HP-41

Overview

-"Sphynx" is a number guessing game.
-You have to find a mystery-number X
-After you've keyed in a guess N, the HP-41 displays  "N / d"  where  d = the sum of the digits of | X - N |

-For example, with N = 456789 and X = 259191, the HP-41 displays  "456789 / 39"  because | 259191 - 456789 | = 197598 and 1+9+7+5+9+8 = 39

-Exception:        if  d = 0 ( i-e  if  X = N ) , the calculator displays   "X // G"    where  G is the number of your guesses.

-In the following program, X is always a 6-digit number.
-It uses ATOX , ALENG and the CX-Function GETKEYX

-The program only stops when you've found the solution!
-After keying in your guess, press any key ( for instance ENTER^ ) except the numeric keys, CHS and the decimal point.

Program Listing

Data Registers:           •  R00 = r     ( random numbers )                       ( Register R00 is to be initialized before executing "SPHYNX" )

R01 = X    R02 = 0 , 1 , 2 , .... , G
Flags: /
Subroutines: /

-The append character is denoted  ~
-SST  line 58  in RUN mode to compile the GTO 03 before the first execution

 01  LBL "SPHYNX" 02  RCL 00 03  R-D 04  FRC 05  STO 00 06  9 E5 07  * 08  INT 09   E5 10  + 11  STO 01 12  0 13  STO 02 14  FIX 0 15  CF 29 16  LBL 01              17  X<> Z 18  ISG 02 19  CLX 20  ENTER^ 21  CLA 22  RCL 01 23  - 24  ABS 25  ARCL X 26  CLX 27  ALENG 28  CHS 29  48 30  * 31  ENTER^ 32  LBL 02              33  STO Y 34  ATOX 35  + 36  X#Y? 37  GTO 02 38  " "          39  ARCL Z 40  "~/"      41  X=0? 42  GTO 04 43  ARCL X 44  AVIEW 45  CLX 46  LBL 03              47  48         48  GETKEYX 49  X=0? 50  GTO 01 51  X<>Y 52  X<> L 53  - 54  X<>Y 55  10 56  * 57  + 58  GTO 03 59  LBL 04              60  "~/"     61  ARCL 02 62  FIX 4 63  SF 29 64  AVIEW 65  END

( 106 bytes / SIZE 003 )

 STACK INPUTS OUTPUTS X / /

Example:      1  STO 00

1st guess    123456  XEQ "SPHYNX"     "123456 / 24"        meaning  the sum of the digits of   | 123456 - X |  = 24
2nd guess    4 3 7 2 1 8       ENTER^        "437218 / 21"        meaning  the sum of the digits of   | 437218 - X |  = 21
3rd guess     3 6 6 2 0 1       ENTER^        "366201 // 3"        the program stops:  you've found the solution in 3 guesses

-Do not press the different digit keys too quickly.
-I let you find a good strategy, but much more than 3 guesses are usually necessary...
-"Sphynx" is probably not so interesting as the Mastermind, but it makes a little change.