(OT) mathematicians-discover-prime-conspiracy

Peter Lebbing peter at digitalbrains.com
Fri Mar 18 13:18:36 CET 2016

On 14/03/16 10:37, Fulano Diego Perez wrote:
> https://www.quantamagazine.org/20160313-mathematicians-discover-prime-conspiracy/

So forgive me for the off-topicness, but something in the text caught my

> Soundararajan was drawn to study consecutive primes after hearing a
> lecture at Stanford by the mathematician Tadashi Tokieda, of the
> University of Cambridge, in which he mentioned a counterintuitive
> property of coin-tossing: If Alice tosses a coin until she sees a
> head followed by a tail, and Bob tosses a coin until he sees two
> heads in a row, then on average, Alice will require four tosses while
> Bob will require six tosses (try this at home!), even though
> head-tail and head-head have an equal chance of appearing after two
> coin tosses.

I did try this at home; only I wrote a Python script to do all the
tedious tossing and accounting. This is its output:

> $ ./cointoss HH HT
> H                   T                   HH                  HT                  
> ----------          ----------          ----------          ----------          
> 59821 (49.9%)       60079 (50.1%)       6.044               3.990               

After over a million coin tosses, it takes 6 tosses on average until you
see two heads in a row, but only 4 to see head-tail. Obviously, the
script is attached. Supply the patterns on invocation, as shown above.
Any number of patterns of any length are supported (I think). Well,
strictly positive numbers and lengths :).

Can someone point me in the direction of the solution to this
counterintuitive probability theory result? Any of a common name for the
property, a mathematical explanation or an intuitive explanation are
much appreciated!

Anyway, to make up for the off-topicness, let's get slightly on-topic...

To the OP: Please provide at least a short abstract of the text when you
post a link. That way people can tell from your mail what the text will
be about.

With regards to the article, I'm surprised by the choice of words in its
title. Other than to draw in more readers, I don't see what place the
word "conspiracy" has in it. That's like saying 0 and 1 are conspiring
to be consecutive on the integral number line. Oh no, pretty much all
are computers are based on 0's and 1's and now they are conspiring!
Probably against us! Quick, we need neutral numbers without an agenda...
In my opinion, this title really devalues the article. "Three secret
ways to cope with prime conspiracy mathematicians don't want you to know
about" isn't that much further out. Oh, I hope that phrasing doesn't
tickle any spam filters... Ah well.



I use the GNU Privacy Guard (GnuPG) in combination with Enigmail.
You can send me encrypted mail if you want some privacy.
My key is available at <http://digitalbrains.com/2012/openpgp-key-peter>
-------------- next part --------------

import collections
import sys
import re
import random

import blessings

class Observer(object):
    def __init__(self, pattern):
        self.pattern = pattern
        self.hist = collections.deque(maxlen=len(pattern))
        self.hits = 0
        self.run = 0

    def toss(self,face):
        if (''.join(self.hist) == self.pattern):
            self.hits += 1
            self.run = 0
            self.run += 1

class CoinToss(object):
    def __init__(self,argv):
        if (len(argv) < 2):
            print('Usage: {} PATTERN [PATTERN]...')
        self.os = list()
        self.labels = ['H', 'T']
        for a in argv[1:]:
            if (re.fullmatch('[HT]+', a) is None):
                print('Patterns consist of H and T only')
        self.term = blessings.Terminal()
        self.tosses = 0
        self.heads = 0
        self.tails = 0

    def toss(self,face):
        self.tosses += 1
        if (face == 'H'):
            self.heads += 1
            self.tails += 1
        for o in self.os:

    def run(self):
        while True:
            for i in range(100):
                self.toss(random.choice(['H', 'T']))

    def print_data(self):
        data = list()
        for x in [self.heads, self.tails]:
            data.append('{} ({:2.1%})'.format(x, x / self.tosses))
        for o in self.os:
            if o.hits == 0:
                v = (self.tosses - o.run) / o.hits
        for b in range((len(self.labels)-1) // 4 + 1):
            for l in self.labels[b * 4:(b + 1) * 4]:
                print(' ' * (20-len(l)),end='')
            for l in self.labels[b * 4:(b + 1) * 4]:
                c = max(len(l), 10)
                print('-' * c,end='')
                print(' ' * (20-c), end='')
            for d in data[b * 4:(b + 1) * 4]:
                print(' ' * (20-len(d)), end='')
        print(self.term.move_up * 5 * ((len(self.labels) - 1) // 4 + 1),end='')

if __name__ == '__main__':
    c = CoinToss(sys.argv)

More information about the Gnupg-users mailing list