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
"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."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"."BABABABABABABABABABABABABABABABABABABABABABABABABA"
Returns: "10101010101010101010101010101010101010101010101010"
"C"
Returns: "0"