Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def trial
- heads, tails = 0, 0
- 500.times do |n|
- if rand(2).zero?
- heads += 1
- else
- tails += 1
- end
- return [heads, tails] if heads > tails
- end
- return [heads, tails]
- end
- heads, tails = 0, 0
- 1000000.times do
- a, b = trial()
- heads += a
- tails += b
- end
- puts "#{heads}/#{tails} = #{heads/tails.to_f}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement