-
-
Save vessenes/20f083e3f0a0a8fc90c2fe676483828d 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 sys | |
from random import randint | |
win_if_lte = 49 | |
payoff = 2.0 | |
if len(sys.argv) < 2: | |
print "Please enter the number of ethereum per bet as the first argument" | |
sys.exit(1) | |
bet_size = float(sys.argv[1]) | |
block_reward = 5.0 | |
percent_of_mining = 0.1 | |
def bet_n_times(n, stake): | |
for i in range(n): | |
stake -= bet_size | |
roll = randint(1,100) | |
if roll <= win_if_lte: | |
# We won! | |
stake += bet_size * payoff | |
return stake | |
def bet_n_times_with_cheat(n, stake, pom): | |
eth_mined = 0 | |
for i in range(n): | |
stake -= bet_size | |
roll = randint(1,100) | |
if roll <= win_if_lte: | |
# We won! | |
stake += bet_size * payoff | |
else: | |
if randint(1,100) <= pom * 100: | |
# We mined the block that has our losing number in it | |
# We get another roll. | |
# We're going to give up 5 ether to roll again | |
stake -= block_reward | |
roll = randint(1,100) | |
if roll <= win_if_lte: | |
stake += bet_size * payoff | |
# We still might win this mining race, too | |
if randint(1,100) <= pom * 100: | |
stake += block_reward | |
eth_mined += 1 | |
return (stake, eth_mined) | |
trials = 50 | |
for trial in range(trials): | |
n_times = bet_n_times(10000, 5000) | |
(n_cheats, mined) = bet_n_times_with_cheat(10000, 5000, 0.1) | |
print "10k bets results in net earnings of", n_times - 5000, " if honest and ", n_cheats - 5000, " if cheating with", percent_of_mining, " of mining and bet size of ", bet_size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment