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
to1
- The second swap moves the ball from
1
to2
- 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
Similar Kata:
Stats:
Created | Nov 17, 2014 |
Published | Nov 17, 2014 |
Warriors Trained | 7108 |
Total Skips | 1915 |
Total Code Submissions | 11287 |
Total Times Completed | 3370 |
Haskell Completions | 294 |
Clojure Completions | 215 |
Ruby Completions | 494 |
Python Completions | 1421 |
JavaScript Completions | 1042 |
CoffeeScript Completions | 7 |
Total Stars | 105 |
% of votes with a positive feedback rating | 93% of 433 |
Total "Very Satisfied" Votes | 381 |
Total "Somewhat Satisfied" Votes | 45 |
Total "Not Satisfied" Votes | 7 |