from random import randint
N = 6
n = 10000
def nxt(x, N):
sgn = randint(0, 1) * 2 - 1
y = (x + sgn) % N
return y if y != 0 else N
def game(N):
rem_to_see = set(range(1, N))
x = N
while len(rem_to_see) > 1:
x = nxt(x, N)
rem_to_see.discard(x)
return rem_to_see.pop()
def sim(N, n):
cnt = {k : 0 for k in range(1, N + 1)}
for _ in range(n):
g = game(N)
cnt[g] += 1
for g in cnt:
cnt[g] /= n
return cnt
print(sim(N, n))
To embed this program on your website, copy the following code and paste it into your website's HTML: