Possible Duplicate:
Winning strategy for a matchstick game
The rules of this variant of Nim are as follows: Starting at zero, each player counts up between 1-N numbers. The person that counts a number L loses. N and L are declared at the start of the game by one player, the other player chooses who goes first.
For example, a game where N=2, L=9 might go like this:
P1: 1, 2 P2: 3 P1: 4, 5 P2: 6, 7 P1: 8
I'm trying to find an algorithm that can win the game for any value of N and L. So far, I've come up with the following.
c = current number if going first: while L-c > N: count n numbers once L-c <= N: count (L-c) numbers
Is there a better way of doing this?