Statistics

Problem Statement for "BinaryPad"

Problem Statement

You awake one morning from uneasy dreams to find that your best friend, Gregor, has transformed in his bed into a gigantic insect. By the frantic waving of his antennae, you deduce that he wants you to build a huge three-button pad in the shape of a circle. The buttons will each take up one third of the pad, and will be labeled A, B, and C. A is on the bottom, B on the upper left (clockwise from A), and C is on the upper right (counter-clockwise from A)

When Gregor wants to say something to you, he'll first convert the message to binary in his head. Then he'll climb onto the pad, starting at the A button. If the first digit in his binary message is 1, he would move clockwise onto button B. If the first digit is instead a 0, he would move counter-clockwise onto button C. He repeats in this fashion, moving clockwise (B, C, A, B, C, A, ...) for each 1 and counter-clockwise (C, B, A, C, B, A, ...) for each 0, until his message is finished.

Given a String presses, indicating which buttons Gregor pressed, return a String representing the binary message he communicated.

Definition

Class:
BinaryPad
Method:
convert
Parameters:
String
Returns:
String
Method signature:
String convert(String presses)
(be sure your method is public)

Notes

  • Gregor always starts on the A button. The first character of presses represents the button he moved to from A.

Constraints

  • presses will contain between 1 and 50 characters, inclusive.
  • presses will only contain the characters 'A', 'B', and 'C'.
  • No two adjacent characters of presses will be the same.
  • The first character of presses will be either 'B' or 'C'.

Examples

  1. "BCABC"

    Returns: "11111"

    Gregor moved clockwise five times (A->B, B->C, C->A, A->B, B->C). Therefore your function should return five 1's.

  2. "CBCABCB"

    Returns: "0011110"

    Two counterclockwise moves (A->C, C->B), four clockwise moves (B->C, C->A, A->B, B->C), and one more counterclockwise move (C->A) create the binary message "0011110".

  3. "BABABABABABABABABABABABABABABABABABABABABABABABABA"

    Returns: "10101010101010101010101010101010101010101010101010"

  4. "C"

    Returns: "0"

  5. "B"

    Returns: "1"

  6. "BA"

    Returns: "10"

  7. "BC"

    Returns: "11"

  8. "CA"

    Returns: "01"

  9. "CB"

    Returns: "00"

  10. "CACACACACACACACACACACACACACACACACACACACACACACACACA"

    Returns: "01010101010101010101010101010101010101010101010101"

  11. "BCBABCBABCABABCBCACABACBACACACABACABACACBABABCACBA"

    Returns: "11001100111101101101100000101011001100100010111000"

  12. "CABCBACBCACBACBCABACBACBCBCABCABCABABACBACACACACBA"

    Returns: "01110000110000011100000010111111111010000010101000"

  13. "CBACBACABACBABABCABCACBCBCBCBACBABACACABCBABCBCABA"

    Returns: "00000001100001011111100101010000010010111001101110"

  14. "BABCABACABACACACACBCACACBACBCBCBCBABACABCBABCABCBA"

    Returns: "10111100110010101001101000001010100100111001111100"

  15. "BABACBABCABCACBABCACBCACBABACBCABACBCABCABCACBACAB"

    Returns: "10100001111110001110011000100011100011111111000011"

  16. "BCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABC"

    Returns: "11111111111111111111111111111111111111111111111111"

  17. "CBACBACBACBACBACBACBACBACBACBACBACBACBACBACBACBACB"

    Returns: "00000000000000000000000000000000000000000000000000"

  18. "CBCABCBCBABACABACABACBACA"

    Returns: "0011110100100110011000001"

  19. "CABCABCACBCABACABACACBCBA"

    Returns: "0111111100111001100100100"

  20. "CABCBACABCBA"

    Returns: "011100011100"

  21. "B"

    Returns: "1"

  22. "CBABCABACABCBCBCBABAC"

    Returns: "000111100111010100100"

  23. "BCA"

    Returns: "111"

  24. "BC"

    Returns: "11"


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: