Sleeping Beauty problem: Difference between revisions

Realize in F#
(added Pascal)
(Realize in F#)
Line 124:
|}
 
=={{header|F_Sharp|F#}}==
<lang fsharp>
// Sleeping Beauty: Nigel Galloway. May 16th., 2021
let heads,woken=let n=System.Random() in {1..1000}|>Seq.fold(fun(h,w) g->match n.Next(2) with 0->(h+1,w+1) |_->(h,w+2))(0,0)
printfn "During 1000 tosses Sleeping Beauty woke %d times, %d times the toss was heads. %.0f%% of times heads had been tossed when she awoke" woken heads (100.0*float(heads)/float(woken))
</lang>
{{out}}
<pre>
During 1000 tosses Sleeping Beauty woke 1519 times, 481 times the toss was heads. 32% of times heads had been tossed when she awoke
</pre>
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
2,171

edits