Monty Hall problem: Difference between revisions

m
(add {{out}} template)
Line 1,163:
 
=={{header|F_Sharp|F#}}==
{{output?|F_Sharp}}
I don't bother with having Monty "pick" a door, since you only win if you initially pick a loser in the switch strategy and you only win if you initially pick a winner in the stay strategy so there doesn't seem to be much sense in playing around the background having Monty "pick" doors. Makes it pretty simple to see why it's always good to switch.
<lang fsharp>open System
Line 1,178 ⟶ 1,177:
let Wins (f:unit -> int) = seq {for i in [1..nSims] -> f()} |> Seq.sum
printfn "Stay: %d wins out of %d - Switch: %d wins out of %d" (Wins StayGame) nSims (Wins SwitchGame) nSims</lang>
Sample Output:
<pre>Stay: 332874 wins out of 1000000 - Switch: 667369 wins out of 1000000</pre>
 
I had a very polite suggestion that I simulate Monty's "pick" so I'm putting in a version that does that. I compare the outcome with my original outcome and, unsurprisingly, show that this is essentially a noop that has no bearing on the output, but I (kind of) get where the request is coming from so here's that version...
<lang fsharp>let montySlower nSims =
Anonymous user