djm4_lj: (Glasses)
[personal profile] djm4_lj
Tonight, Derren Brown explained a trick he did, involving 'influencing' coin tosses. The set up was as follows:

* He had a board showing the eight possible outcomes from three coin tosses.
* He got someone to pick one of the outcomes
* He picked another.
* Someone else then repeatedly flipped a coin until one of the sequences came up.
* Whoever picked the correct sequence scored a point.

The 'trick' was that he had an audience of people 'willing' his sequence to appear. The other person chose 'HHH'. Derren Brown chose 'THH'. Despite the fact that both sequences are, on the face of it, equally likely, Derren Brown won by (IIRC) nine points to one. Go audience!


As he explained, there is 'deeper maths' at work here, although in the case of the sequences picked here it's fairly easy to see why he won. The key is that you keep flipping the coin until the sequence comes up, which could be after three flips or after thirty, and then reset from a blank sequence. If you do it by repeatedly flipping sequences of three until one of them matches, the odds are even. If you keep flipping once you've matched to see the next sequence to come up, the odds are also even. But because of the fact that you stop and re-set once you've found the sequence, then in order to throw 'HHH' without having thrown 'THH' the turn before is to do it in the first three throws. You have a roughly one-in-eight chance of doing that; if you don't, the Derren Brown has won, because you'll never get an 'HHH' sequence without getting 'THH' first.

Derren Brown was lucky that the person picked 'HHH' ('TTT' would work too, of course), but in fact so long as you pick second, you can always find a sequence that's more likely to appear in the game, although not by odds as good at seven-to-one. Derren Brown mentioned this, but his method of finding the sequence was wonky. In fact, the sequences you should choose are as follows:

* First choice: your choice
* HHH: THH (wins 87.5% of the time)
* HHT: THH (75%)
* HTH: HHT (67%)
* HTT: HHT (67%)
* THH: TTH (67%)
* THT: TTH (67%)
* TTH: HTT (75%)
* TTT: HTT (87.5%)

As you can see, Derren Brown would have been able to show a reasonable influence whatever the first person picked, as long as you're expecting the sequences to have an equal chance of appearing.

Incidentally, I didn't get the 67% figures by maths - I can't quite see how to do that at the moment. Instead, I wrote a quick Perl program to calculate the probability matrix. I've included the program under the cut, if anyone wants to pick at it. ;-)

#! /usr/bin/perl -T
#
# Edit - I originally mistakenly posted a version of this after I'd been
# messing around with the parameters. I've restored the correct version,
# which generates the eight sequences of three coin tosses, and fixed 
# the sprintf line so that it generates head/tail sequences of the correct
# length depending on the parameter passed to the generate_tosses function.

use strict;
use warnings;

my @sequences = generate_tosses(3);

print "," . join(',', @sequences) . "\n";
foreach my $sequence1 (@sequences) {
  print "$sequence1";
  foreach my $sequence2 (@sequences) {
    my $percentage = who_wins($sequence1, $sequence2, 10000);
    print ",$percentage";
  }
  print "\n";
}

sub generate_tosses {
  my $count = shift || 1;
  my @toss_sequences = ();
  my $number_in_sequence = (2**$count) - 1;
  
  for (my $sequence_count = 0; $sequence_count <= $number_in_sequence; $sequence_count++) {
    my $sequence = sprintf('%0' . $count . 'b', $sequence_count);
    $sequence =~ tr/01/HT/;
    push @toss_sequences, $sequence; 
  }
  return @toss_sequences;
}
  

sub who_wins {
  my ($sequence1, $sequence2, $count) = @_;
  $count ||= 1000;
  my $tally = $count;
  my $window = length($sequence1);
  for (my $iloop = 0; $iloop < $count; $iloop++) {
    my $sequence_so_far = '';
    my $matched = 0;
    while (!$matched) {
      my $flip = int(rand(2));
      if ($flip == 0) {
        $sequence_so_far .= 'H';
      } else {
        $sequence_so_far .= 'T';
      }
      if (substr($sequence_so_far, -$window) eq $sequence1) {
        $matched = 1;
        $tally++;
      } elsif (substr($sequence_so_far, -$window) eq $sequence2)  {
        $matched = 1;
        $tally--;
      }
    }
  }
  my $percentage = (($tally * 100)/(2 * $count));
  return (sprintf('%.2f', $percentage));
}

Date: 2009-09-11 11:15 pm (UTC)
From: [identity profile] vicki-t-veg.livejournal.com
It's like the car under the cup trick, old marketing game by some company I forget which.

Date: 2009-09-12 12:26 am (UTC)
ext_28046: (Default)
From: [identity profile] prolificdiarist.livejournal.com
Squee, geeklove!

*Grin!*

Date: 2009-09-12 06:36 am (UTC)
From: [identity profile] bethanthepurple.livejournal.com
The guy who did our healthy eating assembly yesterday made a goldfish bowl appear out of a bag appear out of a wallet. Frankly, He impresses me more.

Date: 2009-09-12 10:32 am (UTC)
From: [identity profile] ciphergoth.livejournal.com
I'm not sure exactly how to do it "by maths", but here's an approximation that assumes there will be fewer than 1024 coin tosses. It works by treating it as a state machine with a transition matrix, and applying the transition matrix lots:
#!/usr/bin/python

from numpy import matrix

tstates = ["HH", "HT", "TH", "TT"]

def tosscolumn(x, a):
    res = [0] * (4 + len(a))
    for n in ["H", "T"]:
        if x + n in a:
            res[4 + a.index(x + n)] += 0.5
        else:
            res[tstates.index((x + n)[1:])] += 0.5
    return res

def tosscolumns(a):
    return [tosscolumn(x, a) for x in tstates]

def fixcolumns(a):
    return [[0]*4 + [int(i == j) for j in range(len(a))]
        for i in range(len(a))]

def tossmatrix(a):
    return matrix(tosscolumns(a) + fixcolumns(a)).transpose()

def winodds(*a):
    initialodds = matrix([0.25]*4 + [0]*len(a)).transpose()
    m = tossmatrix(a)
    finalodds = (m ** 1024) * initialodds
    return [float(finalodds[i + 4][0]) for i in range(len(a))] 

print winodds("HHH", "THH")


Update: ah, here's how to do it by maths. I think eigenvectors come in to it :-)
Edited Date: 2009-09-12 10:45 am (UTC)

Date: 2009-09-12 04:21 pm (UTC)
lovingboth: (Default)
From: [personal profile] lovingboth
I first came across this one in a 1970s book called something like 'Never Give a Sucker an Even Break' which is full of amusing ways to make money off people.

Yay for allowing people to pick first in non-transitive situations...

Profile

djm4_lj: (Default)
djm4_lj

July 2015

S M T W T F S
    1234
567891011
12131415161718
19202122232425
262728293031 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 26th, 2025 04:46 pm
Powered by Dreamwidth Studios