^ma1 80^pl-66 0 6^ce NIM for HP-41 or HP-71 ^ju^sk^pa5 Nim is a game for two persons played as follows. There is an arbitrary number of piles of counters, each containing an arbitrary number of counters. Each player in turn chooses one pile and takes one or more counters from it; he must take at least one, and may take any number up to the number in that pile. The player taking the last counter wins. ^sk^pa These programs provide for two players playing each other, or one player playing against the computer, or the computer playing against itself. The number of piles is limited to 3, 4, or 5; 3 being the smallest number to provide a reasonable game and 5 being the largest to comfortably fit in the display. Also partly for reasons of display, the number of counters in a pile is limited to 99. ^sk^pa In the following notes on the two programs, I won't bother to say that each input for the HP-41 is followed by R/S, and that a multicharacter input for the HP-71 (with cursor blinking) is followed by ENDLINE while a single character response (no cursor) requires just the single keystroke. ^sk(1) To start, (41) XEQ "NIM" (71) RUN NIM or CALL NIM. ^sk0(2) (41) supply any number (not necessarily a fraction) as random number seed. ^sk0(3) Requires 2, 1, or 0, according to whether there are two players playing each other, one player against the computer, or computer against itself. ^sk0(4) (71) Supply the name of the player, or of each player. (The 41 names them A and B.) ^sk0(5) If the player named is to play first, press Y (for yes); otherwise N (for no). ^sk0(6) Press 3, 4, or 5, to say how many piles you want. ^sk0(7) Reply Y or N for automatic set up. ^sk0(8a) If Y, when asked supply a maximum number. The computer will then choose a number at random between 1 and the maximum as the number of counters in each pile. ^sk0(8b) If N, the computer asks you for the number to go in each pile. ^sk0(9) The computer shows the game position, the number of counters in each pile and who is to move. ^sk0(10a) If it is the computer's move, the position is shown for just a second or two and then the computer works out its move, shows it and unless the last counter is taken returns to (9). ^sk0(10b) If a player's move, the game position is held indefinitely while he decides his move. On deciding, press (41) R/S (71) any key, and when asked supply the pile number and the number of counters to take. Then unless the last counter has been taken, the computer returns to (9). ^sk0(11) If the last counter has been taken, the computer shows the winner's name (or where the 71 beats a player, the loser's name). You are then asked if you want another game. If Y, the computer returns to (3); if N, the program ends and (71) settings of flags, display, etc. are returned to what they were before the program was started. ^sk^pa The computer plays a perfect game; that is, if there is a wining move it will play it; if there is no winning move it makes a random move. I suggest you start with a reasonably simple game, 3 piles with respectively 3, 4, and 5 counters. ^sk^ce Bob Laughton