my %count;
++$count{$_} foreach @c;
my @pairs = grep { $count{$_} >= 2 } sort { $b <=> $a } @c;
my @kind3 = grep { $count{$_} >= 3 } @pairs;
my @kind4 = grep { $count{$_} >= 4 } @kind3;
####
@c = sort { $b <=> $a } @c;
my $lr_len = 0;
my $lr_idx;
my $s = 0;
while ($s <= 4) {
my $e = $s+1;
++$e while $e <= 4 && $c[$e] == $c[$e-1] - 1;
if ($e-$s > $lr_len) {
$lr_len = $e-$s;
$lr_idx = $s;
}
$s = $e;
}
##
##
@c = sort { $b <=> $a } @c;
my @runs;
my $s = 0;
while ($s <= 4) {
my $e = $s+1;
++$e while $e <= 4 && $c[$e] == $c[$e-1] - 1;
if ($e-$s > 1) {
push(@runs, [ map { $c[$_] } $s..$e-1 ]);
$lr_idx = $s;
}
$s = $e;
}
# Sort by length, then by highest.
@runs = sort { @$b <=> @$a || $b->[0] <=> $a->[0] } @runs;