aboutsummaryrefslogtreecommitdiff
path: root/challenge-077/markus-holzer/raku/ch-2.raku
blob: 4d36fbb2b50656817da5fb22f17ab79f4fa68969 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
unit sub MAIN( $input-file );

my @input = $input-file.IO.lines.map: *.comb;

dd ( ^@input X ^@input.head ).grep( -> ($x, $y) { 
    @input[$x;$y] eq "X" && @input.&stands-alone($x, $y) });

sub stands-alone( $matrix, $x, $y ) {
    state @maybe-neighbours = (-1,-1), (-1,0), (-1,1), (0,-1), (0, 1), (1,-1), (1,0), (1,1);

    sub is-neighbour($c) { 
        $matrix[ $x + $c[0]; $y + $c[1] ] andthen $_ eq "X" }

    @maybe-neighbours.grep( &is-neighbour ) == 0 }