in reply to Longest possible run of a single character
my ($count, $word) = &longest_repeat ($str, 4); sub longest_repeat () { my ($seq, $k) = @_; my $max_word = ""; my $max_count = 0; for (my $i = 0; $i < length ($seq) - $k; ++$i) { my $word = substr ($seq, $i, $k); my $count = 0; while (substr ($seq, $i + ($count * $k), $k) eq $word) { ++$count; } if ($count > $max_count) { $max_count = $count; $max_word = $word; } } return ($max_count, $max_word); }
|
---|