Problem Statement
You have a bicycle lock. The locking mechanism consists of several dials. Each dial contains the digits 0-9 in a cycle, in this order. From each dial exactly one digit is visible.
Each dial can be rotated in either direction:
-
Rotating the dial one step in the positive direction (denoted '+') increments the digit shown.
E.g., if the dial currently shows 4 and you make the '+' rotation, the dial will now show 5. After the digit 9 comes the digit 0 again. -
Rotating the dial one step in the negative direction (denoted '-') does the opposite.
E.g., the '-' rotation will change a dial showing 5 into a dial showing 4, and it will change a dial showing 0 into a dial showing 9.
Your finger is currently on the leftmost dial. You can use it to rotate the dial it's on. You can also move your finger one dial to the right (denoted '>') or one dial to the left (denoted '<'). You can only move your finger if the destination dial actually exists.
You are given the
You would like to scramble your lock into a state where all of the digits shown on the dials are mutually distinct.
Find any sequence of at most 100 actions that accomplishes this goal, and return it as a
Definition
- Class:
- BicycleLock
- Method:
- makeDistinct
- Parameters:
- int[]
- Returns:
- String
- Method signature:
- String makeDistinct(int[] dials)
- (be sure your method is public)
Notes
- You are not required to minimize the number of operations.
Constraints
- dials will contain between 1 and 10 elements, inclusive.
- Each element of dials will be between 0 and 9, inclusive.
Examples
{3, 2, 7}
Returns: ""
All dials already show distinct numbers, so we do not have to do anything at all.
{8, 8, 0, 9}
Returns: ">+++"
Our solution moves the finger to the second dial and then rotates it three times in the positive direction. This changes the lock from its initial state 8809 into 8909, then 8009, and finally 8109, which is a valid final state. There are many other valid solutions. The most efficient one is to simply rotate the first dial once in the negative direction, changing the lock to 7809.
{9}
Returns: "+++--+-"
Again, we do not have to do anything, but we can. Remember that any solution that consists of at most 100 actions will be accepted.
{0, 1, 0, 2, 0}
Returns: ">>>>-<+<+++++"
The returned solution produces the dial values {0, 1, 5, 3, 9} in the end.
{1, 6, 8, 7, 9, 5, 4}
Returns: "+++++++++>+++++>++++>++++++>+++++>>++"
{6, 9, 0, 6, 0, 1, 0, 4}
Returns: "++++>++>++>+++++++>++++>++++>++++++>+++"
{8, 0, 5, 9, 6, 3, 3, 8, 8}
Returns: "++>+>+++++++>++++>++++++++>++>+++>+++++++++>"
{7, 3, 0, 8, 5, 5, 9}
Returns: "+++>++++++++>++>+++++>+++++++++>>+++++++"
{8, 9, 3, 3, 0, 2, 5}
Returns: "++>++>+++++++++>>++++>+++>+"
{5, 9, 6}
Returns: "+++++>++>++++++"
{1, 3, 5, 3, 7, 1}
Returns: "+++++++++>++++++++>+++++++>>+++++++>++++"
{9, 5, 4, 3, 8, 4, 5, 8}
Returns: "+>++++++>++++++++>>++++++>+>+>+++++++++"
{7, 4}
Returns: "+++>+++++++"
{4, 8, 3, 9, 1, 3, 6, 7}
Returns: "++++++>+++>+++++++++>++++>+++>++>>"
{9, 8, 2, 7, 0, 2}
Returns: "+>+++>>++++++>++++>+++"
{1, 4, 8}
Returns: "+++++++++>+++++++>++++"
{6, 5, 0, 9, 4, 9, 8, 7, 5}
Returns: "++++>++++++>++>++++>>++++++>++++++++>>+++"
{9, 3}
Returns: "+>++++++++"
{5, 6, 2, 2, 7}
Returns: "+++++>+++++>>+>+++++++"
{2, 1, 2, 9, 5}
Returns: "++++++++>>>++++>+++++++++"
{1, 4, 7, 0, 1, 6, 1, 5}
Returns: "+++++++++>+++++++>+++++>+++>+++>+++++++++>+++++>++"
{4, 0}
Returns: "++++++>+"
{2, 8, 7, 3}
Returns: "++++++++>+++>+++++>"
{8, 7, 9, 9, 0, 1, 2, 2, 8}
Returns: "++>++++>+++>++++>++++>++++>++++>+++++>"
{0, 9, 3, 0, 6, 1, 0}
Returns: ">++>+++++++++>+++>++++++++>++++>++++++"
{4, 0, 8}
Returns: "++++++>+>++++"
{3, 9, 8, 2, 8, 9}
Returns: "+++++++>++>++++>+>++++++>++++++"
{9, 9, 1, 9, 7, 5}
Returns: "+>++>+>++++>+++++++>"
{1, 6}
Returns: "+++++++++>+++++"
{5, 4, 9, 7, 9, 2, 1, 8}
Returns: "+++++>+++++++>+++>++++++>+++++>+++>+++++>+++++++++"
{7, 7, 0}
Returns: "+++>++++>++"
{9, 8, 1, 4, 7, 8, 1, 3}
Returns: "+>+++>+>+++++++++>+++++++>+++++++>+++++>++++"
{5, 2, 7, 0, 9, 1, 7}
Returns: "+++++>+++++++++>+++++>+++>+++++>++++>+++++++++"
{4, 8, 0, 8, 3, 4, 0, 4, 8}
Returns: "++++++>+++>++>+++++>+>+>++++++>+++>"
{6, 1, 1, 8, 9, 9, 7, 8, 5}
Returns: "++++>>+>+++++>+++++>++++++>+++++++++>+++++++++>+++"
{6, 3, 1, 1, 8, 4}
Returns: "++++>++++++++>+>++>++++++>+"
{5, 8, 5, 1, 1, 9, 6, 5}
Returns: "+++++>+++>+++++++>++>+++>++++++>>++"
{5, 9}
Returns: "+++++>++"
{6, 4}
Returns: "++++>+++++++"
{3, 4, 3, 7, 4, 7}
Returns: "+++++++>+++++++>+++++++++>++++++>>++++++++"
{5, 0, 2, 9, 7, 0, 0, 6, 7}
Returns: "+++++>+>>++++>+++++++>+++++>++++++>+>+"
{9, 4, 4, 1, 4, 1, 2, 6, 5}
Returns: "+>+++++++>++++++++>++>>++++>++++>+>+++"
{6, 3, 8, 9, 8, 4, 5, 8, 0}
Returns: "++++>++++++++>++++>++++>++++++>+>+>+++++++++>++++++++"
{9, 9, 9, 9, 7, 9, 8, 2}
Returns: "+>++>+++>++++>+++++++>++++++>++++++++>+++++"
{0, 2, 9, 2, 9, 1, 7, 6}
Returns: ">+++++++++>+++>+>+++++>++++>+++++++++>+"
{3, 7}
Returns: "+++++++>++++"
{9, 6, 0, 9}
Returns: "+>+++++>++>++++"
{1, 8, 6, 0}
Returns: "+++++++++>+++>++++++>+++"
{7, 7, 5, 1, 8, 6, 1, 1}
Returns: "+++>++++>+++++++>++>++++++>+++++++++>+++++>++++++"
{6, 8, 1, 9, 2, 7, 7, 7}
Returns: "++++>+++>+>++++>++>++++++++>+++++++++>"
{6, 8, 8}
Returns: "++++>+++>++++"
{6, 3, 5, 6, 1, 2, 7}
Returns: "++++>++++++++>+++++++>+++++++>+++>+++>+++++++++"
{1, 4, 7, 1, 5, 0, 6}
Returns: "+++++++++>+++++++>+++++>++>+++++++++>+++++>"
{9, 3, 8}
Returns: "+>++++++++>++++"
{4, 8, 8, 4, 8, 4, 8, 4, 4, 8}
Returns: "++++++>+++>++++>+++++++++>++++++>+>++++++++>+++>++++>+"
{5, 3, 5, 4, 5, 5, 3, 3, 5, 1}
Returns: "+++++>++++++++>+++++++>+++++++++>+++++++++>>+++>++++>+++>++++++++"
{5, 2, 9, 6, 8, 1, 8, 7, 9, 9}
Returns: "+++++>+++++++++>+++>+++++++>++++++>++++>++++++++>>+++++++++>"
{6, 9, 9, 6, 9, 6, 9, 8, 8, 9}
Returns: "++++>++>+++>+++++++>+++++>+++++++++>+++++++>+++++++++>>"
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9}
Returns: "+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>"
{0, 9, 9, 4, 8, 7, 3, 4, 7, 3}
Returns: ">++>+++>+++++++++>++++++>++++++++>+++>+++>+>++++++"
{4, 4, 4, 4, 4, 4, 4, 4, 4, 4}
Returns: "++++++>+++++++>++++++++>+++++++++>>+>++>+++>++++>+++++"
{1, 1, 1, 1, 6, 9, 9, 9, 9, 1}
Returns: "+++++++++>>+>++>++++++++>++++++>+++++++>++++++++>+++++++++>++++++++"
{4, 4, 6, 4, 6, 6, 4, 6, 6, 6}
Returns: "++++++>+++++++>++++++>+++++++++>++++++++>+++++++++>++>+>++>+++"
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
Returns: "+++++++++>>+>++>+++>++++>+++++>++++++>+++++++>++++++++"
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
Returns: "+++++++++>>+>++>+++>++++>+++++>++++++>+++++++>++++++++"
{8, 8, 5, 8, 0, 8, 0, 0, 8, 8}
Returns: "++>+++>+++++++>+++++>++++>+++++++>++++++>+++++++>>+"
{6, 6, 6, 6, 6, 6, 6, 6, 6, 6}
Returns: "++++>+++++>++++++>+++++++>++++++++>+++++++++>>+>++>+++"
{9, 9, 9, 9, 9, 9, 9, 9, 9, 9}
Returns: "+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>"
{2, 1, 1, 1, 1, 3, 0, 0, 1, 9}
Returns: "++++++++>>+>++>+++>++>++++++>+++++++>+++++++>"
{2, 8, 1, 3, 9, 3, 3, 5, 8, 6}
Returns: "++++++++>+++>+>>+++++>++>+++>++>>+++"
{2, 2, 2, 2, 2, 2, 2, 2, 2, 2}
Returns: "++++++++>+++++++++>>+>++>+++>++++>+++++>++++++>+++++++"
{6, 4, 4, 9, 7, 8, 6, 0, 1, 4}
Returns: "++++>+++++++>++++++++>++++>+++++++>+++++++>>+++++++>+++++++>+++++"
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
Returns: "+++++++++>>+>++>+++>++++>+++++>++++++>+++++++>++++++++"
{6, 8, 7, 9, 3, 4, 9, 3, 2, 4}
Returns: "++++>+++>+++++>++++>+>+>+++++++>++++>++++++>+++++"
{3, 9, 9, 9, 3, 3, 9, 3, 9, 9}
Returns: "+++++++>++>+++>++++>+>++>+++++++>++++>+++++++++>"
{6, 1, 2, 7, 6, 3, 9, 7, 2, 9}
Returns: "++++>>>++++++>++++++++>++>+++++++>>++++++>"
{9, 4, 4, 9, 9, 9, 4, 4, 4, 9}
Returns: "+>+++++++>++++++++>++++>+++++>++++++>++>+++>++++>"
{4, 4, 1, 9, 9, 4, 4, 9, 1, 1}
Returns: "++++++>+++++++>+>++++>+++++>+>++>++++++++>+++++++>++++++++"
{6, 6, 6, 6, 6, 6, 6, 6, 6, 6}
Returns: "++++>+++++>++++++>+++++++>++++++++>+++++++++>>+>++>+++"
{1, 1, 1, 1, 8, 8, 1, 1, 8, 8}
Returns: "+++++++++>>+>++>++++++>+++++++>+++++>++++++>>+"
{8, 8, 8, 8, 8, 8, 8, 8, 8, 8}
Returns: "++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>>+"
{3, 3, 8, 8, 8, 8, 3, 7, 3, 3}
Returns: "+++++++>++++++++>++++>+++++>++++++>+++++++>+++>>+++++>++++++"
{9, 9, 9, 9, 2, 2, 2, 2, 3, 2}
Returns: "+>++>+++>++++>++>+++>++++>+++++>+++++>+++++++"
{8, 3, 8, 5, 5, 3, 3, 8, 8, 5}
Returns: "++>++++++++>++++>++++++++>+++++++++>++>+++>+++++++++>>++++"
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Returns: ">+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++"
{2, 3, 1, 2, 5, 0, 1, 7, 1, 3}
Returns: "++++++++>++++++++>+>+>+++++++++>+++++>+++++>>+++++++>++++++"
{6, 6, 8, 8, 3, 8, 3, 6, 6, 8}
Returns: "++++>+++++>++++>+++++>+>+++++++>+++>+>++>+"
{6, 0, 0, 6, 6, 0, 0, 0, 6, 6}
Returns: "++++>+>++>+++++++>++++++++>+++++>++++++>+++++++>++>+++"
{7, 7, 7, 7, 8, 8, 7, 8, 8, 8}
Returns: "+++>++++>+++++>++++++>++++++>+++++++>+++++++++>+++++++++>>+"
{1, 7, 1, 7, 1, 7, 1, 1, 7, 7}
Returns: "+++++++++>++++>+>++++++>+++>++++++++>+++++>++++++>+>++"
{2, 2, 2, 2, 2, 2, 2, 2, 2, 2}
Returns: "++++++++>+++++++++>>+>++>+++>++++>+++++>++++++>+++++++"
{4, 4, 4, 4, 4, 4, 4, 4, 4, 4}
Returns: "++++++>+++++++>++++++++>+++++++++>>+>++>+++>++++>+++++"
{3, 0, 6, 0, 3, 0, 3, 0, 6, 3}
Returns: "+++++++>+>++++++>+++>+>+++++>+++>+++++++>++>++++++"
{4, 2, 4, 1, 8, 7, 3, 4, 1, 4}
Returns: "++++++>+++++++++>++++++++>++>++++++>++++++++>+++>+++>+++++++>+++++"
{2, 9, 1, 1, 7, 1, 0, 7, 4, 7}
Returns: "++++++++>++>+>++>+++++++>++++>++++++>>++++>++"
{4, 3, 1, 1, 6, 3, 1, 5, 5, 8}
Returns: "++++++>++++++++>+>++>++++++++>++>+++++>++>+++>+"
{0, 5, 0, 5, 8, 0, 8, 5, 8, 8}
Returns: ">++++++>++>++++++++>++++++>+++++>++++++++>++>>+"
{5, 9, 5, 5, 5, 5, 9, 9, 5, 5}
Returns: "+++++>++>+++++++>++++++++>+++++++++>>+++++++>++++++++>+++>++++"
{8, 1, 8, 8, 1, 8, 1, 1, 8, 1}
Returns: "++>>++++>+++++>+++>+++++++>+++++>++++++>>++++++++"
{4, 1, 7, 1, 4, 7, 7, 7, 7, 1}
Returns: "++++++>>+++++>++>>++++++++>+++++++++>>+>++++++++"
{7, 7, 7, 7, 7, 7, 4, 4, 4, 4}
Returns: "+++>++++>+++++>++++++>+++++++>++++++++>++>+++>++++>+++++"
{5, 5, 5, 5, 5, 5, 5, 5, 5, 5}
Returns: "+++++>++++++>+++++++>++++++++>+++++++++>>+>++>+++>++++"
{0, 2, 0, 2, 0, 0, 2, 2, 0, 2}
Returns: ">+++++++++>++>+>++++>+++++>++++>+++++>++++++++>+++++++"
{7, 3, 3, 7, 3, 7, 3, 7, 3, 7}
Returns: "+++>++++++++>+++++++++>++++++>+>++++++++>+++>>+++++>++"
{3, 2, 7 }
Returns: ""