]> www.fi.muni.cz Git - aoc.git/blobdiff - 2022/05.pl
Day 25: examining the input
[aoc.git] / 2022 / 05.pl
index 1a787996af13a87a422ca2f928406a7a406dd300..5002bf9dd103d0b4c6e71fb59394d1bf1cd2f33d 100755 (executable)
@@ -7,14 +7,10 @@ use experimental 'multidimensional';
 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) = ' ';
+       s/\A\S*(.)\S*\s\S*\1\S*\z/$1/;
+       $sum += /[A-Z]/
+               ? ord() - ord('A') + 27
+               : ord() - ord('a') + 1; 
 }
 say $sum;