Posted by Lucas Hermann Negri on Mon 20 Apr 00:49
report abuse | download | new post
- math.randomseed(os.time())
- function testa(troca)
- local portas = {false, false, false}
- portas[math.random(3)] = true
- -- Assume-se que escolheu a 1, e remove-se ou a 2 ou a 3
- local r = 2
- if portas[2] then r = 3 end
- table.remove(portas, r)
- -- Verifica se o jogador ganhou
- if not troca then
- return portas[1]
- else
- return portas[2]
- end
- end
- -- Simula N vezes
- local trocar = arg[1] == "trocar"
- local total, venceu = 1000000, 0
- print(string.format("Simulando %i jogos, %s de porta", total, trocar and "trocando" or "sem trocar"))
- for i = 1, total do
- if testa(trocar) then
- venceu = venceu + 1
- end
- end
- print(string.format("Resultado: ganhou %.2f%% das vezes!", venceu / total))
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.