From 14ff8f7593b85f21db546cf304c473148f0245f1 Mon Sep 17 00:00:00 2001 From: "Markus \"Holli\" Holzer" Date: Sat, 12 Sep 2020 03:02:53 +0200 Subject: #2 initial --- challenge-077/markus-holzer/raku/ch-2.input | 3 +++ challenge-077/markus-holzer/raku/ch-2.input.2 | 4 ++++ challenge-077/markus-holzer/raku/ch-2.raku | 14 ++++++++++++++ challenge-077/markus-holzer/raku/ch-2.twitter.raku | 5 +++++ 4 files changed, 26 insertions(+) create mode 100644 challenge-077/markus-holzer/raku/ch-2.input create mode 100644 challenge-077/markus-holzer/raku/ch-2.input.2 create mode 100644 challenge-077/markus-holzer/raku/ch-2.raku create mode 100644 challenge-077/markus-holzer/raku/ch-2.twitter.raku diff --git a/challenge-077/markus-holzer/raku/ch-2.input b/challenge-077/markus-holzer/raku/ch-2.input new file mode 100644 index 0000000000..32e25b69b9 --- /dev/null +++ b/challenge-077/markus-holzer/raku/ch-2.input @@ -0,0 +1,3 @@ +OOX +XOO +XOO diff --git a/challenge-077/markus-holzer/raku/ch-2.input.2 b/challenge-077/markus-holzer/raku/ch-2.input.2 new file mode 100644 index 0000000000..600d69c9a9 --- /dev/null +++ b/challenge-077/markus-holzer/raku/ch-2.input.2 @@ -0,0 +1,4 @@ +OOXO +XOOO +XOOX +OXOO diff --git a/challenge-077/markus-holzer/raku/ch-2.raku b/challenge-077/markus-holzer/raku/ch-2.raku new file mode 100644 index 0000000000..2e8917150e --- /dev/null +++ b/challenge-077/markus-holzer/raku/ch-2.raku @@ -0,0 +1,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 } \ No newline at end of file diff --git a/challenge-077/markus-holzer/raku/ch-2.twitter.raku b/challenge-077/markus-holzer/raku/ch-2.twitter.raku new file mode 100644 index 0000000000..0619e400fe --- /dev/null +++ b/challenge-077/markus-holzer/raku/ch-2.twitter.raku @@ -0,0 +1,5 @@ +unit sub MAIN($f); +my @i=$f.IO.lines.map:{.comb}; +sub a($m,$x,$y){my &n={$m[$x+.[0];$y+.[1]] andthen $_ eq "X"} +!((-1,-1),(-1,0),(-1,1),(0,-1),(0, 1),(1,-1),(1,0),(1,1)).grep: &n} +dd (^@i X ^@i.head).grep(->($x,$y){@i[$x;$y] eq "X" && @i.&a($x,$y)}) \ No newline at end of file -- cgit From af409e4fbda948f36ccb39265301aa23d75d2641 Mon Sep 17 00:00:00 2001 From: "Markus \"Holli\" Holzer" Date: Sat, 12 Sep 2020 03:04:18 +0200 Subject: #2 initial --- challenge-077/markus-holzer/raku/ch-2.raku | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-077/markus-holzer/raku/ch-2.raku b/challenge-077/markus-holzer/raku/ch-2.raku index 2e8917150e..4d36fbb2b5 100644 --- a/challenge-077/markus-holzer/raku/ch-2.raku +++ b/challenge-077/markus-holzer/raku/ch-2.raku @@ -9,6 +9,6 @@ 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" } + $matrix[ $x + $c[0]; $y + $c[1] ] andthen $_ eq "X" } @maybe-neighbours.grep( &is-neighbour ) == 0 } \ No newline at end of file -- cgit