sub sum {$t=0; foreach (@_) {$t+=$_;} return $t;}

sub fudge_numbers {
   ($precision,@n)=@_; $factor = 10 ** ($precision+2); $s=sum(@n); @pcts=();
   foreach $v (@n) {$pct = int(int($v/$s*$factor*10)/10+.5); push @pcts,$pct;}
   $diff = sum(@pcts)-$factor; $spread=abs($diff);
   if ($spread) { $delta=$diff/$spread; $count = 0;
           FIND: foreach $v (@pcts) { if (@pcts[$count] > 1) {
            @pcts[$count] -= $delta;
            $spread--; last FIND if ! $spread;}
            $count++;} }
   $count = 0;
   foreach $pct (@pcts) { @n[$count] = $pct/(10 ** $precision); $count++;
}
   return @n;
}

