Quick actions

cmd+k|ctrl+k

Navigation

Languages

Advent of Code 2021, Day 13 Solutions

Snippet info

Language

Raku

Visibility

public

Author

seaker

Created

2021-12-13T06:59:44.604225Z

Updated

2021-12-13T07:01:30.262136Z

my ($dots-str, $fold-str) = $*IN.slurp.split("\n\n");

my %dots;
$dots-str.words».comb(/\d+/).map({ %dots{ "{ .[0] };{ .[1] }" } = '#' });

my $round = 0;
for $fold-str.lines».&{ .words[2].split('=') } -> ($d, $pos)  {
    my %new-dots;
    for %dots.keys».split(';')».UInt -> ($row, $col) {
        given $d {
            when 'x' { %new-dots{ "{ $row≤$pos ?? $row !! $pos*2-$row };$col" } = '#'; }
            when 'y' { %new-dots{ "$row;{ $col≤$pos ?? $col !! $pos*2-$col }" } = '#'; }
        }
    }
    %dots = %new-dots;
    put 'part 1: ', %dots.elems if $round++ == 0;
}

put 'part 2:';
my @pos = %dots.keys».split(';')».UInt;
for @pos.map(*[1]).minmax -> $y {
    put [~] (%dots{"$_;$y"} // ' ' for @pos.map(*[0]).minmax);
}
INFO