Skip to content

Instantly share code, notes, and snippets.

@makaroni4
Last active November 2, 2015 09:54
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 makaroni4/1aa63db4a7893c54ebdc to your computer and use it in GitHub Desktop.
Save makaroni4/1aa63db4a7893c54ebdc to your computer and use it in GitHub Desktop.
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