Skip to content

Instantly share code, notes, and snippets.

@bentona
Last active August 29, 2015 14:15
Show Gist options
  • Save bentona/164b3c608f08cfd04dff to your computer and use it in GitHub Desktop.
Save bentona/164b3c608f08cfd04dff to your computer and use it in GitHub Desktop.
Benefit on EV of taking max of multiple rolls
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