Last active
November 22, 2016 21:44
-
-
Save aconanlai/5a39cf2101a7b20d79c4b9cb6b91274b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pickDryer(){ | |
return Math.floor((Math.random() * 2) ); | |
} | |
function placePairs (num){ | |
var pairs = []; | |
for (l=0; l<num; l++){ | |
pairs[l]=new Array(2); | |
} | |
var results = []; | |
for (i = 0; i < num; i++){ | |
pairs[i][0] = pickDryer(); | |
pairs[i][1] = pickDryer(); | |
} | |
for (i = 0; i < pairs.length; i++){ | |
results[i] = Math.abs(pairs[i][0] - pairs[i][1]); | |
} | |
return (results.indexOf(0) >= 0); | |
} | |
function simulate(num, pairs){ | |
var counter = 0; | |
for (j=0; j<num; j++){ | |
if (placePairs(pairs) === false){ | |
counter = counter + 1; | |
} | |
} | |
return counter; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment