my $sum;
while (<>) {
chomp;
- my $len = length;
- my ($l, $r) = (substr($_, 0, $len/2), substr($_, $len/2));
- for my $c (split(//, $l)) {
- next if $r !~ /$c/;
- $sum += ord($c) - ord('A') + 27 if $c =~ /[A-Z]/;
- $sum += ord($c) - ord('a') + 1 if $c =~ /[a-z]/;
- say $c;
- last;
- }
+ substr($_, length()/2, 0) = ' ';
+ my ($c) = /(.)\S*\s\S*\1/;
+ $sum += $c =~ /[A-Z]/
+ ? ord($c) - ord('A') + 27
+ : ord($c) - ord('a') + 1;
}
say $sum;
use experimental 'multidimensional';
my $sum;
-chomp (my @bags = <>);
-
-while (my @a = splice(@bags, 0, 3)) {
- for my $c (split(//, $a[0])) {
- next if $a[1] !~ /$c/;
- next if $a[2] !~ /$c/;
- $sum += ord($c) - ord('A') + 27 if $c =~ /[A-Z]/;
- $sum += ord($c) - ord('a') + 1 if $c =~ /[a-z]/;
- say $c;
- last;
- }
+my $s;
+while (<>) {
+ $s .= $_;
+ 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;
}
say $sum;