Sleeping Beauty problem: Difference between revisions

m (→‎{{header|Haskell}}: small simplification)
Line 676:
</pre>
 
=={{header|Ruby}}==
{{trans|Python}}
<lang ruby>def sleeping_beauty_experiment(n)
coin = [:heads, :tails]
gotheadsonwaking = 0
wakenings = 0
n.times do
wakenings += 1
coin.sample == :heads ? gotheadsonwaking += 1 : wakenings += 1
end
puts "Wakenings over #{n} experiments: #{wakenings}"
gotheadsonwaking / wakenings.to_f
end
 
puts "Results of experiment: Sleeping Beauty should estimate
a credence of: #{sleeping_beauty_experiment(1_000_000)}"
</lang>
{{out}}
<pre>Wakenings over 1000000 experiments: 1499604
Results of experiment: Sleeping Beauty should estimate
a credence of: 0.3336854262858728
</pre>
=={{header|Swift}}==
<lang swift>let experiments = 1000000
1,149

edits