Skip to the content of the web site.

Project M.6: Nim

The word "nimm" is the German word for "take". The game of Nim involves there being a number of piles, and on each turn the player or the computer takes 1 or more items from one of the piles. The objective is to be the one to take the last item.

Give each pile a letter, and indicate the number of items on the pile by a sequence of asterisks. A move is indicated by a pile identifier and an integer.

Do you wish to start (y/n)? y

A *****
B ****
C ***

Your move ("!" to give up): B2

A *****
B **
C ***

My move: B1

A *****
B *
C ***

Your move ("!" to give up):

You should ignore upper case or lower case, a player must take at least one item from a pile, and you should implement the winning strategy for your program.