Ronny the robot is watching someone perform the Cups and Balls magic trick. The magician has one ball and three cups, he shows Ronny which cup he hides the ball under (b), he then mixes all the cups around by performing multiple two-cup switches (arr). Ronny can record the switches but can't work out where the ball is. Write a programme to help him do this. 

Rules: 
- There will only ever be three cups.
- Only two cups will be swapped at a time. 
- The cups and their switches will be refered to by their index in a row of three, beginning at one. So [[1,2]] means the cup at position one, is swapped with the cup at position two. 
- Arr will be an array of integers 1 - 3 organised in pairs. 
- There won't be any empty sub-arrays.
- If arr is just an empty array b should be returned.

Examples: 

(b) = 2, 
(arr) = [[1,2]]

The ball is under cup number : 1

-------

(b) = 1, 
(arr) = [[2,3],[1,2],[1,2]]

The ball is under cup number : 1

-------

(b) = 2, 
(arr) = [[1,3],[1,2],[2,1],[2,3]]

The ball is under cup number : 3

Difficulty: introductory

Starter code:

def cup_and_balls(b, arr):
	

Solutions:
from functools import reduce

def cup_and_balls(b, arr):
    return reduce(lambda x, y: y[1] if x == y[0] else y[0] if x == y[1] else x, arr, b)

def cup_and_balls(b, a):
    for l, r in a:
        b = r if b == l else l if b == r else b
    return b

def cup_and_balls(b, arr):
    for switch in arr:
        if b in switch:
            b = sum(switch) - b
    return b

def cup_and_balls(b, arr):
    game = [i == b for i in range(4)]
    for a, b in arr:
        game[a], game[b] = game[b], game[a]
    return game.index(True)

def cup_and_balls(b, arr):
    for swap in arr:
        if b in swap:
            b = swap[not swap.index(b)]
    return b

def cup_and_balls(b, arr):
    cups = [0] * 4
    cups[b] = 1
    for i, j in arr:
        cups[i], cups[j] = cups[j], cups[i]
    return cups.index(1)

def cup_and_balls(b, arr):
    my_ball = b
    for turn in arr:
        if my_ball in turn:
            for x in turn:
                if x != my_ball:
                    my_ball = x
                    break;
    return my_ball

def cup_and_balls(b, arr):
    for i in arr:
        if b in i:
            b=sum(i)-b
    return b

def cup_and_balls(b,a):   
    for i,j in a:
        if b==i: b=j
        elif b==j: b=i
    return b