You are viewing a single comment's thread. Return to all comments →
Perl solution:
sub theLoveLetterMystery { my @s = split("", shift); my $cnt = 0; my $k = 0; my $left_part = 0; my $right_part = 0; while ($k < int(scalar(@s) / 2)) { $left_part = ord($s[$k]); $right_part = ord($s[scalar(@s) - $k - 1]); while ($left_part != $right_part){ if ($left_part < $right_part) { $cnt++; $right_part -= 1; } elsif ($left_part > $right_part) { $cnt++; $left_part -= 1; } } $k++; } return $cnt; }
Seems like cookies are disabled on this browser, please enable them to open this website
The Love-Letter Mystery
You are viewing a single comment's thread. Return to all comments →
Perl solution: