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.

In reply to Re: army building by zengargoyle
in thread army building by dshahin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.