Task 1: Group Position
"Triplet Tracker: Finding Long Consecutive Sequences!"
Identify all substrings of three or more consecutive identical letters in a given string.
The Strategy: Use a regular expression with a backreference to match any character followed by itself two or more times:
(.){2,}. In Python, re.finditer extracts all such non-overlapping matches. In Perl, a global match //g combined with proper handling of capturing groups yields the desired substrings.
Perl Implementation
sub group_position ($str) {
my @groups = ( $str =~ /((.){2,})/g );
my @result;
for ( my $i = 0; $i < @groups; $i += 2 ) {
push @result, $groups[$i];
}
return \@result;
}
Python Implementation
def group_position(text: str) -> list[str]:
return [match.group(0) for match in re.finditer(r"([a-z]){2,}", text)]