in reply to calculating cribbage points
Longest run: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;
All runs:@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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: calculating cribbage points
by Limbic~Region (Chancellor) on Mar 31, 2006 at 16:53 UTC | |
by ikegami (Patriarch) on Mar 31, 2006 at 19:22 UTC | |
|
Re^2: calculating cribbage points
by dracos (Sexton) on Mar 31, 2006 at 14:48 UTC | |
by ikegami (Patriarch) on Mar 31, 2006 at 19:29 UTC | |
|
Re^2: calculating cribbage points
by thor (Priest) on Mar 31, 2006 at 15:07 UTC |