Last active
July 31, 2017 13:43
-
-
Save Mego/a62f4891e392ce4f4b9f11141b854dbd 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
#!/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