Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
17
Task/Monty-Hall-problem/Lua/monty-hall-problem.lua
Normal file
17
Task/Monty-Hall-problem/Lua/monty-hall-problem.lua
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
function playgame(player)
|
||||
local car = math.random(3)
|
||||
local pchoice = player.choice()
|
||||
local function neither(a, b) --slow, but it works
|
||||
local el = math.random(3)
|
||||
return (el ~= a and el ~= b) and el or neither(a, b)
|
||||
end
|
||||
local el = neither(car, pchoice)
|
||||
if(player.switch) then pchoice = neither(pchoice, el) end
|
||||
player.wins = player.wins + (pchoice == car and 1 or 0)
|
||||
end
|
||||
for _, v in ipairs{true, false} do
|
||||
player = {choice = function() return math.random(3) end,
|
||||
wins = 0, switch = v}
|
||||
for i = 1, 20000 do playgame(player) end
|
||||
print(player.wins)
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue