sub init_selections { my $self = shift; my $slice_count = shift; my $cur_balances = $self->{cur_balances}; my $balance = 0; $balance += $_ foreach @$cur_balances; my @selections; my $select = 0; my $cur_balance = $cur_balances->[0]; foreach my $i (1..$slice_count) { # Move move selected forward until we are at the current # position. while ($cur_balance < ($balance * $i / $slice_count)) { $cur_balance += $cur_balances->[++$select]; } push @selections, $select; } return $self->{selections} = \@selections; }