Skip to content

Instantly share code, notes, and snippets.

@sma
Created July 29, 2021 12:00
Show Gist options
  • Save sma/c37f8a185e98c21fdda5f9b34060bd07 to your computer and use it in GitHub Desktop.
Save sma/c37f8a185e98c21fdda5f9b34060bd07 to your computer and use it in GitHub Desktop.
function d6() {
return Math.floor(Math.random()*6)+1;
}
function kill() {
let hp = 40;
let sp = 7;
let turn = 0;
while (hp > 0) {
let d = d6() + d6();
if (d === 12) hp -= 5;
if (sp > 0 && d > sp) {
d -= sp;
sp--;
hp -= d;
} else if (sp == 0) {
hp -= d;
}
turn++;
}
return turn;
}
let turns = 0;
for (let i = 0; i < 1000; i++) {
turns += kill();
}
console.log(turns / 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment