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
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"
"B"
Returns: "1"
"BA"
Returns: "10"
"BC"
Returns: "11"
"CA"
Returns: "01"
"CB"
Returns: "00"
"CACACACACACACACACACACACACACACACACACACACACACACACACA"
Returns: "01010101010101010101010101010101010101010101010101"
"BCBABCBABCABABCBCACABACBACACACABACABACACBABABCACBA"
Returns: "11001100111101101101100000101011001100100010111000"
"CABCBACBCACBACBCABACBACBCBCABCABCABABACBACACACACBA"
Returns: "01110000110000011100000010111111111010000010101000"
"CBACBACABACBABABCABCACBCBCBCBACBABACACABCBABCBCABA"
Returns: "00000001100001011111100101010000010010111001101110"
"BABCABACABACACACACBCACACBACBCBCBCBABACABCBABCABCBA"
Returns: "10111100110010101001101000001010100100111001111100"
"BABACBABCABCACBABCACBCACBABACBCABACBCABCABCACBACAB"
Returns: "10100001111110001110011000100011100011111111000011"
"BCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABC"
Returns: "11111111111111111111111111111111111111111111111111"
"CBACBACBACBACBACBACBACBACBACBACBACBACBACBACBACBACB"
Returns: "00000000000000000000000000000000000000000000000000"
"CBCABCBCBABACABACABACBACA"
Returns: "0011110100100110011000001"
"CABCABCACBCABACABACACBCBA"
Returns: "0111111100111001100100100"
"CABCBACABCBA"
Returns: "011100011100"
"B"
Returns: "1"
"CBABCABACABCBCBCBABAC"
Returns: "000111100111010100100"
"BCA"
Returns: "111"
"BC"
Returns: "11"