Advertisement
Guest User

Untitled

a guest
Jun 6th, 2023
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. flips = ["H", "T"]
  2. value = 0
  3. counted_runs = 0
  4.  
  5. 1_000_000.times do |i|
  6. outcomes = [flips.sample, flips.sample, flips.sample].join
  7. next if outcomes.scan(/(?=H.)/).length == 0 # Outcomes not allowing a flip past an H are not counted
  8. value += outcomes.scan(/(?=HH)/).length.to_f / outcomes.scan(/(?=H.)/).length # HH per H_ this line
  9. counted_runs += 1
  10. end
  11.  
  12. value/counted_runs
  13. => 0.416927548598704
  14.  
  15. counted_runs
  16. => 750095
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement