Programming Geek
Rated 4.1/5 based on 446 reviews

CodeVita 2016 Round 2 Question: Game of Marbles


Problem : Games of Marbles



Statement

Darrell and Sally are two best friends. They had a large collection of marbles. They devised a game with it to play in their free time which will also help them to improve their math. One of them will have to select a certain number of marbles and give a hint to find the number. The other will have to guess the first number that matches the given criteria and vice versa.

Your task is to act as a judge for this game. When the player finds the answer, you will have to verify the answer. If answer is right, add 10 points to that player. If the player passes the question, you will have to give the right answer (no change in points in this case). You should also announce the winner at the end of the game.

Hint to find the number:

When the marbles are put into a group of x1, x2, x3,...(where x1, x2, x3 can be any number from 1 to 100), it falls into a perfect group.(No marble is left without a group).

Example: - When Darrell says the number falls into a perfect set when she groups them into sets of 3 and 5, the answer could be 15 or 30 and so on. Since the first number that matches the criteria is 15, 15 will be the answer.(Explanation: when 15 marbles is put into groups of 3, We will get 5 sets of 3 marbles each and when it is put into groups of 5, we will get 3 sets of 5 marbles each. For 16 marbles, we will get 5 sets of 3 marbles each and one marble will be left without a proper group. So 16 cannot be the answer)




NOTE: - Please have a look at Sample Input and Output before you read the Input and Output specification 
Input Format:

The input will contain
  1. Number of input lines N adhering to the following specification
    1. Lines will be of two types either a Question Posing line or Answer Giving line
    2. Question posing line has to appear before any answer giving line
    3. Question Posing line starts with Player Name and Answer Giving line starts with 'A'
  2. Second line will be a Question posing line whose format is where Perfect Sets are depicted in the format <X1
  3. ,X2,...Xn> where 2<=n<=7 and 1<=Xn<=100
  4. Third line must be an Answer Giving line which is the answer to the precedingQuestion Posing line. The format of the Answer Giving line is as follows :
    1. answer above can only be an integer number OR it will be a constant string "PASS"
    2. An integer number represents the value of the answer given by the Player
    3. If the Player does not know the answer she will "PASS" the question
  5. Fourth line onwards, if they exist, will be alternating series of Question Posing and Answer Giving lines in case of Valid inputs
  6. In case of any Invalid Question Posing line, requisite output must be printed for all previous Valid Question posing line(s).
  7. Processing should stop at Invalid input line after printing required message in output. See output specifications and sample test cases to understand points 5) and 6) better


  8. Output Format:
    1. First line of output must reiterate the question in the following format < Player Name >'s question is : X1,X2,X3...,Xn>

  9. Second line should be an evaluation of the first Answer Giving line of the input. The evaluation message will either be { Correct Answer or Wrong Answer}
  10. If the answer
    1. is correct, output, : 10points
    2. is wrong, output, : 0points
    3. is "PASS"-ed by the player,
      1. output "Question is PASSed"
      2. output "Answer is: " where correct_answer_value is the correct answer for the question passed by the player.
      3. output ": 0points"
    4. Overall points collected by players have to be tracked and output when all valid inputs are processed
  11. If all inputs are valid, after processing all the inputs, the final output should be comprised of the following 4 lines
    1. Output "Total Points:" on fourth last line
    2. Output ": points" on 3rd last line, where Player1 is the one who first posed the question
    3. Output ": points" on 2nd last line, where Player2 is the one who first answered the question
    4. If there is a winner Output "Game Result: is winner" or "Game Result: Draw"
  12. Print "Invalid Input" in case of invalid input or failing constraint


  13. Constraints:
    1. 0 < N <= 10
    2. Player Names are Case-sensitive
    3. Number of inputs in a Question posing line will be 2<=n<=7 and 1<=Xn<=100
    4. <X1 ,X2,X3...,Xn> can only be integers


    Sample Input and Output

    SNo.InputOutput

    1

    4
    Sally 3,5
    A Darrell 15
    Darrell 4,8
    A Sally 8 

    Sally's question is: 3,5
    Correct Answer
    Darrell: 10points
    Darrell's question is: 4,8
    Correct Answer
    Sally: 10points
    Total Points:
    Sally: 10points
    Darrell: 10points
    Game Result: Draw 

    2

    4
    Darrell 5,6
    A Sally 30
    Sally 3,5
    A Darrell PASS

    Darrell's question is: 5,6
    Correct Answer
    Sally: 10points
    Sally's question is: 3,5
    Question is PASSed
    Answer is: 15
    Darrell: 0points
    Total Points:
    Darrell: 0points
    Sally: 10points
    Game Result: Sally is winner 

    3

    2
    Darrell
    A Sally 15

    Invalid Input

    4

    4
    Sally 3,5
    A Darrell 15
    Darrell
    A Sally 15 

    Sally's question is: 3,5
    Correct Answer
    Darrell: 10points
    Invalid Input

    5

    2
    Sally 3,5
    A Darrell 3

    Sally's question is: 3,5
    Wrong Answer
    Darrell: 0points
    Total Points:
    Sally: 0points
    Darrell: 0points
    Game Result: Draw

    6

    2
    Sally 3,5,15
    A Darrell 15

    Sally's question is: 3,5,15
    Correct Answer
    Darrell: 10points
    Total Points:
    Sally: 0points
    Darrell: 10points
    Game Result: Darrell is winner