X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=sidebyside;f=2022%2F06.pl;h=39b07aefabaa8a95607ed36ff2857ced034b2a94;hb=78136e93bf5e13aabceb8834ab3748187ee74eee;hp=31b1327f44ba95ee1a03e927caa4306c59e68d5a;hpb=4e8c8d806887ee71ff62d737aaf703f415b5336d;p=aoc.git diff --git a/2022/06.pl b/2022/06.pl index 31b1327..39b07ae 100755 --- a/2022/06.pl +++ b/2022/06.pl @@ -5,16 +5,15 @@ use strict; 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 = ''; + 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;