Skip to content

Instantly share code, notes, and snippets.

@tedchou12
Last active January 25, 2022 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tedchou12/22e7621d2449932497a4612ce49aa744 to your computer and use it in GitHub Desktop.
Save tedchou12/22e7621d2449932497a4612ce49aa744 to your computer and use it in GitHub Desktop.
three color marbles sampling
import random
combinations = ['B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y']
simulations = 500000
results = []
counter = 0
while counter < simulations :
#start sampling
sample = random.sample(combinations, k=12)
modes = [sample.count('B'), sample.count('R'), sample.count('Y')]
code = sorted(modes, reverse=True)
code = ''.join(map(lambda x: str(x), code))
value = 0
if code == '840' :
value = 100
elif code == '831' :
value = 10
elif code == '822' :
value = 10
elif code == '750' :
value = 20
elif code == '741' :
value = 2
elif code == '732' :
value = 2
elif code == '660' :
value = 20
elif code == '651' :
value = 1
elif code == '642' :
value = 1
elif code == '633' :
value = 1
elif code == '552' :
value = 1
elif code == '543' :
value = -10
elif code == '444' :
value = 1
results.append(value)
counter = counter + 1
print(sum(results) / len(results))
# result
# -4.244846
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment