]> www.fi.muni.cz Git - aoc.git/blob - 2022/09.pl
Day 25: examining the input
[aoc.git] / 2022 / 09.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 use Data::Dumper;
19 print Dumper \@stacks;
20 scalar <>;
21
22 while (<>) {
23         my ($amount, $src, $dst) = /(\d+)/g;
24         push @{ $stacks[$dst-1] }, pop @{ $stacks[$src-1] } for 1 .. $amount;
25 }
26
27 for my $st (@stacks) {
28         print $st->[-1];
29 }
30 print "\n";
31