]> www.fi.muni.cz Git - aoc.git/blobdiff - 2022/10.pl
Day 25: examining the input
[aoc.git] / 2022 / 10.pl
index 913e078d860582ba3385330017e9e296b7ab438d..0dcf15f87c1d13ea6350b300118f09517a539408 100755 (executable)
@@ -8,14 +8,10 @@ my @stacks;
 
 while (<>) {
        last if /^ \d/;
-       my $i = 1;
-       my $st = 0;
-       $stacks[$st] //= [];
-       while ($i < length) {
-               my $c = substr($_, $i, 1);
-               unshift @{ $stacks[$st] }, $c if $c =~ /[A-Z]/;
-               $i += 4;
-               $st++;
+       my $i = 0;
+        for (/.(.). ?/g) {
+               unshift @{ $stacks[$i] }, $_ if /[A-Z]/;
+               $i++;
        }
 }