]> www.fi.muni.cz Git - aoc.git/blob - 2022/05.pl
Day 3: it took too long to write this.
[aoc.git] / 2022 / 05.pl
1 #!/usr/bin/perl -w
2
3 use v5.36;
4 use strict;
5 use experimental 'multidimensional';
6
7 my $sum;
8 while (<>) {
9         chomp;
10         my $len = length;
11         my ($l, $r) = (substr($_, 0, $len/2), substr($_, $len/2));
12         for my $c (split(//, $l)) {
13                 next if $r !~ /$c/;
14                 $sum += ord($c) - ord('A') + 27 if $c =~ /[A-Z]/;
15                 $sum += ord($c) - ord('a') +  1 if $c =~ /[a-z]/;
16                 say $c;
17                 last;
18         }
19 }
20 say $sum;