Skip to content

Instantly share code, notes, and snippets.

@serashioda
Last active December 17, 2016 07:09
Show Gist options
  • Save serashioda/7947930dc40221ff983189db22ff4a37 to your computer and use it in GitHub Desktop.
Save serashioda/7947930dc40221ff983189db22ff4a37 to your computer and use it in GitHub Desktop.
"""The shell module to for the swap/shell function."""
def shell((start_post, swaps)):
"""swap position of ball under 3 cups."""
cups = [0, 0, 0]
cups[start_post] = 1
for i in cups:
cups[swap[1]] = cups[swap[0]]
return cups.index(1)
"""Tests for shell module."""
import pytest
TEST_TABLE = [
[[0,0,1], 2],
[[0,1,0], 1]
@pytest.mark.parametrize("start_post, swaps, result", TEST_TABLE)
def test_rotations(start_post, swaps, result, Test_TABLE)
"""Test the shell function."""
from shell import shell
assert shell(start_post, swaps) == result
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 swap sequence is [(0,1), (1,2), (1,0)]
My function gets called as find_the_ball(1, [(0,1), (1,2), (1,0)])
find_the_ball returns 2
@nhuntwalker
Copy link

You take a parameter that is a tuple of the actual parameters you want.

You have no variable called swap in your inner loop, so your function breaks.
Your inner loop should be looping over all the swaps, not over the number of cups that you have.

I see where you were going with this, but yeah you ended up iterating over the wrong things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment