Learn practical skills, build real-world projects, and advance your career

Problem Solving using Python


 

Cup Swapping


There are three cups on a table, at positions A, B and C. At the start, there is a ball hidden under the cup at position B.
However, I perform a number of swaps on the cups, which is notated as two letters. For example, if I swap the cups at positions A and B, I could notate this as AB or BA.
Create a function which returns the letter position that the ball is at, once I finish swapping the cups. The swaps will be given to you as a list.

Worked Example cup_swapping(['AB', 'CA', 'AB']) ➞ 'C'

Ball begins at position B.

Cups A and B swap, so ball is at position A.
Cups C and A swap, so ball is at position C.
Cups A and B swap, but the ball is at position C, so it doesn't move.

Examples
cup_swapping(['AB', 'CA']) ➞ 'C'
cup_swapping(['AC', 'CA', 'CA', 'AC']) ➞ 'B'
cup_swapping(['BA', 'AC', 'CA', 'BC']) ➞ 'A'