Last Updated on June 17, 2022 by Ria Pathak
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; }
import java.util.Scanner; class PlayGanes2 { static void solve(int n) { String an=""; int ans=n%6; if(ans == 0|| ans ==1) { an="Friend"; } else { an="Arnab"; } an+='\n'; System.out.print(an); } public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t!=0) { int n=sc.nextInt(); solve(n); t--; } sc.close(); } }
def solve(n): an = "" ans = n % 6 if ans == 0 or ans == 1: an = "Friend" else: an = "Arnab" print(an) for _ in range(int(input())): n = int(input()) solve(n)
[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.