Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- flips = ["H", "T"]
- value = 0
- counted_runs = 0
- 1_000_000.times do |i|
- outcomes = [flips.sample, flips.sample, flips.sample].join
- next if outcomes.scan(/(?=H.)/).length == 0 # Outcomes not allowing a flip past an H are not counted
- value += outcomes.scan(/(?=HH)/).length.to_f / outcomes.scan(/(?=H.)/).length # HH per H_ this line
- counted_runs += 1
- end
- value/counted_runs
- => 0.416927548598704
- counted_runs
- => 750095
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement