Skip to content

Instantly share code, notes, and snippets.

@torjusb
Created June 10, 2013 08:50
Show Gist options
  • Save torjusb/5747345 to your computer and use it in GitHub Desktop.
Save torjusb/5747345 to your computer and use it in GitHub Desktop.
var results, passes, tests;
results = {
'switch': 0,
'keep': 0
};
passes = 100000;
tests = ['switch', 'keep'];
tests.forEach( function (test) {
var choice, correct;
for (var i = 0; i < passes; i++) {
choice = Math.floor(Math.random() * 3) + 1;
correct = Math.floor(Math.random() * 3) + 1;
if (test === 'switch') {
if (correct !== choice) {
results['switch']++;
}
} else {
if (correct === choice) {
results.keep++;
}
}
}
} );
for (var test in results) {
console.log(test, results[test] / passes * 100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment