Created
April 18, 2023 00:41
-
-
Save LarryRuane/8a79f7271eef0d88591e0794d48144a5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/env python3 | |
import sys | |
import random | |
if not len(sys.argv) == 4: | |
print("usage:", sys.argv[0], "reps points a-win-%") | |
sys.exit(1) | |
reps = int(sys.argv[1]) | |
points = int(sys.argv[2]) | |
wp = int(sys.argv[3]) | |
# number of set wins | |
a_wins = 0 | |
b_wins = 0 | |
for i in range(reps): | |
# current points in the set | |
ap = 0 | |
bp = 0 | |
while True: | |
if random.randrange(100) < wp: | |
ap += 1 | |
if ap >= points and ap - bp >= 2: break | |
else: | |
bp += 1 | |
if bp >= points and bp - ap >= 2: break | |
if ap > bp: a_wins += 1 | |
else: b_wins += 1 | |
print("a %wins", a_wins * 100 / reps) | |
print("b %wins", b_wins * 100 / reps) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment