Skip to content

Instantly share code, notes, and snippets.

@hoehrmann
Created April 15, 2012 15:56
Show Gist options
  • Save hoehrmann/2393552 to your computer and use it in GitHub Desktop.
Save hoehrmann/2393552 to your computer and use it in GitHub Desktop.
Quick and dirty run lengths
sub run_lengths {
return unless @_ > 0;
my $prev = shift @_;
my @runs = [$prev, 1];
for (@_) {
if ($_ eq $prev) {
$runs[-1]->[1]++;
next;
}
push @runs, [$_, 1];
$prev = $_;
}
@runs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment