A brain teasing probability puzzle

Tuco

I got Tuco'd!
<Gold Donor>
45,430
73,490
btw if someone knows how to calculate the average payout I'd like to see it. I think it'd be a summation from 1->infinite with x^2 and 0.5 mixed in but I don't really know how to do it.
 

Szlia

Member
6,561
1,318
From my model about $13
wink.png
Did you run it just the once? I would expect avgVal to be all over the place considering the expected result is infinite and the deviation not a lot smaller.

expectedResult = (1/2)*1 + (1/4)*2 + (1/8)*4 + ... + (1/2^n)*2^(n-1) + ...

since (1/2^n)*2^(n-1) = (2^(n-1))/(2^n) = 1/2 expectedResult does not converge.


As to the question of whether or not a casino would run such a lottery... just imagine Loki is running the casino as a practical joke or something and that he is creating money out of thin air.
 

Tuco

I got Tuco'd!
<Gold Donor>
45,430
73,490
Did you run it just the once? I would expect avgVal to be all over the place considering the expected result is infinite and the deviation not a lot smaller.

expectedResult = (1/2)*1 + (1/4)*2 + (1/8)*4 + ... + (1/2^n)*2^(n-1) + ...

since (1/2^n)*2^(n-1) = (2^(n-1))/(2^n) = 1/2 expectedResult does not converge.


As to the question of whether or not a casino would run such a lottery... just imagine Loki is running the casino as a practical joke or something and that he is creating money out of thin air.
I ran it 100000000 times (literally, check out the while(i<100000000) { } statement, that's C++ code for "Run this shit 100000000 times bro" as long as you're increasing i each time it goes through.)
 

Szlia

Member
6,561
1,318
I got that. What I am saying is that if you run your code another time, your average might not be anywhere close to 13 despite the sample size. I tried to test it myself, but I forgot most of the little I knew about C, so I am not sure what I need to include for your code to compile.
 

The Master

Bronze Squire
2,084
2
Theexpectedpayout, based on statistical models, is not infinite though, nor is it even very large, is my point.
It is infinite based on statistics, that is what the sigma notation in the wiki article is telling you. That is the point of the problem... foddon is right about why all those other games are not infinite. They are programmed/designed to be non-infinte, no matter what. Which is precisely why this game, as stated, would never be run by a casino. They would do what they do withevery other gamethat has potential to be infinite: put an arbitrary cap on it. Just like they do with roulette. Now at that point the average return is easy to figure out and they would charge slightly more than that. However no one would play it, because without the possibility of infinite money such a game is frankly boring, as you noted.
 

Melvin

Blackwing Lair Raider
1,399
1,168
I got that. What I am saying is that if you run your code another time, your average might not be anywhere close to 13 despite the sample size. I tried to test it myself, but I forgot most of the little I knew about C, so I am not sure what I need to include for your code to compile.
Like I mentioned earlier, I'm a little concerned about the consistency of rand() (but not concerned enough to say that it's not good enough for our purposes). I ran Tuco's code essentially unmodified, and got the exact same numbers. I was interested in seeing how the averages changed over time, but wanted a little coarser scale than the commented out lines, so I made it output every time "i" went up an order of magnitude, then ran it 1,000,000,000 times. I would have added another zero and let it run overnight, but for some reason using long long ints for i and iMag caused some kind of problems that I can't even begin to diagnose.

tl;dr:
Yep, playing 10 times as long increased the average win ~41%, or at least it does withtheseparticular loaded dice.
 

Szlia

Member
6,561
1,318
A good sign rand() is fubared is that you getexactlythe same results as Tuco at the 100000000 mark even though the values are not converging.
 

Tuco

I got Tuco'd!
<Gold Donor>
45,430
73,490
A good sign rand() is fubared is that you getexactlythe same results as Tuco at the 100000000 mark even though the values are not converging.
Hehe, that's exactly how rand() is supposed to work, it's not fubared.

fromrand - C++ Reference
This number is generated by an algorithm that returns a sequence of apparently non-related numbers each time it is called. This algorithm uses a seed to generate the series, which should be initialized to some distinctive value using function srand.

This means that if you seed it with the number 5 and call it a 1000 times it will return the same 1000 numbers. This makes it very useful for certain simulations (Because you can have a semi-random but repeatable simulation).

