6 kyu

The Shell Game

294 of 3,370mtthw123

Description:

"The Shell Game" involves cups upturned on a playing surface, with a ball placed underneath one of them. The index of the cups are swapped around multiple times. After that the players will try to find which cup contains the ball.

Your task is as follows. Given the cup that the ball starts under, and list of swaps, return the location of the ball at the end. Cups are given like array/list indices.

For example, given the starting position 0 and the swaps [(0, 1), (1, 2), (1, 0)]:

  • The first swap moves the ball from 0 to 1
  • The second swap moves the ball from 1 to 2
  • The final swap doesn't affect the position of the ball.

So

(start = 0 ; swaps = [(0, 1), (2, 1), (0, 1)] ) --> 2

There will always be at least two cups. You can assume all swaps are valid, and involve two distinct indices.

Fundamentals

More By Author:

Check out these other kata created by mtthw123

Stats:

CreatedNov 17, 2014
PublishedNov 17, 2014
Warriors Trained7108
Total Skips1915
Total Code Submissions11287
Total Times Completed3370
Haskell Completions294
Clojure Completions215
Ruby Completions494
Python Completions1421
JavaScript Completions1042
CoffeeScript Completions7
Total Stars105
% of votes with a positive feedback rating93% of 433
Total "Very Satisfied" Votes381
Total "Somewhat Satisfied" Votes45
Total "Not Satisfied" Votes7
Ad
Contributors
  • mtthw123 Avatar
  • jhoffner Avatar
  • Mackay Avatar
  • nLight Avatar
  • user578387 Avatar
  • GiacomoSorbi Avatar
  • Voile Avatar
  • trashy_incel Avatar
  • WestwardLand968 Avatar
  • dfhwze Avatar
  • sid114 Avatar
Ad