Created
November 28, 2022 16:51
-
-
Save kusano/d878d69223a78d6220e54d68e5d94cce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
# ババ抜きをシミュレート | |
# n: 人数 | |
# s: 配り始める人 | |
def simulate(n, s): | |
C = [0] | |
for i in range(1, 14): | |
C += [i]*4 | |
random.shuffle(C) | |
P = [set() for _ in range(n)] | |
for i, c in enumerate(C): | |
p = (i+s)%n | |
if c in P[p]: | |
P[p].remove(c) | |
else: | |
P[p].add(c) | |
while True: | |
for p in range(n): | |
if len(P[p])>0: | |
for i in range(1, n): | |
q = (p-i)%n | |
if len(P[q])>0: | |
c = random.choice(list(P[q])) | |
P[q].remove(c) | |
if c in P[p]: | |
P[p].remove(c) | |
else: | |
P[p].add(c) | |
break | |
else: | |
assert P[p]==set([0]) | |
return p | |
T = 1000000 | |
for n in range(2, 6): | |
print(f"{n=}") | |
for s in range(n): | |
C = [0]*n | |
for _ in range(T): | |
p = simulate(n, s) | |
C[p] += 1 | |
print(*[f"{c/T*100:5.2f}" for c in C]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n=2 | |
50.67 49.33 | |
50.72 49.28 | |
n=3 | |
34.29 34.13 31.58 | |
43.40 21.32 35.27 | |
22.12 35.71 42.17 | |
n=4 | |
16.21 28.60 38.80 16.39 | |
34.69 16.26 34.56 14.49 | |
27.90 39.16 17.70 15.24 | |
25.16 25.67 24.87 24.30 | |
n=5 | |
20.84 21.36 26.35 11.41 20.05 | |
11.02 21.57 21.75 20.79 24.87 | |
13.25 13.15 23.86 36.09 13.65 | |
32.86 12.94 13.28 28.80 12.11 | |
22.93 35.67 14.88 13.94 12.58 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment