Monty Hall problem: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 3,555: | Line 3,555: | ||
Estimate: 4960/10000 wins for 'picking anew' strategy |
Estimate: 4960/10000 wins for 'picking anew' strategy |
||
Of course, this challenge could also be tackled by putting up a GUI and letting the user be the source of the randomness. But that's moving away from the letter of the challenge and takes a lot of effort anyway... |
Of course, this challenge could also be tackled by putting up a GUI and letting the user be the source of the randomness. But that's moving away from the letter of the challenge and takes a lot of effort anyway... |
||
=={{header|Transact SQL}}== |
|||
T-SQL for general case: |
|||
<lang Transact Sql> |
|||
---- BEGIN ------------ |
|||
create table MONTY_HALL( |
|||
NOE int, |
|||
CAR int, |
|||
ALTERNATIVE int, |
|||
ORIGIN int, |
|||
[KEEP] int, |
|||
[CHANGE] int, |
|||
[RANDOM] int |
|||
) |
|||
-- INIT |
|||
truncate table MONTY_HALL |
|||
declare @N int , @i int -- No of Experiments and their counter |
|||
declare @rooms int , -- number of rooms |
|||
@origin int, -- original choice |
|||
@car int , -- room with car |
|||
@alternative int -- alternative room |
|||
select @rooms = 3, @N = 100000 , @i = 0 |
|||
-- EXPERIMENTS LOOP |
|||
while @i < @N begin |
|||
select @car = FLOOR(rand()*@rooms)+1 , @origin = FLOOR(rand()*@rooms)+1 |
|||
select @alternative = FLOOR(rand()*(@rooms-1))+1 |
|||
select @alternative = case when @alternative < @origin then @alternative else @alternative + 1 end |
|||
select @alternative = case when @origin = @car then @alternative else @car end |
|||
insert MONTY_HALL |
|||
select @i,@car,@alternative,@origin,@origin,@alternative,case when rand() < 5e-1 then @origin else @alternative end |
|||
select @i = @i + 1 |
|||
end |
|||
-- RESULTS |
|||
select avg (case when [KEEP] = CAR then 1e0 else 0e0 end )*1e2 as [% OF WINS FOR KEEP], |
|||
avg (case when [CHANGE] = CAR then 1e0 else 0e0 end )*1e2 as [% OF WINS FOR CHANGE], |
|||
avg (case when [RANDOM] = CAR then 1e0 else 0e0 end )*1e2 as [% OF WINS FOR RANDOM] |
|||
from MONTY_HALL |
|||
---- END ------------ |
|||
</lang> |
|||
<pre> |
|||
% OF WINS FOR KEEP % OF WINS FOR CHANGE % OF WINS FOR RANDOM |
|||
---------------------- ---------------------- ---------------------- |
|||
33.607 66.393 49.938 |
|||
</pre> |
|||
=={{header|UNIX Shell}}== |
=={{header|UNIX Shell}}== |