]> www.fi.muni.cz Git - aoc.git/blob - 2022/10.pl
Day 25: examining the input
[aoc.git] / 2022 / 10.pl
1 #!/usr/bin/perl -w
2
3 use v5.36;
4 use strict;
5 use experimental 'multidimensional';
6
7 my @stacks;
8
9 while (<>) {
10         last if /^ \d/;
11         my $i = 0;
12         for (/.(.). ?/g) {
13                 unshift @{ $stacks[$i] }, $_ if /[A-Z]/;
14                 $i++;
15         }
16 }
17
18 scalar <>;
19
20 while (<>) {
21         my ($amount, $src, $dst) = /(\d+)/g;
22         push @{ $stacks[$dst-1] }, splice @{ $stacks[$src-1] }, -$amount, $amount;
23 }
24
25 for my $st (@stacks) {
26         print $st->[-1];
27 }
28 print "\n";
29