The Museum of HP Calculators


Flip-Flop for the HP-41C

This program was first published in the HP-41C Users' Library Solutions: Games by Hewlett-Packard and is used here by permission.

This program is supplied without representation or warranty of any kind. Hewlett-Packard Company 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

Flip-Flop challenges you to change a string of 8 zeroes and 1 one (.000010000) to 1 zero and 8 ones (,111101111). Only positions containing ones can be specified for flipping. Flipping a one to a zero will automatically flip adjacent zeroes to ones and ones to zeroes. Flipping a one in either end position will flip the opposite end as well as the adjacent position.

Positions are: previous move, 123456789. Note that the position to the left of the comma always shows the last move unless the last move tried to flip a zero, at which time it will show zero.

Instructions

Step

Instructions

Input Data/Units

Keys

Output Data/Units

1

Enter program

     

2

Initialize

 

[XEQ] FLIP 

0,000010000

3

Key in position to flip.

x

 

(x),(    )

 

 

 

 

 

 

Repeat step 3 until successful.

 

 

 

Example

   Keystrokes:          Display:
[XEQ] [ALPHA] SIZE 
[ALPHA] 013
[XEQ] 
[ALPHA] FLIP [ALPHA]    0,000010000
5                       5,000101000
6                       6,000110100
5                       5,000001100
.                       .
.                       .
.                       .

The Program

LINE  KEYS
 01 <>LBL "FLIP"        Initialize
 02  CF 28
 03  FIX 9
 04  CLRG
 05  9
 06  STO 12
 07 <>LBL 00
 08  10
 09  RCL 12
 10  CHS
 11  Y^X
 12  STO IND 12
 13  DSE 12
 14  GTO 00
 15  RCL 05
 16  STO 00
 17  CHS
 18  STO 05
 19 <>LBL 01
 20  RCL 00
 21  .111101111
 22  X<>Y
 23  X=Y?
 24  GTO 02
 25  RCL 10
 26  +
 27  XEQ 05
 28 <>LBL 03
 29  STO 12
 30  STO 10
 31  XEQ 07
 32  ISG 11
 33 <>LBL 10
 34  CHS
 35  STO IND 12         Update
 36  ST- 00
 37  9
 38  RCL 12
 39  X=Y?
 40  GTO 09
 41  1
 42  X=Y?
 43  GTO 04
 44  ISG 12
 45 <>LBL 10
 46  RCL IND 12
 47  CHS
 48  STO IND 12
 49  ST- 00
 50  DSE 12
 51  DSE 12
 52  RCL IND 12
 53  CHS
 54  STO IND 12
 55  ST- 00
 56  GTO 01
 57 <>LBL 09
 58  RCL 01
 59  CHS                Right end
 60  STO 01
 61  ST- 00
 62  RCL 08
 63  CHS
 64  STO 08
 65  ST- 00
 66  GTO 01
 67 <>LBL 04
 68  RCL 02             Left end
 69  CHS
 70  STO 02
 71  ST- 00
 72  RCL 09
 73  CHS
 74  STO 09
 75  ST- 00
 76  GTO 01
 77 <>LBL 05
 78  CF 22
 79  VIEW X
 80 <>LBL 06
 81  PSE                Input loop
 82  FS?C 22
 83  RTN
 84  GTO 06
 85 <>LBL 07
 86  RCL IND 12         Valid?
 87  X<0?
 88  RTN
 89  RCL 00
 90  VIEW X
 91  XEQ 06
 92  GTO 03
 93 <>LBL 02
 94  RCL 10
 95  +                  Game over
 96  VIEW X
 97  PSE
 98  CLA
 99  FIX 0
100  CF 29
101  SF 28
102  ARCL 11
103  "|- FLIPS"
104  AVIEW
105  .END.

Register Use

R00  Current Display
R01  Used
R02  Used
R03  Used
R04  Used
R05  Used
R06  Used
R07  Used
R08  Used
R09  Used
R10  Used
R11  # of flips
R12  Counter

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