Not again! This time, the Mathematician was tasked to perform in front of children. The mathematician had to think of a new trick but this time, his trick requires programming rather than mathematical knowledge.
This is the classic trick of cups and a ball. The cups are placed such that Cup 0 is placed at Position 0, Cup 1 placed at Position one...Cup is placed at Position . You are given that there are a total of 8 cups and 8 positions. The Mathematician wanted to confuse the children by changing the positions of the cups 41 times.
In the attached link, there are 41 lines of 2 integers(space separated). The first integer, represents Postion and the second integer represents Position . This line means that the cup at Position changes positions with the cup at Position . Therefore Cup originally at Position is now at Position and vice versa.
Given that the ball was originally under Cup 0 (i.e. Position 0). What position would it be in after the 41 swaps.
Example If we have 4 cups, Cup 0, Cup 1, Cup 2, Cup 3, and we are given 3 swaps:
0 2
1 3
2 3
The order now of the four cups are: 2 3 1 0
After swap 1: 2 1 0 3
After swap 2: 2 3 0 1
After swap 3: 2 3 1 0
Remember: The position is of the first cup is 0!
Attached link : Click here
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Here's my code in
C++