You're looking for something like this:
# without using hashes, as you requested sub group_cards_nohash { # convert initial string param into a sorted list of cards my @cards = sort { $a <=> $b } split / /, shift; my @tally; my $cnt = 1; # generate running tally of cards - we're going to remove # cards one at a time from the list, until it's empty while (@cards) { # remove a card my ($card, $tally) = (shift @cards, 1); # remove successive cards until there are none left, or # a card of a different value is encountered while (defined $cards[0] and $cards[0] == $card) { shift @cards; $tally++; # increment tally for every identical card } # add this tally to the results push @tally, $tally; } # return the tally sorted in reverse sort { $b <=> $a } @tally; } # though it's much more straightforward with the hash-based approach b +elow sub group_cards_hash { # convert initial string param into a sorted list of cards # notice that we don't need to sort this one my @cards = split / /, pop; my %tally; # tally the cards $tally{$_}++ foreach @cards; # return the tally sorted in reverse sort { $b <=> $a } values %tally; } print join ',', group_cards_hash('9 9 5 5 1'); print "\n"; print join ',', group_cards_nohash('9 9 5 5 1');
   MeowChow                                   
               s aamecha.s a..a\u$&owag.print

In reply to Re: Keeping track of Pairs by MeowChow
in thread Keeping track of Pairs by Satira

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.