Monty Hall problem: Difference between revisions

(Add SETL)
(3 intermediate revisions by 2 users not shown)
Line 695:
If you stick to your choice, you have a 33.32 percent chance to win
If you switched, you have a 66.68 percent chance to win
</pre>
 
 
=={{header|FutureBasic}}==
Translated from ANSI BASIC
</syntaxhighlight lang="futurebasic">
// Monty Hall problem
// May 2024 - Rich Love
 
local fn IsGameWon(Sw as int) as bool
REM Play one game.
REM Switching if and only if Sw <> 0.
REM Returns 1 if the game is won, 0 otherwise.
short Car = INT(RND(3)) //Randomly place car behind a door.
short Player0 = INT(RND(3)) // Player randomly chooses a door.
short Monty
short IsGameWon
short Player
DO
Monty = INT(RND(3)) // Monty opens door revealing a goat.
UNTIL (Monty <> Car) AND (Monty <> Player0)
380
IF Sw <> 0 // Player switches TO remaining door.
DO
LET pta_montysPlayer = INT(RND * (3) + 1)
UNTIL (Player <> Player0) AND (Player <> Monty)
Monty = INT(RND(3))
 
ELSE
Player = Player0 // Player sticks with original door.
END IF
IF Player = Car
IsGameWon = 1
ELSE
IsGameWon = 0
END IF
END fn = IsgameWon
 
 
_NGames = 10000
 
float NWins = 0
short Game
 
FOR Game = 0 TO _NGames
IF fn IsGameWon(0) <> 0 THEN NWins = NWins + 1
NEXT Game
 
 
PRINT "NOT switching doors wins car in ";
PRINT USING "##.##" ; NWins / 100 ;
PRINT " % of games."
 
NWins = 0
FOR Game = 0 TO _NGames
IF fn IsGameWon(1) <> 0 THEN NWins = NWins + 1
NEXT Game
PRINT "But switching doors wins car in ";
PRINT USING "##.##" ; NWins / _NGames * 100;
PRINT " % of games."
 
handleevents
</syntaxhighlight>
{{output}}
<pre>
NOT switching doors wins car in 33.48% of games.
But switching doors wins car in 67.15% of games.
</pre>
 
Line 924 ⟶ 995:
 
==={{header|True BASIC}}===
<syntaxhighlight lang="basicqbasic">OPTION BASE 0
DIM puertas(3)
 
LET numTiradas = 1000000
 
FOR i = 10 TO numTiradas
LET pta_coche = INT(RND * 3) + 1
LET puertas(pta_coche) = 1
LET pta_elegida = INT(RND * 3) + 1
DO
IF pta_coche <> pta_elegida THEN
LET pta_montys = 6INT(RND -* pta_coche3) -+ pta_elegida1
LOOP WHILE puertas(pta_montys) = 1 OR pta_montys = pta_elegida
IF puertas(pta_elegida) = 1 THEN
LET cambia = cambia + 1
ELSE
IF pta_coche = pta_elegida THEN LET permanece = permanece + 1
DO
LET pta_montys = INT(RND * 3) + 1
LOOP UNTIL pta_montys <> pta_coche
END IF
LET puertas(pta_coche) = 0
! mantener elección
IF pta_coche = pta_elegida THEN LET permanece = permanece + 1
! cambiar elección
IF pta_coche = 6 - pta_montys - pta_elegida THEN LET cambia = cambia + 1
NEXT i
 
PRINT "Cambiar gana el"; permanece / numTiradas * 100; "% de las veces."
PRINT "Mantenerse gana el"; cambia / numTiradas * 100; "% de las veces."
END</syntaxhighlight>
END
</syntaxhighlight>
 
==={{header|Yabasic}}===
Line 3,065 ⟶ 3,136:
(0.33241,0.66759)
</pre>
=={{header|K}}==
<syntaxhighlight lang="k">
montyhall:{t:,/ 1_ x {`prng@`t[];ch:1?3;pr:1?3;sw:1?2;$[sw;a:ch=pr;a:~(ch=pr)];a}\0N;("KEEP %";(+/t)%x;"SWAP %";(+/~t)%x)}
 
montyhall 100000
</syntaxhighlight>
 
=={{header|Kotlin}}==
44

edits