logoalt Hacker News

hansvm12/10/20242 repliesview on HN

That code has the same problem that Colin Wright's explanation does. Your computation of the success rate explicitly uses the fact that you're between the two values, but till you've seen the second value you can't possibly know whether you are or are not and thus can't adjust your guess based on that fact.


Replies

LudwigNagasena12/10/2024

The success is checked after the decision is made to, well, verify the decision. The guess isn't adjusted on whether the number is between two values.

The strategy is straightforward and bulletproof (if you allow a random generator of real numbers, otherwise you may keep tossing coins indefinitely): keep tossing coins until you get tails. If the number you saw is less than the number of heads you got, you don't switch.

For the simplest case assume that one envelope always contains 1 and another always contains 2. You choose one envelope randomly, so in 50% of cases you get 1, which you switch in 50% of cases. And in 50% of cases you get 2, which you switch in 25% of cases. Hence, you pick the higher number in 62.5% of cases. The same works with any numbers N, M; or any complex distributions; or even real numbers with a bit more complicated strategy. You don't have to know whether you are between two values in advance, you just have to guess.

btilly12/10/2024

No, I'm not doing anything other than tracking it. I'm doing that to show the user, "How much of this success was chance 50% choices, how much was guaranteed?" And so people can see how much of a good or bad result was blind luck versus the strategy successfully sticking a thumb on the scales.

In other words, I'm merely trying to be informative.