Last active
November 2, 2015 09:54
-
-
Save makaroni4/1aa63db4a7893c54ebdc 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
def toss | |
(rand * 100) > 60 ? 1 : 2 | |
end | |
# Both players bet on 1 | |
def game | |
toss_1 = toss() | |
toss_2 = toss() | |
if toss_1 == 1 && toss_2 != 1 | |
return 1 | |
elsif toss_2 == 1 && toss_1 != 1 | |
return 2 | |
else | |
return game() | |
end | |
end | |
h = 1_000_000.times.map { game() }.inject(Hash.new(0)) do |h, n| | |
h[n] += 1 | |
h | |
end | |
p h | |
# {2=>499985, 1=>500015} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment