Join Stack Overflow to learn, share knowledge, and build your career. Connect and share knowledge within a single location that is structured and easy to search. I noticed in arriving at the above solution that I was using a recursive thought process, so rather than writing a program that just used the modulo operator, I want to write a recursive version that tells me whether I can win, and also what move to make at each step. I've made a start with the Python code below, but am stuck on how to print the instruction for how many stones to take at each step.
Combinatorial Game Theory | Set 2 (Game of Nim) - GeeksforGeeks
Some games are all about luck. Your winning chance depends on the roll of a die or the cards you've been dealt. But there are other games that are only about strategy: if you play cleverly, you're guaranteed to win. A great example of this is the ancient game of Nim.
Join Stack Overflow to learn, share knowledge, and build your career. Connect and share knowledge within a single location that is structured and easy to search. The idea for this program is to play a game of Nim.
In this program you are to allow the user to play this game with the computer. The game starts with an initial number of marbles, which your program decides, and determines at random who goes first, and then the user and the computer take turns. The player who goes gets a chance to draw a certain number of marbles which must be at least one and no greater than half of the current number of marbles.