Firestorm002

Monty Hall Paradox

Jan 19th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.34 KB | None | 0 0
  1. --[Monty Hall Paradox Test]-- By: Cody Hardink
  2.  
  3. --[Variables]--
  4. local testSampleNum = 200 --Change this to what you like.
  5. local curTestSampleNum = 0 --Counts how many tests have been run.
  6. local switchWins = 0
  7. local stickWins = 0
  8. local winLocation = 0
  9. local selLocation = 0
  10. local sTime = 0.05
  11. --[Functions]--
  12.  
  13. local function randomSel()
  14.     local gNum = math.random(1,3)
  15.     return gNum
  16. end
  17.  
  18. local function runTest()
  19.   winLocation = randomSel()
  20.   selLocation = randomSel()
  21.   if selLocation == winLocation then
  22.     stickWins = stickWins + 1
  23.   else
  24.     switchWins = switchWins + 1
  25.   end
  26. end
  27.  
  28.  
  29.  
  30. local function main()
  31.   while curTestSampleNum < testSampleNum do
  32.     runTest()
  33.     curTestSampleNum = curTestSampleNum + 1
  34.     term.clear()
  35.     term.setCursorPos(1,1)
  36.     print("---------------------------------------------------")
  37.     print(" ")
  38.     print("Stick Wins Percentage:"..stickWins/testSampleNum * (100).."%")
  39.     print(" ")
  40.     print("Switch Wins Percentage:"..switchWins/testSampleNum * (100).."%")
  41.     print(" ")
  42.     print("Total Progress:"..curTestSampleNum/testSampleNum * (100).."%")
  43.     print(" ")
  44.     print("Total Samples Run:"..curTestSampleNum.."/"..testSampleNum)
  45.     print(" ")
  46.     print("ETA:"..(math.ceil((sTime * testSampleNum) - (sTime * curTestSampleNum))).." Seconds")
  47.     sleep(sTime)
  48.   end
  49. end
  50.  
  51. main()
Advertisement
Add Comment
Please, Sign In to add comment