Advertisement
Guest User

MontyJS

a guest
Apr 20th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function monty(){
  2.   var doors = [0, 0, 0];
  3.   var switchWins = 0;
  4.   var keepWins = 0;
  5.  
  6.   //switching 10,000 times
  7.   for(var i = 0 ; i < 10000 ; ++i){
  8.     doors[Math.floor(Math.random() * 3)] = 1;
  9.     pick = Math.floor(Math.random() * 3;
  10.     if(doors[pick] !== 1) switchWins++;
  11.   }
  12.   //not switching 10,000 times
  13.   for(var i = 0 ; i < 10000 ; ++i){
  14.     doors[Math.floor(Math.random() * 3)] = 1;
  15.     pick = Math.floor(Math.random() * 3;
  16.     if(doors[pick] === 1) keepWins++;
  17.   }
  18.   console.log("Switch wins: " + switchWins);
  19.   console.log("Keep wins: " + keepWins);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement