Arjun and babu are friends, they are playing the matchstick game. in this game, a group of matchsticks is placed on the floor. the players can pick any number of matchsticks from 1 to 4 (both inclusive) during their chance. the player who takes the last match stick wins the game. if arjun starts first, how many matchsticks should he pick such that he is guaranteed to win the game? write a suitable program to help arjun. note : consider the game is played optimally. input format total number of matchsticks output format number of match sticks arjun should pick for a guaranteed win. if it is not possible for arjun to win, dispaly "you are a loser"
Answers
Language used : Python Programming
NOTE : The question would have been more easier to understand if you have given the sample test case. So, here we are, solving it over the remaining picks picking first optimization, giving start kick to Arjun.
Program :
n=int(input("Enter the total no.of matchsticks present in the game :"))
count=1
srt=""
quo=n//4
rem=n%4
if rem==0:
#game starts with arjun, taking 4 sticks.
while(n!=0):
if count%2!=0:
if count==1:
n=n-4
print("Arjun starts by picking 4 sticks")
count+=1
str="arjun"
else:
n=n-int(input("Arjun : "))
count=count+1
str="arjun"
else:
n=n-int(input("Babu : "))
count=count+1
str="babu"
print("matchsticks remaining :", n)
else:
#Helping arjun with remainder picks picking first, giving max next to 4.
while(n!=0):
if count%2!=0:
if count==1:
print("Arjun starts with picking", rem," sticks")
n=n-rem
count+=1
str="arjun"
else:
n=n-int(input("Arjun : "))
count=count+1
str="arjun"
else:
n=n-int(input("Babu : "))
count=count+1
str="babu"
print("matchsticks remaining :", n)
if str=="arjun":
print("Arjun! You are a winner")
else:
print("Arjun! You are a loser")
TEST CASES :
CASE 1 : (Giving headstart by remainders to Arjun and he wins by his next inputs)
Enter the total no.of matchsticks present in the game :11
Arjun starts with picking 3 sticks
matchsticks remaining : 8
Babu : 4
matchsticks remaining : 4
Arjun : 4
matchsticks remaining : 0
Output :
Arjun! You are a winner
CASE 2 : (Giving headstart by remainders to Arjun and still he loses by his next inputs)
Enter the total no.of matchsticks present in the game :11
Arjun starts with picking 3 sticks
matchsticks remaining : 8
Babu : 3
matchsticks remaining : 5
Arjun : 1
matchsticks remaining : 4
Babu : 4
matchsticks remaining : 0
Output :
Arjun! You are a loser
CASE 3 : (Sticks present are multiple of 4 in number. Arjun starts by 4)
Enter the total no.of matchsticks present in the game :12
Arjun starts by picking 4 sticks
matchsticks remaining : 8
Babu : 1
matchsticks remaining : 7
Arjun : 2
matchsticks remaining : 5
Babu : 4
matchsticks remaining : 1
Arjun : 1
matchsticks remaining : 0
Output :
Arjun! You are a winner
Learn more :
1) Printing all the palindromes formed by a palindrome word.
brainly.in/question/19151384
2) Indentation is must in python. Know more about it at :
brainly.in/question/17731168
3) Write a Python function sumsquare(l) that takes a nonempty list of integers and returns a list [odd,even], where odd is the sum of squares all the odd numbers in l and even is the sum of squares of all the even numbers in l.
brainly.in/question/15473120
4) Python program to find absolute difference between the odd and even numbers in the inputted number.
brainly.in/question/11611140