Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Monty Hall Problem Simulated
-- Change these to see different results! local doors = 3 local max_tries = 9999 local switch_door = true -- Don't change -- local answers_correct = 0 local u = 0 local function random(x, y) u = u + 1 if x ~= nil and y ~= nil then return math.floor(x +(math.random(math.randomseed(os.time()+u))*999999 %y)) else return math.floor((math.random(math.randomseed(os.time()+u))*1000)) end end for i = 1, max_tries do local correct_door = random(1, doors) local door_chosen = random(1, doors) local door_revealed = random(1, doors) if door_revealed == door_chosen or door_revealed == correct_door then door_revealed = (door_revealed + 1)%doors + 1 end if switch_door then repeat door_chosen = (door_chosen + 1)%doors +1 until door_revealed ~= door_chosen end if correct_door == door_chosen then answers_correct = answers_correct + 1 end end print("Percentage of correct answers: %" .. math.floor( (answers_correct/max_tries)*1000)/10 ) print("\nCorrect answers: " .. answers_correct) print("Incorrect answers: " .. max_tries - answers_correct)
run
|
edit
|
history
|
help
1
ok
Code golf - ASCII art #1
RSA KEY GENERATOR (LUA)
test123
sh
dd
5+5 == 10
Reverse strings function - Lua
Binary to Integers / Integers to Binary
Convert MySQL 'framed' table into CSV