[SOLVED] Algothon Assignment 2-Tom and Jerry 9

30.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon Tom-and-Jerry-9-dvuhu6.zip (210.4 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
πŸ”’ Securely Powered by:
Secure Checkout
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

  • Tom-and-Jerry-9-dvuhu6.zip