If you want some more random you can seed it with a different number before you start calling it. Giving it a timestamp is popular because you'll never give it that seed again:
srand (time(NULL));

You could also hash the time() value if you're afraid it won't properly cast to unsigned int, you could use the C++ random (- C++ Reference) and there's probably other random libraries to use.


output:
avgVal:[11.69] avgIt:[ 2.00] max:[ 8388608] maxTimeToTails:[ 24]
avgVal:[15.24] avgIt:[ 2.00] max:[ 16777216] maxTimeToTails:[ 25]
avgVal:[11.55] avgIt:[ 2.00] max:[ 8388608] maxTimeToTails:[ 24]
avgVal:[12.51] avgIt:[ 2.00] max:[ 8388608] maxTimeToTails:[ 24]
avgVal:[10.95] avgIt:[ 2.00] max:[ 4194304] maxTimeToTails:[ 23]
avgVal:[11.17] avgIt:[ 2.00] max:[ 8388608] maxTimeToTails:[ 24]
avgVal:[12.16] avgIt:[ 2.00] max:[ 8388608] maxTimeToTails:[ 24]
avgVal:[14.22] avgIt:[ 2.00] max:[ 16777216] maxTimeToTails:[ 25]
avgVal:[13.13] avgIt:[ 2.00] max:[ 8388608] maxTimeToTails:[ 24]
avgVal:[13.18] avgIt:[ 2.00] max:[ 8388608] maxTimeToTails:[ 24]


Now the reason why you see so much variance in these is because it's sort of emulating a lottery. If you were look at the counts of who won what times you'd probably see very few at the high end.
 

Tuco

I got Tuco'd!
<Gold Donor>
45,430
73,490
I couldn't help myself:
Note that those win counts are over all ten games. So in one game that guy that won 24 times skewed the whole fucking result a bunch. If he didn't win that time it'd be way over.

Another cool observations that are intuitive if you think about it is each win count is roughly twice that of the next win count. So 5million suckers lost their first time, but only 2.5 million suckers lost their second time. And if you were to tabulate up the people who didn't lose their first time you'd get 5 million people! This is pretty basic stuff but if you're a nerd it's a little beautiful.

Theoretically if you increased the thing to run for a very long time (overnight etc) in most random systems you'd see them settle around a number. However because the payout increases exponentially this game is very resilient to that. If you were to cap the maximum to 10-20 you'd probably see things stabilize much more.
 

Erronius

Macho Ma'am
<Gold Donor>
16,478
42,396
This means that if you seed it with the number 5 and call it a 1000 times it will return the same 1000 numbers. This makes it very useful for certain simulations (Because you can have a semi-random but repeatable simulation).

If you want some more random you can seed it with a different number before you start calling it. Giving it a timestamp is popular because you'll never give it that seed again:
srand (time(NULL));
No wonder I keep getting the same Minecraft maps!
 

BrutulTM

Good, bad, I'm the guy with the gun.
<Silver Donator>
14,441
2,223
Not sure if you guys are understating how it works. If you pay $5 to play you'd need 3 heads in a row before you actually win anything. Odds are against that so the casino will win much more often.
Yeah, the odds of 3 heads in a row is 8:1 and it would pay out 8:5. The casino would be all over that shit. I think that to be "fair" the initial bet should be 1 dollar since both the pot and the odds of winning double with each coin flip.
 

Ambiturner

Ssraeszha Raider
16,040
19,500
Yeah, the odds of 3 heads in a row is 8:1 and it would pay out 8:5. The casino would be all over that shit. I think that to be "fair" the initial bet should be 1 dollar since both the pot and the odds of winning double with each coin flip.
But then you could never lose any money, so how is that "fair" to the casino?
 

BrutulTM

Good, bad, I'm the guy with the gun.
<Silver Donator>
14,441
2,223
But then you could never lose any money, so how is that "fair" to the casino?
You're right, I forgot the part where you actually win on the tails. The casino also has risk because the payout keeps going up with consecutive heads but what they take in is static. Probably $3 would work out fairly well.

That is still a big winner for the casino. You have to get at least 2 heads in a row to win anything and the payout is always lower than the odds. I could be fucking this up somewhere as well. My last probability class was in like 2000. I think I will stick to craps and blackjack.
 

Tuco

I got Tuco'd!
<Gold Donor>
45,430
73,490
You're right. Any other HOS candidates? I really haven't felt like any threads have met the bar.