Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danShumway/b28dfac4a4c8c6eae14a to your computer and use it in GitHub Desktop.
Save danShumway/b28dfac4a4c8c6eae14a to your computer and use it in GitHub Desktop.
Fixing stuff up
var damageDealt = 0;
var max = 0;
var trials = 1000000;
function dealDamage(damage){
if(Math.random() < .2){
return damage;
} else {
return dealDamage(damage + 1);
}
}
for(var i = 0; i<trials; i++){
var d = dealDamage(1);
if(d > max){
max = d;
}
damageDealt += d;
}
console.log(damageDealt/trials);
console.log(max);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment