Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Go ahead and run a few million simulations of the problem and graph the running mean over time. You might be surprised :)

Be sure to use exact arithmetic (eg http://docs.python.org/2/library/fractions.html)



https://gist.github.com/tedtieken/6567112

Run the simulator and you'll see, the ev is 3x/2, regardless of switching behavior.

Feel free to modify if you think I've innacurrately conceptualizer the problem.

Also, please excuse some non pythonic names, I'm writing the code on an iPhone.


Sorry, I should have been more specific :S

You have assumed a fixed amount in each envelope. The article leaves the amount unspecified but implicitly assumes that there is no maximum amount that could be in the envelope. The problem only becomes interesting for certain distributions.

Try this code:

https://gist.github.com/jamii/6567205

If you run it with the uniform distribution the running mean will eventually converge to 0. If you comment that out and uncomment the exponential distribution it is much more interesting :)

With the exponential distribution the expected value of switching does not even exist.

EDIT Doh, the original gist was totally wrong. That'll teach me to argue on the internet at 3am. The updated gist is correct.


Fixed amount vs variable amount is irrelevant, variable amount just requires higher n.

Either way, the gain from switching approaches zero as n approaches infinity.


It does make a difference but I messed up the code :S

If you try the updated gist you will find that the second distribution appears to converge for a while but always jumps away again. I've run it now for 20540000 rounds and its further away than it started.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: