I first encountered the game of Nim in my first semester as an undergraduate here at UIUC, Fall 1994, in a MATH 198 Freshman Seminar course with the current department chair, Professor Dan Grayson. We spent two to three weeks working on the Nim problem, and we managed as a class to come up with a winning strategy for most starting positions. What we came up with is actually well-known to those familiar with the game.
For several years, I could not remember what we'd come up with, only remembering something about an obscure bitwise operator buried in my calculator having something to do with it. On the second day of the Spring 2005 semester, over ten years later, I ran across Nim again in a MATH 413 class with Professor Alexandr Kostochka. As he presented the strategy in lecture, I remembered having come up with it with my classmates ten years earlier. It was conducive even then to calculator work; now it seems conducive to writing a block of code.
Nim is a game for two players. The game involves piles of counters; each pile contains a finite positive integer number of counters, and there is a finite positive integer number of piles. On each player's turn, she takes any number of counters (at least one) from exactly one pile (possibly leaving as few as zero in that pile). Players alternate turns. The object is to be the player who takes the last counter.
This page allows the user to enter the current state of a game of Nim with an arbitrary (user-specified) number of piles. As the user changes the size of each pile, the code executes and calculates winning moves. If there are no winning moves, the page states that; otherwise, the page will list all possible winning moves as the number of counters to reduce a pile to. A given board may have more than one winning move; those will be listed separately (remember, the rules only allow reducing one pile each turn).