[SOLVED] Algothon- Tom and Jerry 9

20.00 $

Programming resource
Digital learning resource
Category:
Practical programming resource
Suitable for guided study and reference
Tutor guidance available when needed

Description

5/5 - (1 vote)

Tom and jerry are are playing a game with N candies. Tom always takes candies first, and the then two (tom and jerry) move in alternating turns. There are some rules as well,

  • Ina single move, one can get either 2,3 or 5 candies
  • If one can’t take any candies he looses the game

Given an amount of candies, find and print the name of the winner. Remember that tom and jerry are equally intelligent and play optimally.

Example 1

If there are 4 candies first way

  • Tom takes 3 candies
  • Then there are only 1 candy
  • Jerry can’t take any according to rules (one can take only or 5)
  • Tom wins second way
  • Tom takes 2 candies
  • Then there are 2 candies left
  • Jerry takes those 2 candies
  • No candies left for Tom
  • Tom wins since tom always takes cadies first he can select the first way and win

Answer – Tom

Input Format

Integer(Candies amount)

Constraints

Output Format

Print the name of the winner. Tom or Jerry

Sample Input O

Sample Output O

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.