[LA.pm] The odds of finger games

Robert Spier rspier at pobox.com
Wed Mar 5 15:28:57 CST 2003


Apparently the finger circle thingy we did at the very fun meeting
last night actually is fair, as long as you assume that everyones hand
is a perfect RNG. 

(Of course, you can't assume that every person is a perfect random
number generator... but that's a different discussion.)

This little program simulates every possible possible combination of
five fingers and six people, builds up the sum, and then does the
mods.  The curve on the raw sums is just as we expected, peaking at
15... but once mod-ded it all balances out:

0: 7776
1: 7776
2: 7776
3: 7776
4: 7776
5: 7776

use strict;
use warnings;
use Set::CrossProduct;
my $people = 6;
my $fingers = 5;
my $hand = [0..$fingers];
my $it = Set::CrossProduct->new( [($hand)x $people] );
my %sums = ();
my %modsums = ();

while (my $tuple = $it->get) {
  my $t;
  $t += $_ for @$tuple;
  $sums{$t}++;
  $modsums{$t%$people}++;
}

# Output non-mod-ed values (sum of all fingers)
#print "$_: $sums{$_}\n"
#  for (sort {$a <=> $b} keys %sums);

# Output mod-ed values, i.e. "people"
print "$_: $modsums{$_}\n"
  for (sort {$a <=> $b} keys %modsums);



-R



More information about the Losangeles-pm mailing list