Play Games 2

CONCEPTS USED:

Game theory

DIFFICULTY LEVEL:

Easy.

PROBLEM STATEMENT(SIMPLIFIED):

Arnab wants to play games with his friend. He made a pile of chocolates and now he will take the first move and the players can remove chocolates of value 2,3,4 turn by turn. And if any person fails to take the chocolates, he will lose.

See original problem statement here

For Example :

Input
5
12 
20 
31 
33 
71 

Output
Friend
Arnab
Friend
Arnab
Arnab

OBSERVATION:

This is a simple observation question where you could clearly see that, if the remainder is 0 or 1,the friend loses.

Else Arnab.

SOLUTION:

#include <bits/stdc++.h>
using namespace std;

void solve(int n) 
{
   string an="";
    int ans = n%6;
    if(ans==0||ans==1)
       an="Friend";
    else
      an="Arnab";   

    an+='\n';

    cout<<an;
}

int main()
{  

  int t;
  cin>>t;
  while(t--)
  {
    int n;
    cin>>n;
    solve(n);
  }

return 0;
}

[forminator_quiz id="2339"]

So, in this blog, we have tried to explain the concept of Game Theory. If you want to solve more questions on Game Theory, which are curated by our expert mentors at PrepBytes, you can follow this link Game Theory.

Leave a Reply

Your email address will not be published. Required fields are marked *