Thimbles
SRM 354 · 2007-06-14 · by Andrew_Lazarev
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
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.
{"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
Submissions are judged against all 68 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Thimbles with a public method int thimbleWithBall(vector<string> swaps) · 68 test cases · 2 s / 256 MB per case