- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this game, there are two players X and Y. our task is to predict who will win the game if both play optimally and X starts the game.

**Game**

In the coin game, there are two piles with N and M number of coins. One of the players chooses any one of the piles for the game. Then the task is to divide the piles into two halves till any one player cannot further divide the piles.

Let’s take an example to understand the problem,

Input: M = 2 , N = 2 Output:X

**Explanation **- X starts the game and choose M pile(both are same), and divide the pile into two. Now each will contain only one coin, so Y will be left with no move. This will make X win.

To solve this problem, we need to see the chances that player X wins. The case in which player X wins is when any of the piles will have an even number of coins. Otherwise, Y will be the winner.

Program to show the implementation of our logic

#include <iostream> using namespace std; int isXWinner(int M, int N) { if (M % 2 == 0 || N % 2 == 0) return 1; return 0; } int main() { int M = 1, N = 2; cout<<"Game Starts!\n"; if(isXWinner(M,N)) cout<<"Player X is the Winner"; else cout<<"Player Y is the Winner"; return 0; }

Game Starts! Player X is the Winner

- Related Questions & Answers
- Predict the Winner in C++
- Predict the winner of the game on the basis of the absolute difference of sum by selecting numbers in C++
- Program to find winner of stone game in Python
- Program to find winner of array removal game in Python
- Program to find winner of number reducing game in Python
- Program to find the winner of an array game using Python
- Program to find winner of a rower breaking game in Python
- Program to find winner of a rower reducing game in Python
- Coin Path in C++
- Program to find winner of a set element removal game in Python
- Coin Change 2 in C++
- Find the winner of a game where scores are given as a binary string in Python
- Python program to find score and name of winner of minion game
- C Program Coin Change
- Stone Game in C++

Advertisements