in reply to army building

i saw something like this here on PM before...

#!/usr/bin/perl use strict; use warnings; my $points = shift @ARGV; # @player = ( [ value, rank, name ], ... ) # likely to sort by value,rank or rank,value my @player = map { chomp; [ (split ':', $_)[2,1,0] ] } <DATA>; sub print_player { sprintf "%s(%s)[%d]$/", @{$_[0]}[2,1,0]; } # the sort determines the order you try to get the most of, # i'm going for more guys with big values. @player = sort {$b->[0] <=> $a->[0]} @player; my $pointbuff = 'x' x $points; my $re = join '', map("((?:x{$_->[0]})*)", @player), '(x*)'; my @counts = $pointbuff =~ /$re/; # so fooguy(a)[4] and barguy(b)[3] would give # '((?:x{4})*)((?:x{3})*)(x*)' # the final capture being what's left over. # # with points = 11 # pointbuff = xxxxxxxxxxx # which maches xxxx twice and then xxx once with none left over. my @match = map {[ $_, shift @counts ]} @player; print "$points points will get you:$/"; foreach my $match (@match) { printf "%d %s", length($match->[1]) / $match->[0][0], print_player($match->[0]); } printf "with %d left over.$/", length $counts[0]; __DATA__ blastaar:v:138 mr fixit:u:104 daredevil:r:30 blob:v:51 boomerang:e:34 wolverine:e:61 skrull commando:v:18

i don't remeber if there's a way to make it cycle through all possible matches or not.

./game.pl 4096 4096 points will get you: 29 blastaar(v)[138] 0 mr fixit(u)[104] 1 wolverine(e)[61] 0 blob(v)[51] 0 boomerang(e)[34] 1 daredevil(r)[30] 0 skrull commando(v)[18] with 3 left over.