Quick actions

cmd+k|ctrl+k

Navigation

Languages

AoC 2022, day 5

Snippet info

Language

Raku

Visibility

public

Author

seaker

Created

2022-12-05T06:37:08.40523Z

Updated

2022-12-05T07:55:40.669635Z

my ($stacks, $actions) = $*IN.slurp.split("\n\n");
my @stacks = $stacks.lines;
my \width = @stacks.pop.comb(/\d+/).elems;

my @S1 = [] xx (width + 1);
for @stacks».comb -> @L {
    my @a = @L[1, 5 ... width * 4 - 1];
    for ^width -> \j {
        @S1[j+1].push(@a[j]) unless @a[j] eq ' ';
    }
}

my @S2 = @S1.deepmap(*.clone);

for $actions.lines».comb(/\d+/)».Int -> (\quantity, \from, \to) {
    @S1[to].unshift(@S1[from].shift) for ^quantity;
    @S2[to].unshift(|@S2[from].splice(0, quantity));
}

put 'part 1: ', @S1[1..width;0].join;
put 'part 2: ', @S2[1..width;0].join;
INFO