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); }
In reply to Re: Longest possible run of a single character
by Anonymous Monk
in thread Longest possible run of a single character
by srdst13
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |