Last active
August 29, 2015 14:15
-
-
Save bentona/164b3c608f08cfd04dff to your computer and use it in GitHub Desktop.
Benefit on EV of taking max of multiple rolls
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
def roll | |
Random.rand(10) + 1 | |
end | |
# Monte Carlo-in it | |
(1...10000000).inject(0){ |avg,i| avg += (roll - avg).to_f/i } | |
(1...10000000).inject(0){ |avg,i| avg += ([roll, roll, roll, roll].max - avg).to_f/i } | |
# Closed form thx http://math.stackexchange.com/questions/150586/expected-value-of-max-of-iid-variables | |
def ev a, b, n | |
a + (n.to_f/(n+1)) * (b - a) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment