The Museum of HP Calculators


An XOR Game for the HP-41

This program is Copyright © 2004 by Jean-Marc Baillard and is used here by permission.

This program is supplied without representation or warranty of any kind. Jean-Marc Baillard 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.

Overview

-The purpose of this game is to change the display from "----------"  ( ten "-" characters )  into "**********"  ( ten "*" characters )
-Pressing a numeric key ( from "1" to "9" ) followed by R/S changes some "-"  into "*" and some "*" into "-"
-The transformation is reversible.
-Actually, each operation is a logical eXclusive OR ( "-" beeing 0 and "*" beeing 1 ). The result is placed in the alpha register and displayed.
-If you find a solution, the HP-41 displays "**********" , you hear a BEEP and your number of tries is in registers X and R12.
-There is always ( at least ) one 4 keystroke solution which is stored in register R11.
-Finding a solution without pen and paper is quite a feat!

-The first "XOR" program uses 103 data registers.
-In case you have not enough room to execute SIZE 103 , "XOR2" is then listed ( it is a little bit slower but only 16 registers are used )
-Finally, "XOR3" is an easier version which displays 6 character strings , using only 5 numeric keys ( from "1" to "5" ) , with a solution in 3 keystrokes.


Program#1


Data Registers:    • R00 = random numbers ( this register is to be initialized before executing "XOR" )
                                  R01 to R10 correspond to the 10 displayed characters    R13 thru R22    correspond to the "1" key
                                  R11 = one solution                                                           -----------------------------------------
                                  R12 = the score = the number of guesses                         R93 thru R102  correspond to the "9" key
Flag:   F10
Subroutine:  /


001  LBL "XOR"
002  9
003  LBL 00
004  STO IND X
005  DSE X
006  GTO 00
007  STO 11
008  4
009  STO 12
010  9
011  LBL 01
012  STO Y
013  RCL 00                  All these programs use the same random number generator:   RCL 00  R-D  FRC  STO 00
014  R-D
015  FRC
016  STO 00
017  *
018  10
019  ST* 11
020  SIGN
021  +
022  RCL IND X
023  ST+ 11
024  X<> IND Z
025  STO IND Y
026  RDN
027  SIGN
028  -
029  DSE 12
030  GTO 01
031  102.012
032  STO 02
033  LBL 02
034  RCL 00
035  R-D
036  FRC
037  STO 00
038  ST+ X
039  INT
040  STO IND 02
041  DSE 02
042  GTO 02
043  10
044  STO 01
045  ST* 06
046  ST* 07
047  ST* 08
048  ST* 09  
049  12
050  ST+ 06
051  ST+ 07
052  ST+ 08
053  ST+ 09
054  LBL 03
055  SIGN
056  RCL IND 06
057  +
058  RCL IND 07
059  +
060  RCL IND 08
061  +
062  2
063  MOD
064  STO IND 09
065  DSE 06
066  DSE 07
067  DSE 08
068  DSE 09
069  DSE 01
070  GTO 03
071  2.01                      If you don't have an HP-41CX, replace lines 71-72 by   CLX  STO 02  STO 03  STO 04  STO 05  STO 06
072  CLRGX                                                                                                               STO 07  STO 08  STO 09  STO 10
073  LBL 04
074  SF 10
075  10
076  " "                         ( one space )
077  LBL 05
078  RCL IND X
079  X=0?
080  CF 10
081  X=0?
082  "~-"                      ( I mean:  append  - )
083  X#0?
084  "~*"                     ( append * )
085  X<>Y
086  DSE X
087  GTO 05
088  AVIEW
089  FS?C 10
090  GTO 07
091  STOP
092  AVIEW
093  10
094  *
095  12
096  +
097  10
098  LBL 06
099  RCL IND Y
100  RCL IND Y
101  +
102  2
103  MOD
104  STO IND Y
105  DSE Z
106  RDN
107  DSE X
108  GTO 06
109  SIGN
110  ST+ 12
111  GTO 04
112  LBL 07
113  RCL 12
114  BEEP
115  END

( 193 bytes / SIZE 103 )  


Example:    With     0.1883185174  STO 00

    XEQ "XOR"  49 seconds later ( t0 ) , the program stops and the HP-41 displays "----------"

   Press ( for instance )  1  R/S  the previous string is displayed again and 7 seconds later ( t1) , you'll see  "-*-*--***-"
                                    2  R/S  >>>>  "**--*-****"
                                    3  R/S  >>>>  "---**-*---"
                                    4  R/S  >>>>  "----**--*-"
                                    5  R/S  >>>>  "-*****--*-"
                                    6  R/S  >>>>  "---*****--"
                                    7  R/S  >>>>  "----*---*-"     from which we can gradually deduce the following informations:

-The 1st character is changed by    2 ; 3
-The 2nd -----------------------    1 ; 3 ; 5 ; 6
-The 3rd  -----------------------    5 ; 6
-The 4th  -----------------------    1 ; 2 ; 3 ; 4 ; 5 ; 7
-The 5th  -----------------------    2
-The 6th  -----------------------    4 ; 7
-The 7th  -----------------------    1 ; 4 ; 6 ; 7
-The 8th  -----------------------    1 ; 3 ; 6 ; 7
-The 9th  -----------------------    1 ; 3 ; 4 ; 6 ; 7
-The 10th ----------------------    2 ; 3

-We'll have a solution if all the 10 characters are changed an odd number of times, therefore we can try to "switch off"  4 ; 3 ; 1 ; 6:

      4  R/S  >>>>  "---****---"
      3  R/S  >>>>  "**--******"
      1  R/S  >>>>  "*--***---*"
      6  R/S  >>>>  "**********"  ( BEEP )  and  X = R12 = 11 = the number of our guesses. We have found one solution = 2-5-7

-In this example, we didn't have to press 8 or 9 but the HP-41 gives another solution in register R11 = 8-3-5-9.


Note:    -If you have an HP-41CX, lines 92-93 may be replaced with the 4 lines:  99  GETKEYX  48   -
               and you'll only have to press the numeric key ( without R/S ).


Program#2


Data Registers:    • R00 = random numbers  ( this register is to be initialized before executing "XOR2" )
                                  R01 to R09 correspond to the 9 numeric keys      R10 corresponds to the 10 displayed characters    R13 to R15: temp.
                                  R11 = one solution                                               R12 = the score
Flag:   F10
Subroutine:  /


001  LBL "XOR2"
002  9
003  LBL 00
004  STO IND X
005  DSE X
006  GTO 00
007  STO 11
008  4
009  STO 10
010  15
011  9
012  LBL 01
013  RCL 00
014  R-D
015  FRC
016  STO 00
017  RCL Y
018  *
019  10
020  ST* 11
021  SIGN
022  +
023  RCL IND X
024  ST+ 11
025  STO IND T
026  X<> IND Z
027  STO IND Y
028  RDN
029  SIGN
030  ST- Z
031  -
032  DSE 10
033  GTO 01
034  9
035  STO 10
036  LBL 02
037  10
038  ENTER^
039  CLX
040  LBL 03
041  10
042  *
043  RCL 00
044  R-D
045  FRC
046  STO 00
047  ST+ X
048  INT
049  +
050  DSE Y
051  GTO 03
052  STO IND 10
053  DSE 10
054  GTO 02
055  RCL IND 12
056  RCL IND 13
057  RCL IND 14
058  +
059  +
060  10
061  STO 10
062  SIGN
063  STO 12
064  CLX
065  STO IND 15
066  X<>Y
067  LBL 04
068  ENTER^
069  ENTER^
070  SIGN
071  +
072  2
073  MOD
074  RCL 12
075  *
076  ST+ IND 15
077  CLX
078  10
079  ST* 12
080  /
081  INT
082  DSE 10
083  GTO 04
084  CLX
085  STO 12
086  LBL 05
087  SF 10
088  10
089  " "                 ( one space )
090  RCL 10
091  LBL 06
092  ENTER^
093  ENTER^
094  2
095  MOD
096  X=0?
097  CF 10
098  X=0?
099  "~-"            ( append  - )
100  X#0?
101  "~*"           ( append * )
102  CLX
103  10
104  /
105  INT
106  DSE Y
107  GTO 06
108  AVIEW
109  FS?C 10
110  GTO 08
111  STOP
112  AVIEW
113  10
114  STO 13
115  SIGN
116  STO 14
117  CLX
118  X<> 10
119  RCL IND Y
120  +
121  LBL 07
122  STO Y
123  2
124  MOD
125  RCL 14
126  *
127  ST+ 10
128  CLX
129  10
130  ST* 14
131  /
132  INT
133  DSE 13
134  GTO 07
135  SIGN
136  ST+ 12
137  GTO 05
138  LBL 08
139  RCL 12
140  BEEP
141  END

( 208 bytes / SIZE 016 )


-This program is slower than "XOR":   t0 = 62 seconds ;  t1 = 11 seconds.
-The 10 characters are displayed in the reversed order but this doesn't change the strategy.


Program#3


Data Registers:    • R00 = random numbers  ( this register is to be initialized before executing "XOR3" )
                                  R01 to R06 correspond to the 6 displayed characters      R09 thru R14    correspond to the "1" key
                                  R07 = one solution                                                           -----------------------------------------
                                  R08 = the score                                                              R33 thru R38  correspond to the "5" key
Flag:   F10
Subroutine:  /


001  LBL "XOR3"
002  5
003  LBL 00
004  STO IND X
005  DSE X
006  GTO 00
007  STO 07
008  3
009  STO 08
010  5
011  LBL 01
012  STO Y
013  RCL 00
014  R-D
015  FRC
016  STO 00
017  *
018  10
019  ST* 07
020  SIGN
021  +
022  RCL IND X
023  ST+ 07
024  X<> IND Z
025  STO IND Y
026  RDN
027  SIGN
028  -
029  DSE 08
030  GTO 01
031  38.008
032  STO 02
033  LBL 02
034  RCL 00
035  R-D
036  FRC
037  STO 00
038  ST+ X
039  INT
040  STO IND 02
041  DSE 02
042  GTO 02
043  6
044  STO 01
045  ST* 03
046  ST* 04
047  ST* 05
048  8
049  ST+ 03
050  ST+ 04
051  ST+ 05
052  LBL 03
053  SIGN
054  RCL IND 03
055  +
056  RCL IND 04
057  +
058  2
059  MOD
060  STO IND 05
061  DSE 03
062  DSE 04
063  DSE 05
064  DSE 01
065  GTO 03
066  CLX
067  STO 02
068  STO 03
069  STO 04
070  STO 05
071  STO 06
072  LBL 04
073  SF 10
074  6
075  " "                         ( one space )
076  LBL 05
077  RCL IND X
078  X=0?
079  CF 10
080  X=0?
081  "~-"                      ( append  - )
082  X#0?
083  "~*"                     ( append * )
084  X<>Y
085  DSE X
086  GTO 05
087  AVIEW
088  FS?C 10
089  GTO 07
090  STOP
091  AVIEW
092  6
093  *
094  8
095  +
096  6
097  LBL 06
098  RCL IND Y
099  RCL IND Y
100  +
101  2
102  MOD
103  STO IND Y
104  DSE Z
105  RDN
106  DSE X
107  GTO 06
108  SIGN
109  ST+ 08
110  GTO 04
111  LBL 07
112  RCL 08
113  BEEP
114  END

( 178 bytes / SIZE 039 )  


Example:    With     1  STO 00  

  XEQ "XOR3" , 20 seconds later, the HP-41 displays  "------"
 
     1  R/S  >>>>  ( 5 seconds later )  "-*-**-"
     2  R/S  >>>>  "---**-"
     3  R/S  >>>>  "*-**--"
     4  R/S  >>>>  "-*-*-*"
     5  R/S  >>>>  "*--**-"   Similar arguments suggest to switch off  3 and 5

     3  R/S  >>>>  "--**--"
     5  R/S  >>>>  "******"  ( BEEP )  and  X = R08 = 7 guesses.

-We have found the solution  1-2-4  which is confirmed by register  R07 = 241.

Go back to the HP-41 software library
Go back to the general software library
Go back to the main exhibit hall