Statistics

Problem Statement for "NumberMagicEasy"

Problem Statement

NOTE: This problem statement contains images that may not display properly if viewed outside of the applet.

Taro shows a magic trick to Hanako.

Taro: Hello Hanako. I'll show you a magic trick. Please imagine a positive integer less than or equal to 16.
Hanako: OK. I imagined it.
Taro: (Taro shows card 1 to Hanako.) Does this card contain your number?
Hanako: Yes.
Taro: (Taro shows card 2 to Hanako.) Does this card contain your number?
Hanako: No.
Taro: (Taro shows card 3 to Hanako.) Does this card contain your number?
Hanako: Yes.
Taro: (Taro shows card 4 to Hanako.) Does this card contain your number?
Hanako: Yes.
Taro: Your number is 5!


(Card 1 contains 1, 2, 3, 4, 5, 6, 7 and 8. Card 2 contains 1, 2, 3, 4, 9, 10, 11 and 12. Card 3 contains 1, 2, 5, 6, 9, 10, 13 and 14. Card 4 contains 1, 3, 5, 7, 9, 11, 13 and 15.)

Your task is to write a program that simulates this magic trick. You are given Hanako's answers in the String answer. The i-th character is 'Y' if she answered "yes" to the i-th question, and 'N' if she answered "no" to the i-th question. Return the integer Hanako imagined.

Definition

Class:
NumberMagicEasy
Method:
theNumber
Parameters:
String
Returns:
int
Method signature:
int theNumber(String answer)
(be sure your method is public)

Constraints

  • answer will contain exactly 4 characters.
  • Each character in answer will be 'Y' or 'N'.

Examples

  1. "YNYY"

    Returns: 5

    The example from the statement.

  2. "YNNN"

    Returns: 8

    8 is the only number that exists on the first card and does not exist on any other cards.

  3. "NNNN"

    Returns: 16

  4. "YYYY"

    Returns: 1

  5. "NYNY"

    Returns: 11

  6. "NNNY"

    Returns: 15

  7. "NNYN"

    Returns: 14

  8. "NNYY"

    Returns: 13

  9. "NYNN"

    Returns: 12

  10. "NYYN"

    Returns: 10

  11. "NYYY"

    Returns: 9

  12. "YNNY"

    Returns: 7

  13. "YNYN"

    Returns: 6

  14. "YYNN"

    Returns: 4

  15. "YYNY"

    Returns: 3

  16. "YYYN"

    Returns: 2


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: