Skip to content

Instantly share code, notes, and snippets.

@Brandon-Rozek
Created May 14, 2021 23:17
Show Gist options
  • Save Brandon-Rozek/5b2e84b2197695beeea3cceff8cd5640 to your computer and use it in GitHub Desktop.
Save Brandon-Rozek/5b2e84b2197695beeea3cceff8cd5640 to your computer and use it in GitHub Desktop.
var decay = function(initial, chance) {
var numDecayed = 0;
for (var i = 0; i < initial; i++) {
if (Math.random() < chance) {
numDecayed++
}
}
return numDecayed;
}
var simulate = function(initial, chance, n) {
var numLeft = initial;
for (var i = 0; i < n; i++) {
numLeft -= decay(numLeft, chance);
}
return numLeft
}
var decayModel = function(initial, chance) {
var numLeft = initial;
var results = [];
while (numLeft > 0) {
numLeft -= decay(numLeft, chance);
results.push(numLeft);
}
return results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment