# RosettaCode Monty Hall

## Reference

Statement of the Monty Hall problem on RosettaCode: here.

## Eiffel code

Here's an initial implementation, just to get things started. I just typed this straight into the wiki, so it might not even compile.

Please feel free to edit this in place, I won't be offended.

```class MONTY_HALL

feature

play
local
games: INTEGER
random: RANDOM
doors: ARRAYED_LIST [BOOLEAN]
chosen, shown: INTEGER
stayWins: INTEGER
do
games := 1000000
create random.make

across 1 |..| games as plays loop
create doors.make_filled (3)	-- False is a goat, True is a car
random.forth
doors [random.item \\ 3 + 1] := True	-- Put a car behind a random door

random.forth
chosen := random.item \\ 3 + 1	-- Pick a door, any door

from shown := chosen until shown /= chosen and not doors [shown] loop
random.forth
shown := random.item \\ 3 + 1
end

if doors [chosen] then	-- If you would have won by staying, count it
stay_wins := stay_wins + 1
end
end

out ("Staying wins " + stay_wins + " times.%N")
out ("Switching wins " + games - stay_wins + " times.%N")
end

end```