Skip to content

Instantly share code, notes, and snippets.

@aconanlai
Last active November 22, 2016 21:44
Show Gist options
  • Save aconanlai/5a39cf2101a7b20d79c4b9cb6b91274b to your computer and use it in GitHub Desktop.
Save aconanlai/5a39cf2101a7b20d79c4b9cb6b91274b to your computer and use it in GitHub Desktop.
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