Skip to content

Instantly share code, notes, and snippets.

@dpritchett
Created June 21, 2011 16:35
Show Gist options
  • Save dpritchett/1038260 to your computer and use it in GitHub Desktop.
Save dpritchett/1038260 to your computer and use it in GitHub Desktop.
game_log = new Array();
go = function (){
x = Math.floor(Math.random() * 11) + Math.floor(Math.random() * 11);
return x;
};
execute_n_times = function(n) {
for( i = 0; i < n; i++){
single_roll = go();
if(game_log[single_roll] == undefined){
game_log[single_roll] = 0;}
game_log[single_roll]++;}};
print_test_results = function() {
for(i = 0; i < game_log.length; i++){
console.log(i + ":\t" + game_log[i]);}};
calculate_winner = function (game_log) {
has_most = -1;
the_most = 0;
for(i = 0; i < game_log.length; i++){
if(game_log[i] > the_most){
has_most = i;
the_most = game_log[has_most]}}
return has_most;};
run_n_times_with_report = function (n) {
execute_n_times(n);
print_test_results();
console.log("\nWINNER: " + calculate_winner(game_log));};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment