Created
May 14, 2021 23:17
-
-
Save Brandon-Rozek/5b2e84b2197695beeea3cceff8cd5640 to your computer and use it in GitHub Desktop.
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 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