*The Museum of HP Calculators*

#
NIM for the HP-12C

This program is by Paul Dale and is used here by permission.

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

This is the basic game of NIM.
To run it, f CLEAR PRGM (not in program mode), enter the number in the pile and press R/S. You and the calculator will take turns taking from 1 to 3 from the pile, whoever takes the last one loses. You know it is your turn when the pile's remaining count is displayed negative.

After you turn, the new pile count will display followed by the calculator's grab count.

Turn the calculator upside down at the end of the game.

##
Listing

01 STO 0
02 4 One more than the maximum that can be taken
03 STO 1
04 FIX 0
05* RCL 0 Start of main game loop
06 CHS
07 R/S Player's input
08 INTG
09 0
10 x<>y
11 x<=y? Player tried something too small
12 GTO 05
13 RCL 1
14 x<=y? Player tried something too large
15 GTO 05
16 x<>y
17 STO- 0
18 e^x
19 STO+ 02 Push some fuzzyness into our random number
20 0
21 RCL 0
22 x<=y? Has the player lost?
23 GTO 35
24 2
25 x<=y? Is there more than one left?
26 GTO 41
27 FIX 1 We lost!
28 3
29 5
30 0
31 7
32 .
33 1
34 GTO 00
35* 5 We won!
36 5
37 1
38 7
39 8
40 GTO 00
41* RCL 0 Display the adjusted total
42 PSE
43 1 Figure out our move
44 -
45 RCL 1
46 /
47 FRAC
48 RCL 1
49 *
50 x=0? Is the ideal count unachievable?
51 GTO 55
52* STO- 0 Adjust & display our grab
53 PSE
54 GTO 05
55* RCL 2 Generate a random selection
56 EEX
57 3
58 *
59 FRAC
60 RCL 2
61 EEX
62 5
63 /
64 +
65 FRAC
66 STO 2
67 RCL 1 Scale to proper range
68 1
69 -
70 *
71 1
72 +
73 INTG
74 GTO 52

Go back to the software library

Go
back to the main exhibit hall