Shell Game
I’m fairly new to this but I just can’t understand the shell game at all

Can someone explain it line by line for me as a beginner

Like what does the N do? Why is there 3 shells but only 2 are accounted for and the “3rd” one is just the guess? If it’s supposed to be seeing if the guess is write why does it not ask “if g = pebble shell location” or something like that?

Please can someone help?

You should probably read this:


The first line of the input file contains an integer N giving the number of swaps (1≤N≤1001≤�≤100). Each of the next N� lines describes a step of the game and contains three integers a�, b�, and g�, indicating that shells a� and b� were swapped by Bessie, and then Elsie guessed shell g� after the swap was made. All three of these integers are either 1, 2, or 3, and a≠b�≠�.

Basically its saying that theres three shells, and each line of input tells you: (pos1) swapped with(pos2) → (guess 1); because theres only 3 shells and bessie swapped two and elsie made a guess, and the first line N just indicates how many swaps and guesses there were

The first input is the number of swaps so it says 3 and we have 3 swaps:

1 2 1
3 2 1
1 3 1

Each line represents swap a, b, and guess. Shells 1 and 2 were swapped and the guess was 1. Shell 3 and 2 were swapped and the guess was 1 again. Shell 1 and 3 were swapped and same guess.

The N or first input tells you how many times you should iterate the input really

Here is my code:

fin = open("", "r")
fout = open("shell.out", "w")

n = int(fin.readline())
ans = 0
swap = [[0 for _ in range(3)] for _ in range(n)]
for i in range (0, n):
    line = fin.readline().split()
    cup1 = int(line[0])
    cup2 = int(line[1])
    guess = int(line[2])
    swap[i][0] = cup1 - 1   
    swap[i][1] = cup2 - 1   
    swap[i][2] = guess - 1  
maxCount = 0       
for i in range(1, 4):
    pebLoc = [False, False, False]
    pebLoc[i-1] = True
    count = 0
    for j in range (0, n):
        cup1 = swap[j][0]
        cup2 = swap[j][1]
        guess = swap[j][2]
        storage = pebLoc[cup2]
        pebLoc[cup2] = pebLoc[cup1]
        pebLoc[cup1] = storage
        if pebLoc[guess]:
    maxCount = max(maxCount, count)
ans = str(maxCount)