while (<>) {
chomp;
substr($_, length()/2, 0) = ' ';
- my ($c) = /(.)\S*\s\S*\1/;
- $sum += $c =~ /[A-Z]/
- ? ord($c) - ord('A') + 27
- : ord($c) - ord('a') + 1;
+ s/\A\S*(.)\S*\s\S*\1\S*\z/$1/;
+ $sum += /[A-Z]/
+ ? ord() - ord('A') + 27
+ : ord() - ord('a') + 1;
}
say $sum;
next if $. % 3;
$_ = $s;
$s = '';
- my ($c) = /(.)\S*\s\S*\1\S*\s\S*\1/;
- $sum += $c =~ /[A-Z]/
- ? ord($c) - ord('A') + 27
- : ord($c) - ord('a') + 1;
+ s/\A\S*(.)\S*\s\S*\1\S*\s\S*\1\S*\s?\z/$1/;
+ $sum += /[A-Z]/
+ ? ord() - ord('A') + 27
+ : ord() - ord('a') + 1;
}
say $sum;