Skip to content

Instantly share code, notes, and snippets.

@Mego
Last active July 31, 2017 13:43
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 Mego/a62f4891e392ce4f4b9f11141b854dbd to your computer and use it in GitHub Desktop.
Save Mego/a62f4891e392ce4f4b9f11141b854dbd to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import math
import random
successes = 0
history = []
n = random.randint(1, 256)
k = random.randint(1, n)
B = 0
while B in [0, k]:
B = random.uniform(0, k)
turn = 0
while turn < n:
print("Coins: {}".format(n))
print("Goal: {}".format(k))
print("Coins flipped: {}".format(turn))
print("Budget: {}".format(B))
print("Successes: {}".format(successes))
print("History: {}".format(history))
print()
p = eval(input("Probability for this flip: "))
flip = random.choices([0, 1], [1-p, p])[0]
print()
print("Outcome: {}".format("Success" if flip else "Failure"))
successes += flip
history.append((p, flip))
budget -= p
turn += 1
print("Coins: {}".format(n))
print("Goal: {}".format(k))
print("Coins flipped: {}".format(turn))
print("Budget: {}".format(B))
print("Successes: {}".format(successes))
print("History: {}".format(history))
print()
print("Overall Outcome: {}".format("success" if successes >= k else "failure"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment