Anonymous user
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
{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 = :
[choice] = [0,1,2] -- [guess, shown(doors, guess)]
if Enum.at(doors, choice) == :car, do: simulate(n-1, stay, switch+1),
|