There are two players P1 and P2 and two piles of coins consisting of M and N coins respectively. At each turn, a player can choose only one of the piles out of these and discard the other one. This discarded pile cannot be used further in the game. The pile player chooses is further divided into two piles of non zero parts. The player who cannot divide the pile i.e. the number of coins in the pile is < 2, loses the game. The task is to determine which player wins if P1 starts the game and both the players play optimally.
Input: M = 4, N = 4
Output: Player 1
Player 1 can choose any one of the piles as both contain the same number of coins
and then splits the chosen one (the one which is not chosen is discarded) into two piles with 1 coin each.
Now, player 2 is left with no move (as both the remaining piles contain a single coin each
which cannot be split into two groups of non-zero coins).
Input: M = 1, N = 1
Output: Player 2
There’s no move to make.
Approach: Simply check if any of the pile consists of even number of coins. If yes then Player 1 wins else Player 2 wins.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Predict the winner of the game | Sprague-Grundy
- Predict the winner of the game on the basis of absolute difference of sum by selecting numbers
- Predict the winner of a card game of removing K cards in each turn such that Bitwise AND of K and size of pile is 0
- Game Theory (Normal-form game) | Set 3 (Game with Mixed Strategy)
- Game Theory (Normal-form Game) | Set 6 (Graphical Method [2 X N] Game)
- Game Theory (Normal-form Game) | Set 7 (Graphical Method [M X 2] Game)
- Coin game of two corners (Greedy Approach)
- Find the player who will win the Coin game
- Optimal Strategy for a Game | Special Gold Coin
- Find the winner in nim-game
- Find the winner of the Game to Win by erasing any two consecutive similar alphabets
- Find the winner of the game with N piles of boxes
- Find the winner of the Game
- Winner in the Rock-Paper-Scissor game using Bit manipulation
- Determine winner of the Game by arranging balls in a row
- Find the winner of a game of removing any number of stones from the least indexed non-empty pile from given N piles
- Determine the winner of a game of deleting Characters from a String
- Combinatorial Game Theory | Set 2 (Game of Nim)
- Game Theory (Normal - form game) | Set 1 (Introduction)
- Game Theory (Normal-form Game) | Set 4 (Dominance Property-Pure Strategy)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.