aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-07-06 21:14:50 +0100
committerGitHub <noreply@github.com>2020-07-06 21:14:50 +0100
commit22d6d834b23aea22e15f4c54b01d60d9c35a7727 (patch)
treeb30d44e92ace80b7f86da49b7ee97bd3f858be2f
parent8164b11ba10da1d7a5d4241a393bad074b0a0cea (diff)
parent91c47b77cbb6c3eafc6ac198eeb6bc5b6cee71f3 (diff)
downloadperlweeklychallenge-club-22d6d834b23aea22e15f4c54b01d60d9c35a7727.tar.gz
perlweeklychallenge-club-22d6d834b23aea22e15f4c54b01d60d9c35a7727.tar.bz2
perlweeklychallenge-club-22d6d834b23aea22e15f4c54b01d60d9c35a7727.zip
Merge pull request #1914 from andemark/branch-for-challenge-068
Challenge 68 Solution 1
-rw-r--r--challenge-068/mark-anderson/raku/ch-1.raku47
-rw-r--r--challenge-068/mark-anderson/raku/slow-ch-1.raku31
2 files changed, 78 insertions, 0 deletions
diff --git a/challenge-068/mark-anderson/raku/ch-1.raku b/challenge-068/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..d42319fc1d
--- /dev/null
+++ b/challenge-068/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,47 @@
+#!/usr/bin/env raku
+
+my @matrix = [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 0, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1];
+
+my $rows = @matrix.elems;
+my $cols = @matrix[0].elems;
+
+my @zeroes = gather {
+ for ^$rows -> $r {
+ for ^$cols -> $c {
+ take [$r, $c] if @matrix[$r][$c] == 0;
+ }
+ }
+}
+
+my %seen_row;
+my %seen_col;
+
+for @zeroes -> $p {
+ unless %seen_row{$p[0]} {
+ @matrix[$p[0]] = [0 xx $cols];
+ %seen_row{$p[0]} = True;
+ }
+
+ unless %seen_col{$p[1]} {
+ @matrix.map({$_[$p[1]] = 0;});
+ %seen_col{$p[1]} = True;
+ }
+}
+
+say @matrix.join("\n");
diff --git a/challenge-068/mark-anderson/raku/slow-ch-1.raku b/challenge-068/mark-anderson/raku/slow-ch-1.raku
new file mode 100644
index 0000000000..40b2bef17f
--- /dev/null
+++ b/challenge-068/mark-anderson/raku/slow-ch-1.raku
@@ -0,0 +1,31 @@
+#!/usr/bin/env raku
+
+my @matrix = [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 0, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ [1, 1, 1, 1, 1, 1, 1, 1, 1];
+
+my @rows = (^@matrix).grep({@matrix[$_].any == 0});
+
+my @cols = (^@matrix[0]).grep({([Z] @matrix)[$_].any == 0});
+
+@matrix[$_] = [0 xx @matrix] for @rows;
+
+@matrix = [Z] @matrix;
+
+@matrix[$_] = [0 xx @matrix[0]] for @cols;
+
+say ([Z] @matrix).join("\n");