- $hist{$_}++ for @cards;
- return 1 if grep { $hist{$_} == 5 } @cards;
- return 2 if grep { $hist{$_} == 4 } @cards;
- return 3 if grep { $hist{$_} == 3 } @cards
- and grep { $hist{$_} == 2 } @cards;
- return 4 if grep { $hist{$_} == 3 } @cards;
- return 5 if (grep { $hist{$_} == 2 } @cards) == 4;
- return 6 if grep { $hist{$_} == 2 } @cards;
+ $hist{$_}++ for split //, shift;
+ my %rh;
+ $rh{$_}++ for values %hist;
+ return 1 if $rh{5};
+ return 2 if $rh{4};
+ return 3 if $rh{3} && $rh{2};
+ return 4 if $rh{3};
+ return 5 if $rh{2} && $rh{2} == 2;
+ return 6 if $rh{2};