in reply to Re^7: Array problem
in thread Array problem
I don't see any unfairness.
Okay, try running this and see if it changes your mind.
Over time, the variance should tend to converge towards zero for all choices, but every time I run this, one or two of the choices show no signs of converging. Indeed, their variance just seems to grow. Not mathematical proof of unfairness--I can't work out how to apply a Chi Squared test to this kind of data--but sufficient to convince me that there is something hookey.#! perl -slw use strict; our $N ||= 1e6; my %stats; my @data = 'A' .. 'Z'; for my $n ( 1 .. $N ) { my @scratch = @data; foreach my $first ( @data ) { for my $j ( reverse $#scratch -2 .. $#scratch ) { my $r = rand( $j + 1 ); @scratch[ $j, $r ] = @scratch[ $r, $j ]; if( $scratch[ $j ] eq $first ) { my $r = rand $j; @scratch[ $j, $r ] = @scratch[ $r, $j ]; } } ++$stats{ $_ } for @scratch[ -3 .. -1 ]; } system 'cls'; printf "%8d\n", $n; printf "%s : %6d ( %+3d ) %s\n", $_, $stats{ $_ }, $stats{ $_ } - ( 3 * $n ), '#' x abs( $stats{ $_ } - ( 3 * $n ) ) for @data; }
BTW, you'll need a wide terminal to see the effect at it's best. Mine is set to 1000 wide. Setting a small font also helps as the numbers grow.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: Array problem
by ikegami (Patriarch) on Sep 29, 2008 at 04:57 UTC | |
|
Re^9: Array problem
by JavaFan (Canon) on Sep 29, 2008 at 09:42 UTC | |
by BrowserUk (Patriarch) on Sep 29, 2008 at 15:22 UTC |