Wednesday, April 27, 2011

Heads or Tails? or: how to lose money at the roulette table

I've always wondered how many heads/tails you'd get in a row if you could just keep flipping coins forever. The other day I was bored so I put together a stupid matlab script to try it out (leaving out the "forever" bit).

It's obvious that in theory you could get a never ending series of heads or tails, but in practice that is infinitely unlikely to happen, so I just wanted to get a feel for a "reasonable" figure in terms of how many repetitions one should expect to experience if one actually started tossing coins (or betting money on red/black at the roulette) for a very long time.

Out of 100 million series of coin tosses (where a series is defined by an uninterrupted streak of heads or tails) the longest streak of identical outcomes was 26 (I wanted to try with a billion series but was taking too long).

That means that if you go to a casino to make money doubling bets on red/black (the so-called Martingale strategy) and you are particularly unlucky you might have to flush out 20*(2^25) = 671,088,630 $ (a single bet is usually at least 20 $) on your last bet to actually make a profit (plus all the money you spent to get there).

If you play smart though, and you wait for 5 reds/blacks in a row before you start betting against that, then you can get away with a last bet of only 20*(2^20) = 20,971,520 $ (that's 20 millions!).


peter kelly said...

How many times did you run it? Was 26 the average "streak" or was it the longest? Interesting distraction!

Johnny Idol said...

Hi Peter, I ran it a bunch of times (3 or 4) - 100 million series of tosses each time - and 26 was the longest streak recorded. The average streak was (not surprisingly) 1!

Anonymous said...

You could have easily computed the probability of a streak having a specific length n >= 1 as 1/2^n, and so find out that the probability of a streak of length 26, like the one you observed, is 1.49 * 10^-8. Multiplying this probability by the number of trials (10^8), you get that the expected number of streaks of length 26 is 1.49... and you got yours! ;-)

Anonymous said...

Oh, and about the average length: if you compute the expected value as the infinite sum of n / 2^n for n >= 1, you get 2.

Johnny Idol said...

@anonymous yes, I could've calculated the probability no problem that way - but what I was really curious about (and could not infer from the probability) was the longest streak of identical outcomes that one may come up with over a huge number of tosses (100 million series was huge enough for my curiosity).