Created
May 25, 2011 18:04
-
-
Save josephdunn/991507 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
#!/usr/bin/ruby | |
def winloss | |
if rand(2) == 1 | |
return true | |
else | |
return false | |
end | |
end | |
def session | |
bankroll = 10 | |
bet = 0.1 | |
while bankroll > 0 && bankroll < 15 | |
if winloss | |
bankroll += bet * 2 | |
bet = 0.1 | |
else | |
bankroll -= bet | |
bet = bet * 2 # double up | |
end | |
#puts "bankroll is #{bankroll}, bet is #{bet}" | |
end | |
if bankroll >= 15 | |
return true | |
else | |
return false | |
end | |
end | |
win = 0 | |
lose = 0 | |
10000.times do | |
results = session | |
if results | |
win += 1 | |
else | |
lose += 1 | |
end | |
end | |
puts "#{win} wins, #{lose} losses" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment