|
|
|
|
|
by mag487
4547 days ago
|
|
It may be a useful sanity check to simulate the experiment multiple times to see the result: def choose_coin
rand < 0.001 ? 1 : 0.5
end
def flip_coin(coin)
rand < coin ? :heads : :tails
end
def all_10_heads?(coin)
10.times { return false if flip_coin(coin) == :tails }
true
end
next_flip = { :heads => 0, :tails => 0 }
1000000.times do
coin = choose_coin
next unless all_10_heads? coin
next_flip[flip_coin(coin)] += 1
end
puts next_flip[:heads].to_f / (next_flip[:heads] + next_flip[:tails])
|
|
http://en.wikipedia.org/wiki/Probabilistic_programming_langu...