Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/Monty-Hall-problem/Io/monty-hall-problem.io
Normal file
22
Task/Monty-Hall-problem/Io/monty-hall-problem.io
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
keepWins := 0
|
||||
switchWins := 0
|
||||
doors := 3
|
||||
times := 100000
|
||||
pickDoor := method(excludeA, excludeB,
|
||||
door := excludeA
|
||||
while(door == excludeA or door == excludeB,
|
||||
door = (Random value() * doors) floor
|
||||
)
|
||||
door
|
||||
)
|
||||
times repeat(
|
||||
playerChoice := pickDoor()
|
||||
carDoor := pickDoor()
|
||||
shownDoor := pickDoor(carDoor, playerChoice)
|
||||
switchDoor := pickDoor(playerChoice, shownDoor)
|
||||
(playerChoice == carDoor) ifTrue(keepWins = keepWins + 1)
|
||||
(switchDoor == carDoor) ifTrue(switchWins = switchWins + 1)
|
||||
)
|
||||
("Switching to the other door won #{switchWins} times.\n"\
|
||||
.. "Keeping the same door won #{keepWins} times.\n"\
|
||||
.. "Game played #{times} times with #{doors} doors.") interpolate println
|
||||
Loading…
Add table
Add a link
Reference in a new issue