Created
October 4, 2014 19:22
-
-
Save danShumway/b28dfac4a4c8c6eae14a to your computer and use it in GitHub Desktop.
Fixing stuff up
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
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