Problem 1481. Game of Nim
The Game of Nim is a famous studied 2 player strategy game. http://en.wikipedia.org/wiki/Nim
There are 3 heaps, and you are given the number of pebbles in each heap. Player 1 and 2 take turns removing pebbles from each heap. Game ends when a player cannot remove any pebbles from any heap, and the last player able to do so is the winner.
Given the number of pebbles in each heap, determine if player-1 will win assuming that both player play their optimal strategy, ie their best possible moves.
Solution Stats
Problem Comments
-
2 Comments
For the test case [7 7 7] all of [1 7] [2 7] [3 7] should be valid responses, right? Also you don't have any test cases where the game is not winnable.
Isn't the answer supposed to be a binary output?
Solution Comments
Show commentsGroup

Board Games I
- 16 Problems
- 21 Finishers
- The Tower of Hanoi
- hanoi towers II
- Eight Queens Solution Checker
- N-Queens Checker
- Wheat on a chessboard pt 1
- Wheat on a chessboard pt 2
- Identify Reachable Points
- Valid Chess Moves
- Chess probability
- Chess performance
- Chess ELO rating system
- Pentago: find winning move
- Go-style solver
- Game of Nim
- RISK board game battle simulation
- RISK Calculator - Large Armies, High Accuracy, Fast
Problem Recent Solvers34
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!