Oh, and here is my attempt (not golfed):
sub is_straight { my ($low,$high,$high_no_ace) = @_; return $low==2 ? ($high == 14 ? ($high_no_ace==5) : ($high == 6) ) : ($high-$low) == 4; } my %tr = (J => 11,Q => 12, K => 13, A => 14); @hand = map {s/^([JQKA])/$tr{$1}/;$_} @hand; my %suits; my %ranks; my $num_suits; my $num_ranks; my $low_rank = 100; my $high_rank = 0; my $high_rank_no_ace = 0; foreach my $card (@hand) { my ($r,$s) = $card =~ /(\d+)(.)/; if ($suits{$s}++ == 0) {$num_suits++} if ($ranks{$r}++ == 0) {$num_ranks++} $low_rank = min($r,$low_rank); $high_rank = max($r,$high_rank); $high_rank_no_ace = max($r,$high_rank_no_ace) unless $r == 14; } my @nranks = sort map {$ranks{$_}} keys %ranks; my $hand = 'high card'; { ($hand = 'straight flush',last) if $num_suits==1 && is_straight($low_rank,$high_rank,$high_rank +_no_ace); ($hand = 'four of a kind',last) if $nranks[1]==4; ($hand = 'full house',last) if $nranks[1]==3; ($hand = 'flush',last) if $num_suits==1; ($hand = 'straight',last) if $num_ranks == 5 && is_straight $low_rank,$high_rank,$high_ran +k_no_ace); ($hand = 'three of a kind',last) if $nranks[2]==3; ($hand = 'two pair',last) if $nranks[2]==2; ($hand = 'pair',last) if $nranks[3]==2; }


-pete
"Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."

In reply to Re: Golf/Elegance: Poker Hands by dreadpiratepeter
in thread Golf/Elegance: Poker Hands by dreadpiratepeter

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.