]> www.fi.muni.cz Git - aoc.git/commitdiff
Day 3: use $_ everywhere
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Sat, 3 Dec 2022 06:10:22 +0000 (07:10 +0100)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Sat, 3 Dec 2022 06:10:22 +0000 (07:10 +0100)
2022/05.pl
2022/06.pl

index a7e1f9db71bcd52fbef00ca118a04c726d97e9a8..5002bf9dd103d0b4c6e71fb59394d1bf1cd2f33d 100755 (executable)
@@ -8,9 +8,9 @@ my $sum;
 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;
index 84ea0fbe44a073f51e7525f4c514ca08bd73f124..39b07aefabaa8a95607ed36ff2857ced034b2a94 100755 (executable)
@@ -11,9 +11,9 @@ while (<>) {
        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;