I don't want to be embarassed #2

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 \(n\) is placed at Position \(n\). 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,\(x\) represents Postion \(x\) and the second integer \(y\) represents Position \(y\). This line means that the cup at Position \(x\) changes positions with the cup at Position \(y\). Therefore Cup originally at Position \(x\) is now at Position \(y\) 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


Problem Loading...

Note Loading...

Set Loading...