Something different...
use strict; use warnings; use List::Util qw( shuffle );
{ my %val; @val{2..10,qw(J Q K A)} = (2..14); my @hand_names = ( [ 'Straight Flush' => qr/^<(.)xxxx((?>x*))><\1\2xxx><\1\2xx><\1 +\2x><\1\2>/ ], [ 'Straight Flush' => qr/^<(.)x{14}><\1x{5}><\1x{4}><\1x{3}><\1 +x{2}>/ ], [ 'Four of a Kind' => qr/<.((?>x*))>(?:.*<.\1>){3}/ + ], [ 'Full House' => qr/^<.((?>x*))>(?>(?:<.\1>){1,2})<.((?>x* +))>(?>(?:<.\2>)*)\z/ ], [ 'Flush' => qr/^<(.)(?>x*)>(?:<\1(?>x*)>){4}\z/ + ], [ 'Straight' => qr/^<.xxxx((?>x*))><.\1xxx><.\1xx><.\1x>< +.\1>/ ], [ 'Straight' => qr/^<.x{14}><.x{5}><.x{4}><.x{3}><.x{2}>/ + ], [ 'Three of a Kind' => qr/<.((?>x*))>(?:.*<.\1>){2}/ + ], [ 'Two Pair' => qr/<.((?>x*))><.\1>.*<.((?>x*))><.\2>/ + ], [ 'One Pair' => qr/<.((?>x*))><.\1>/ + ], ); sub hand_name { my $hand = join '', sort { length($b) <=> length($a) } map { /^(.+)(.)/; "<$2".("x" x $val{$1}).">" } @_; for (@hand_names) { my ($hn, $re) = @$_; return $hn if $hand =~ $re; } return 'High Card'; } }
{ my @hand = (@ARGV ? @ARGV : ( shuffle map { $_.'H', $_.'S', $_.'D', $_.'C' } 2..10,qw(J Q + K A) )[0..4] ); print join(', ', @hand) . ' is a ' . hand_name(@hand) . "\n"; }

In reply to Re: Golf/Elegance: Poker Hands by ikegami
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.