Jump to content

Monty Hall problem: Difference between revisions

→‎{{header|Elixir}}: change :random -> :rand module
m (added whitespace before a header.)
(→‎{{header|Elixir}}: change :random -> :rand module)
Line 1,278:
<lang elixir>defmodule MontyHall do
def simulate(n) do
:random.seed(:os.timestamp)
{stay, switch} = simulate(n, 0, 0)
:io.format "Staying wins ~w times (~.3f%)~n", [stay, 100 * stay / n]
Line 1,287 ⟶ 1,286:
defp simulate(n, stay, switch) do
doors = Enum.shuffle([:goat, :goat, :car])
guess = :randomrand.uniform(3) - 1
[choice] = [0,1,2] -- [guess, shown(doors, guess)]
if Enum.at(doors, choice) == :car, do: simulate(n-1, stay, switch+1),
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.