Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2011
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.34 KB | None | 0 0
  1. def trial
  2.   heads, tails = 0, 0
  3.   500.times do |n|
  4.     if rand(2).zero?
  5.       heads += 1
  6.     else
  7.       tails += 1
  8.     end
  9.     return [heads, tails] if heads > tails
  10.   end
  11.   return [heads, tails]
  12. end
  13.  
  14. heads, tails = 0, 0
  15. 1000000.times do
  16.   a, b = trial()
  17.   heads += a
  18.   tails += b
  19. end
  20.  
  21. puts "#{heads}/#{tails} = #{heads/tails.to_f}"
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement