a. You have arranged a party to celebrate 31 December 2020 and you have invited all your friends. To make the party successful, you came up with an interesting game called “Happy New Year”. There are few rules in the game: i. All the members that will play the game must sit in a circular manner. ii. There will be two coins, which will determine the faith of the player. iii. If the both coins after flipping get ‘Heads’ or ‘Tails’ or viceversa, the player has to pass the coin to the next player (sitting to his/her right). iv. If one coin after flipping gets ‘Tails’ and the other gets ‘Heads’, the player gets eliminated and passes the coin to the next player (sitting to his/her right). v. The game continues until there is only one member left and he/she will get a surprise gift. Write a method that finds out the winner of the ‘Happy New Year’ game, you will be given as input the number of players playing and the coin sequences. [You must use recursion for solving this problem.]
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
a. You have arranged a party to celebrate 31 December 2020 and you have invited all your
friends. To make the party successful, you came up with an interesting game called “Happy
New Year”. There are few rules in the game:
i. All the members that will play the game must sit in a circular manner.
ii. There will be two coins, which will determine the faith of the player.
iii. If the both coins after flipping get ‘Heads’ or ‘Tails’ or viceversa, the player has to pass
the coin to the next player (sitting to his/her right).
iv. If one coin after flipping gets ‘Tails’ and the other gets ‘Heads’, the player gets
eliminated and passes the coin to the next player (sitting to his/her right).
v. The game continues until there is only one member left and he/she will get a surprise
gift.
Write a method that finds out the winner of the ‘Happy New Year’ game, you will be given as input the
number of players playing and the coin sequences. [You must use recursion for solving this
problem.]
Please ans it asap, it’s urgen.. Tia
Step by step
Solved in 2 steps with 1 images