Heads and Tails Game - Part 1 of 2

Let's suppose that we play the following game:
  1. Pick a sequence of heads (H) and tails (T). Any sequence, of a reasonable length, say 10
  2. Suppose your sequence is HTTHTHTHTT. Call this sequence O (for Opponent)
  3. The computer will then pick a random sequence of same length
  4. Let's suppose the sequence is THHHHTTHHT. Call this sequence C (for Computer)
  5. We'll then start tossing coins up randomly, in sequence
  6. The first sequence (O or C) to be generated wins a point. Notice that Ad Infinitum eventually O or C will be generated (assuming a reasonably random random-number generator)
  7. Repeat steps 5 and 6 for 1M (one million) times
  8. Whoever has the most points wins :)
We then play this game, and this is one of the results ("I" means the computer):

Well, I win!!! :)
You win 499610 times (or 49.961% of the total)
And I win 500390 times (or 50.039% of the total)

Well, pretty close, it could have gone either way, near 50% chance of win to each party. OK, let's try again but changing the computer's random string to something else, such as TTTTTHTTTT:

You win!!! :)
You win 660232 times (or 56.8951669889593% of the total)
And I win 500204 times (or 43.1048330110407% of the total)

Not that close anymore. Yet again changing to something random such as HTHTHHHHTT, we then have:

You win!!! :)
You win 687640 times (or 50.0058540388141% of the total)
And I win 687479 times (or 49.9941459611859% of the total)

Pretty even again.

I guess by now you're wondering: "so what, the probability of victory either way will approach 50% over time, this is a complete random game".

Well...

OK, now the computer will generate something slightly smarter. Now let's just say that the sequence C will be a function of the sequence O, or in other words C = F(O). I'll get to that function later on, but let's try again the same input for O = HTTHTHTHTT but this time C = F(O):

Well, I win!!! :)
You win 374722 times (or 37.4722% of the total)
And I win 625278 times (or 62.5278% of the total)

Wow!!! The computer now wins with a mind-blowing 62.5% of chances! This is starting to not look random anymore. OK, we then change our input from the previous O to something a little different: O = THHHTHHHTH. We run our machine again:

Well, I win!!! :)
You win 286820 times (or 28.682% of the total)
And I win 713180 times (or 71.318% of the total)

Wait a minute, 71% chance of victory is far from being "random"!! Let's bite the bullet and have something very unique for O, such as O = HHHHHHHHHH. Run it again:

Well, I win!!! :)
You win 498754 times (or 39.9148170615568% of the total)
And I win 750792 times (or 60.0851829384432% of the total)

Better, but still no chance - the computer's chance of winning is still > 60%. Let's then try a longer sequence, very long, with a truly random permutation, such as O = HTTHTHHHTHTTTHTTTHTHHHHTHHTHTHTHTTTTTHTHTHHHHHTHTHHHTH. After all, the longer the sequence, the more likely the results will converge to 50-50. OK, the results:

Well, I win!!! :)
You win 135462 times (or 13.5462% of the total)
And I win 864538 times (or 86.4538% of the total)

Wait, what?! 86% of winning chances for the computer?!? What's going on??? I mean, really, one could come up with any crazy formula as much as one wants, but at the end of the day, both my sequence and the computer's sequence are just sequences just like any other, and they should occur with the same probability. Sure, running the tests many times might results in some slight variations, but with such a long length and with 1M runs, surely it should converge to 50-50. This is what fundamental statistics would tell us.

Well, but F(O) is a special function! It does wonders, and sure enough it can bring the chances of winning to anywhere from 60% to 90%, but always way north of 50%.

How does F(O) work? Stay tuned for the next episode......

Marcelo



Comments

Popular posts from this blog

Changing the root of a binary tree

ProjectEuler Problem 719 (some hints, but no spoilers)

Hard Leetcode Problem: Grid Illumination