Task 1: Echo Chamber
"Letter Amplification: When Each Letter Gets Its Moment to Shine!"
This week's first task involves transforming a string where each character is repeated based on its position (starting from 0). The character at index i is repeated i+1 times.
The Strategy: Iterate through each character with its index. For each character, repeat it (index + 1) times and append to the result.
Perl Implementation
sub echo_chamber {
my ($str) = @_;
$str =~ s/(.)/ $1 x (pos($str) + 1) /ge;
return $str;
}
Python Implementation
def echo_chamber(s: str) -> str:
result = ""
for i, char in enumerate(s):
result += char * (i + 1)
return result