#!/usr/local/bin/perl -w use strict; $| = 1; my @all = ((5) x 6, (10) x 6); # twelve voters: six voting up to 5, six voting up to 10 for my $own (5, 10) { # your own vote my $i = 0; my @others = grep $_ != $own || $i++, @all; # remove your vote from the list for now... my(%r, %n); for (1 .. 5000) { my @voters = shuffle(@others); # shuffle the other votes splice @voters, my $pos = int(rand @voters+1), 0, $own; # put your vote back in, and save the position my $rep = 0; for my $v (@voters) { $rep++ if $rep < $v; } # calculate the reputation $r{$pos} += $rep; $n{$pos}++; # adjust the stats for this position } print "$own:\n"; for (sort { $a <=> $b } keys %n) { printf " %2d %4d %4.2f\n", $_, $n{$_}, $r{$_} / $n{$_}; } # print position, number of occurences, and average reputation } sub shuffle { my @list = @_; for (my $i = $#list; $i >= 0; --$i) { my $j = int rand $i + 1; @list[$i, $j] = @list[$j, $i]; } @list; }