Problem Statement
Thimbles is a hazard game with the following rules. The dealer puts three identical thimbles on the table, with a small ball underneath the first one. Then, he repeatedly selects a pair of thimbles and swaps their positions. Finally, he asks you "Where is the ball?". You win if you point to the right thimble and lose otherwise.
You are writing the computer version of this game, and in this problem, you must write the module that determines the position of the ball after all the thimble swaps have been done.
You will be given a
Definition
- Class:
- Thimbles
- Method:
- thimbleWithBall
- Parameters:
- String[]
- Returns:
- int
- Method signature:
- int thimbleWithBall(String[] swaps)
- (be sure your method is public)
Constraints
- swaps will contain between 1 and 50 elements, inclusive.
- Each element of swaps will be in the format "X-Y" (quotes for clarity) where X and Y are distinct digits between 1 and 3, inclusive.
Examples
{"1-2", "3-1"}
Returns: 2
Initially the ball is under the first thimble. After the first swap it moves to the second position. The second swap doesn't affect the ball. So, the final position of the ball is 2.
{"3-1", "2-3", "3-1", "3-2"}
Returns: 3
The path of the ball is: 1->3->2->2->3.
{"2-3", "1-3", "2-3", "2-1", "3-1"}
Returns: 3
{"1-2", "3-2", "1-2", "2-1", "2-1", "3-2", "1-3", "3-1", "1-2"}
Returns: 1
{"2-1","3-1","3-2","2-3","3-2","1-2"}
Returns: 3
{"1-3","3-1","2-1","2-3","2-3"}
Returns: 2
{"2-3","2-3","2-3","3-2","1-3","2-1","3-1"}
Returns: 1
{"2-1","3-1","3-2"}
Returns: 3
{"2-3","2-3","1-3","3-1","2-3"}
Returns: 1
{"1-3","2-1","3-2","2-1","2-1","1-3"}
Returns: 2
{"3-1","1-3","1-3","3-1","3-1","3-2","1-3","2-3","3-1"}
Returns: 1
{"1-2","2-1","1-2","1-3","3-1","1-2","2-3","2-3","3-2","3-2"}
Returns: 1
{"1-2","3-2","1-3","3-2","1-2","1-2"}
Returns: 1
{"3-1","1-3","3-2","2-1","1-2"}
Returns: 1
{"2-1","3-1","3-2","3-1","2-3","2-1","2-3","2-3","1-3"}
Returns: 2
{"1-3","1-2","2-1"}
Returns: 3
{"3-2","1-2","1-3","3-2","2-3","2-3","3-1","3-2","2-3","3-1"}
Returns: 3
{"2-3","2-1","3-1","1-3","2-3","3-1","1-2","1-3"}
Returns: 2
{"3-2","2-1","2-1","2-1"}
Returns: 2
{"1-3","2-3","1-3","1-3","3-1","3-2"}
Returns: 3
{"1-3","3-1","2-1","2-1","3-1"}
Returns: 3
{"3-1","2-1","2-3","3-1","2-3"}
Returns: 3
{"3-2","1-3","3-1"}
Returns: 1
{"3-1","1-2","3-2"}
Returns: 2
{"1-3","3-2","2-1","2-1","3-2","3-1","2-1","1-3","1-2","2-3","1-3","1-3","2-3","1-2","1-3","2-3","1-2","1-2","3-1","1-3","3-1","1-2","2-3","3-2","1-3","2-1","2-1","2-3","2-3","2-3","1-2","1-2","3-1","1-2","3-2","2-1","2-1","1-3","2-3","3-1","2-3","2-3","2-3","1-3","2-3"}
Returns: 3
{"1-2","2-3","3-2","2-3","2-1","3-1","1-2","1-2","2-1","1-3","2-1","1-2","2-1","1-3","1-2","1-2","2-3","2-1","2-1","2-1","2-1","2-3","3-2","3-2","1-3","2-3","2-1","1-3","1-2","3-1","2-3","1-2","1-3","2-1","2-3","1-3","2-1","2-3","2-1","1-2","2-3","1-2","1-2","2-3","3-2"}
Returns: 1
{"2-3","1-2","3-2","2-3","1-3","2-1","1-2","3-1","3-1","2-1","2-1","1-3","3-1","2-3","1-3","1-2","1-2","2-1","1-2","1-2","2-3","1-2","1-2","2-1","1-2","3-1","2-3","3-2","3-1","2-1","1-3","3-1","1-2","3-2","1-2","2-1","1-3","2-1","3-2","3-1"}
Returns: 3
{"1-2","3-2","2-1","1-2","3-2","2-3","3-2","3-1","2-3","1-3","1-3","2-1","2-1","2-3","2-1","2-3","3-1","3-2","3-1","1-3","2-3","1-3","2-3","1-3","3-1","1-3","2-1","2-1","3-1","3-2","1-2","1-3","2-3","3-2","2-3","1-2","1-3","3-2","3-1","3-2","1-3","2-3","1-3","1-3","3-1","2-1","2-3","1-3"}
Returns: 1
{"3-2","2-1","1-3","3-2","3-1","1-2","1-2","1-3","3-2","1-3","3-1","1-3","1-3","3-1","1-2","1-2","1-3","3-1","3-1","1-2","3-2","2-1","2-1","1-2","3-2","1-3","3-1","3-1","3-2","2-1","3-1","3-1","3-1","3-2","3-2","2-3","1-3","2-1","2-1","3-2","1-3","1-2","2-1"}
Returns: 3
{"1-2","3-1","2-1","1-2","3-2","1-3","3-2","3-2","1-3","1-2","3-1","1-2","1-2","3-2","3-1","3-2","1-2","2-1","2-1","1-3","2-3","1-3","3-1","2-1","1-3","3-2","1-2","2-1","2-1","1-3","3-1","1-2","3-1","3-2","1-3","3-2","2-3","2-1","3-2","1-3","3-2","1-3","1-2","3-2","2-1","2-1","1-3","1-3","2-3"}
Returns: 3
{"2-1","3-2","2-1","1-2","1-2","3-2","3-1","1-2","3-1","3-2","2-1","3-2","3-1","3-1","2-1","1-3","2-3","3-2","2-3","1-3","3-2","1-2","3-1","1-2","1-2","2-3","1-2","3-2","2-3","2-3","3-2","1-3","2-3","2-3","2-3","1-3","1-2","3-2","1-2","2-3","2-3","2-1","3-1","2-3","2-1","2-3","1-2","1-2","2-1","1-2"}
Returns: 2
{"2-3","3-2","3-1","3-1","1-2","2-1","1-2","2-1","1-2","2-3","2-1","2-1","2-1","1-3","2-1","2-3","1-3","1-3","1-3","2-1","3-2","1-2","2-1","1-2","1-2","2-3","3-2","3-1","2-3","2-3","3-1","3-1","2-1","3-1","2-3","2-1","3-1","3-2","1-2","3-2","2-1","2-3","2-1","3-2","1-2"}
Returns: 2
{"1-2","3-2","3-2","1-3","2-1","2-3","2-1","2-1","3-1","1-3","2-3","2-3","1-2","1-3","2-1","3-1","1-2","1-2","1-3","2-1","3-1","1-3","3-2","2-1","3-2","3-1","3-2","2-3","3-1","3-1","2-3","1-2","1-2","2-3","2-1","1-3","2-1","1-2","3-2","2-1","1-3","3-1","1-2","1-3","1-2","2-3","3-2","2-3","1-2"}
Returns: 2
{"1-3","3-1","1-3","1-3","3-1","1-2","2-1","2-3","1-2","2-3","2-1","3-1","3-1","3-1","3-1","2-3","3-1","1-2","2-1","3-2","3-2","2-1","3-2","1-3","3-1","3-2","3-2","2-3","1-3","2-1","1-2","2-3","2-1","3-2","2-1","1-3","3-1","1-2","1-2","1-2"}
Returns: 2
{"1-2","2-1","2-1","3-1","1-3","2-1","3-1","2-1","2-3","3-2","3-2","3-2","1-2","3-2","2-3","1-3","2-1","2-1","3-1","1-3","3-1","3-2","1-3","2-3","2-1","2-1","2-3","3-1","3-1","2-3","3-1","3-1","3-1","3-2","1-2","2-1","1-3","2-1","1-3","1-3","1-3","2-3","3-1","1-2"}
Returns: 3
{"1-2","1-2","2-3","2-1","3-1","3-1","2-3","1-2","2-1","3-2","1-3","2-3","1-2","1-2","2-1","2-3","3-2","2-1","3-1","2-3","2-3","3-1","2-1","3-1","3-2","2-1","3-2","2-3","1-2","2-3","1-3","3-2","2-3","2-3","2-1","3-2","2-1","2-3","2-3","3-2","3-2"}
Returns: 2
{"3-1","3-2","2-1","1-3","3-2","3-2","1-3","3-1","1-2","3-2","2-1","1-2","1-2","2-3","1-3","2-3","3-1","1-2","1-3","3-1","1-2","2-3","3-2","3-1","3-1","2-1","2-3","3-1","1-2","3-2","2-3","3-2","1-2","1-3","1-3","3-2","3-1","3-1","1-2","2-3","3-2","1-2","2-3","2-1","1-2","2-3","2-3","2-1"}
Returns: 2
{"3-1","3-2","1-2","2-3","3-1","3-1","2-1","1-2","3-2","2-3","3-1","1-2","1-2","3-2","3-1","1-2","1-2","3-2","3-1","2-3","3-2","2-1","2-1","3-1","3-2","3-2","2-3","2-3","3-1","1-2","3-1","2-1","3-1","3-1","3-2","2-1","1-2","2-3","2-3","2-1","2-3","1-3","2-1","3-2","3-2","3-1","1-3","3-2"}
Returns: 3
{"3-1","3-2","1-2","1-2","2-3","1-3","3-2","3-2","1-2","1-3","1-2","2-3","2-3","1-3","1-2","3-1","2-3","1-2","3-2","3-1","2-3","3-1","3-2","2-3","1-3","2-1","2-1","3-1","2-3","2-1","2-1","1-3","1-3","3-2","1-3","3-2","2-3","3-1","3-2","3-1","1-2","1-3"}
Returns: 3
{"3-2","2-1","3-2","1-3","3-2","2-3","2-3","2-1","3-1","3-2","3-1","2-1","3-2","3-2","2-1","1-3","2-3","3-2","2-1","2-1","1-2","3-1","2-1","2-3","3-1","2-3","3-2","1-2","3-1","3-1","1-3","1-3","3-1","1-2","1-3","3-1","3-2","3-1","1-2","1-2"}
Returns: 3
{"3-2","1-3","1-3","1-3","1-2","1-3","1-2","2-3","1-3","2-1","1-2","3-1","2-3","2-3","3-2","1-3","1-3","1-3","2-1","2-1","3-1","3-1","3-1","2-3","1-3","3-1","3-2","3-1","1-2","2-1","1-2","2-3","1-3","1-2","3-2","1-3","1-3","2-3","2-3","2-3","3-1","2-1","3-2"}
Returns: 3
{"1-3","1-2","1-3","2-3","3-2","3-2","3-2","1-2","3-2","3-1","2-1","1-3","3-1","2-1","3-1","3-2","2-1","1-3","2-3","3-1","1-2","2-3","3-2","1-2","3-2","3-2","1-2","3-1","3-1","3-1","3-1","2-3","1-2","3-1","2-3","1-3","3-2","3-2","1-2","2-1","1-3","3-1","3-1","2-3","3-2","1-2","1-3","1-2"}
Returns: 2
{"1-3","2-3","3-1","2-1","3-1","2-1","3-2","2-1","3-2","2-1","3-2","3-1","2-1","3-1","3-2","1-2","2-1","2-3","3-1","3-2","2-3","2-3","2-1","1-3","1-3","1-3","1-2","3-1","1-2","2-1","2-3","2-1","1-2","2-3","3-2","2-3","2-3","1-3","3-2","3-2","2-3","3-1","3-1","3-2","1-3","3-2","2-1","3-1","1-2","3-2"}
Returns: 2
{"1-2","3-1","1-3","2-1","1-3","3-1","1-3","2-3","1-2","2-3","3-2","2-1","1-2","3-2","3-1","2-3","1-2","1-2","1-3","2-1","1-2","3-1","1-3","2-1","1-3","3-2","1-3","1-3","2-1","3-2","1-2","1-3","3-2","1-2","3-1","2-1","2-3","3-1","3-2","3-2"}
Returns: 1
{"3-1","1-3","3-1","3-2","2-3","3-1","2-1","2-3","3-1","1-2","3-2","2-3","3-2","3-2","3-2","3-2","2-1","2-1","1-2","1-3","1-3","1-2","3-2","3-2","1-2","1-3","1-3","3-1","2-3","2-3","2-3","3-2","3-1","2-1","2-3","1-3","3-1","2-3","3-2","3-1"}
Returns: 1
{"1-2","3-2","3-2","3-2","3-2","2-1","1-3","3-2","2-1","3-1","1-3","3-1","3-1","2-1","2-1","1-3","2-3","3-2","3-2","2-1","1-2","2-1","3-1","3-1","1-2","3-2","3-1","1-3","3-1","3-1","2-3","1-2","1-3","3-1","3-1","2-3","1-2","2-1","3-2","3-1","1-3","1-3","1-2","1-2"}
Returns: 1
{"2-1","2-1","1-2","2-3","1-3","1-3","1-3","1-2","1-2","3-1","1-3","1-3","1-3","2-1","3-2","1-3","1-2","2-1","2-1","1-2","3-1","1-3","2-1","2-1","1-3","2-3","1-2","2-1","1-2","3-1","3-2","2-1","1-3","2-3","1-2","3-1","3-1","1-2","1-2","1-2","2-3","3-2"}
Returns: 2
{"1-3","3-2","2-3","3-2","2-1","3-1","3-2","2-1","1-2","3-2","3-1","2-1","3-2","3-1","3-1","2-3","2-1","2-1","2-1","2-1","3-2","3-1","1-3","2-3","2-3","3-1","1-3","2-3","2-3","3-2","2-1","2-1","3-2","2-3","2-3","3-1","1-3","3-1","1-3","1-3","1-3","3-1","3-1","1-3"}
Returns: 1
{"1-3","3-1","1-2","3-2","2-3","1-2","3-1","3-2","2-1","3-1","3-2","1-2","2-1","2-3","3-1","3-1","3-1","1-2","2-3","2-3","1-2","3-1","3-2","2-3","3-1","3-1","2-3","1-2","2-1","1-2","2-1","3-2","3-1","2-1","2-1","3-1","2-3","2-3","3-2","2-1","2-1","3-2","1-3","1-2","3-2","3-1","2-1","3-2","3-2","2-3"}
Returns: 3
{"1-3","1-3","2-1","2-3","3-2","2-3","3-2","2-1","2-1","2-3","3-1","2-1","2-3","3-2","1-2","1-2","1-2","3-1","1-3","2-1","1-2","1-3","2-3","2-3","3-1","3-1","2-3","2-3","2-3","1-2","1-2","2-3","1-3","1-3","3-1","3-1","3-1","1-2","2-3","1-3","1-2","1-2","1-2"}
Returns: 2
{"1-3","2-3","2-3","1-3","1-2","2-3","2-3","1-2","2-1","1-2","1-2","1-2","2-1","2-1","3-1","2-3","1-2","3-1","2-3","2-1","1-2","2-1","1-2","2-3","2-3","2-1","1-3","2-3","2-1","1-3","1-3","3-1","2-3","2-1","1-3","1-3","3-1","3-2","2-3","1-3","3-1","2-3","1-2","2-1","2-1"}
Returns: 1
{"1-2","2-1","1-3","1-3","2-1","3-2","1-3","1-2","3-2","2-3","3-2","3-1","1-2","3-2","3-2","1-2","2-1","1-2","2-1","1-2","1-2","1-2","2-1","2-1","1-3","1-3","2-1","1-2","1-2","2-1","3-1","3-2","2-1","1-2","1-2","3-1","3-1","1-2","2-3","3-2","2-3","3-1"}
Returns: 1
{"1-3","3-1","3-1","1-3","2-1","1-2","2-1","3-2","1-3","2-1","3-2","2-3","3-2","1-3","1-3","2-3","2-1","1-2","2-1","1-2","1-2","1-3","3-2","1-2","1-3","3-2","2-1","1-2","2-1","1-2","1-2","1-2","2-3","3-1","1-2","1-2","2-1","1-2","1-3","3-2"}
Returns: 2
{"2-1","3-2","3-2","2-3","3-1","3-1","1-3","1-2","1-2","3-1","2-3","1-2","1-2","3-2","1-3","1-3","1-3","2-1","2-1","3-1","3-2","1-2","1-3","3-1","2-1","2-3","1-3","2-1","1-2","2-1","2-3","3-2","3-2","2-3","2-1","1-3","2-3","2-1","1-3","2-3","3-2","1-3","1-3","2-3","1-2","3-1","1-3","1-3","1-3","1-2"}
Returns: 2
{"2-3"}
Returns: 1
{"3-2"}
Returns: 1
{"1-3"}
Returns: 3
{"1-2"}
Returns: 2
{"2-3","2-3","3-2","3-2","2-3","3-2","3-2","3-2","2-3","3-2","2-3","3-2","2-3","2-3","2-3","2-3","3-2","2-3","2-3","3-2","2-3","3-2","3-2","2-3","3-2","3-2","3-2","3-2","2-3","3-2","2-3","3-2","2-3","3-2","3-2","3-2","2-3","3-2","2-3","2-3","2-3","2-3","2-3","3-2","3-2","2-3","3-2","2-3","2-3","2-3"}
Returns: 1
{"2-1" }
Returns: 2
{"2-3", "1-3", "2-3", "2-1", "3-1" }
Returns: 3
{"1-2", "2-1" }
Returns: 1
{"2-3" }
Returns: 1
{"3-1", "2-3", "3-1", "3-2", "2-1" }
Returns: 3
{"3-1", "2-3", "3-1", "3-2" }
Returns: 3
{"1-2" }
Returns: 2
{"1-2", "2-3" }
Returns: 3
{"3-1" }
Returns: 3