[SOLVED] game 21/10/19, 11(05 pm

$25

File Name: game_21/10/19,_11(05_pm.zip
File Size: 216.66 KB

5/5 - (1 vote)

21/10/19, 11(05 pm
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 String[] swaps which describes the swaps made, in order. Each element of swaps will be in the format X-Y (quotes for clarity), which means that the thimble in position X was swapped with the thimble in position Y. The positions are 1, 2 or 3. Your method should return the position of the thimble with the ball after all the swaps.
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
0)
1)
{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 doesnt 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:
https://cs.adelaide.edu.au/~second/pssd/15s2-pssd-adelaide/2014/week8practice/Thimbles/content.php Page 1 of 2

21/10/19, 11(05 pm
1->3->2->2->3. 2)
{2-3, 1-3, 2-3, 2-1, 3-1}
Returns: 3
3)
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2006, TopCoder, Inc. All rights reserved.
{1-2, 3-2, 1-2, 2-1, 2-1, 3-2, 1-3, 3-1, 1-2}
Returns: 1
https://cs.adelaide.edu.au/~second/pssd/15s2-pssd-adelaide/2014/week8practice/Thimbles/content.php Page 2 of 2

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] game 21/10/19, 11(05 pm
$25