Skip to content

Instantly share code, notes, and snippets.

@nhuntwalker
Created December 15, 2016 19:02
Show Gist options
  • Save nhuntwalker/578803882e7dc5a325473894ca7ee00f to your computer and use it in GitHub Desktop.
Save nhuntwalker/578803882e7dc5a325473894ca7ee00f to your computer and use it in GitHub Desktop.
The Shell Game
Three (or more) cups. One has a ball underneath, and the rest are empty.
The person running the game will switch the cup positions over and over until they stop.
You, as the gambler, are trying to find which cup still has the ball.
Given the shell that the ball starts under, and a list of swaps, return the location of
the ball at the end.
For example, if my function name is find_the_ball,
and the starting position is 0
and the swap sequence is [(0, 1), (1, 2), (1, 0)]
My function gets called as find_the_ball(0, [(0, 1), (1, 2), (1, 0)])
find_the_ball returns 2
email: nicholas@codefellows.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment