2023 AoC Day 22 – Sand Slabs

This is a solution to Advent of Code 2023 day 22, written in Raku.

https://adventofcode.com/2023/day/22

Part One

Figure how the blocks will settle based on the snapshot. Once they've settled, consider disintegrating a single brick; how many bricks could be safely chosen as the one to get disintegrated?

constant \x = 0; constant \y = 1; constant \z = 2;
my @bricks = '22-test.txt'.IO.lines>>.comb(/\d+/)>>.Int>>.rotor(3);

my @stack[330;10;10];

for @bricks.kv -> $k, @v {
    for @v[0][x] .. @v[1][x] -> $x {
        for @v[0][y] .. @v[1][y] -> $y {
            for @v[0][z] .. @v[1][z] -> $z {
                @stack[$z;$y;$x] = $k;
            }
        }
    }
}
say @stack;

Part Two

constant \x = 0; constant \y = 1; constant \z = 2;
my @bricks = '22-input.txt'.IO.lines>>.comb(/\d+/)>>.Int>>.rotor(3);
say @bricks.map(
    -> @b {
        @b[0][z] max @b[1][z]
    }).max;
327
say (3,4,5) >>->> 1
(2 3 4)
raku