aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-07-06 12:11:44 +0100
committerGitHub <noreply@github.com>2020-07-06 12:11:44 +0100
commitb9f0eba10c5d82ad61f059331730a613653c7384 (patch)
treea2732b9e1354ea19f3eb4d086cad3d4d3a689012
parent39015be235d69244050c27121aca228b7be77e5e (diff)
parent12955fd0811be31d2de6d1194d3c9ba5dd276e5d (diff)
downloadperlweeklychallenge-club-b9f0eba10c5d82ad61f059331730a613653c7384.tar.gz
perlweeklychallenge-club-b9f0eba10c5d82ad61f059331730a613653c7384.tar.bz2
perlweeklychallenge-club-b9f0eba10c5d82ad61f059331730a613653c7384.zip
Merge pull request #1909 from Scimon/master
Bit brute force but it works
-rw-r--r--challenge-068/simon-proctor/raku/ch-1.raku37
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-068/simon-proctor/raku/ch-1.raku b/challenge-068/simon-proctor/raku/ch-1.raku
new file mode 100644
index 0000000000..1287b3a325
--- /dev/null
+++ b/challenge-068/simon-proctor/raku/ch-1.raku
@@ -0,0 +1,37 @@
+#!/usr/bin/env raku
+
+#| Given a matrix of 0's and 1's make any row or column with a 0 in all 0's
+sub MAIN (
+ UInt :h(:$height)!, #= Height of matrix
+ UInt :w(:$width)!, #= Width of matrix
+ *@values where {
+ ( @values.elems == $height * $width ) &&
+ ( so all(@values.map( 0|1 == * ) ) )
+ }, #= Matrix of 0's and 1's
+) {
+ my @matrix = @values.rotor($width);
+ say "Before:";
+ format-matrix( @matrix ).say;
+ say "After:";
+ format-matrix( process-matrix( $height, $width, @matrix ) ).say;
+ # @matrix.rotor($width).map( *.join(" ") ).join("\n").say;
+}
+
+sub format-matrix( @matrix ) {
+ @matrix.map( *.join(" ") ).join("\n");
+}
+
+sub process-matrix( $height, $width, @matrix ) {
+ my @output = [1 xx $width] xx $height;
+ for ^$height -> $y {
+ for ^$width -> $x {
+ if (@matrix[$y][$x] == 0) {
+ @output[$y] = [0 xx $width];
+ for ^$height -> $yo {
+ @output[$yo][$x] = 0;
+ }
+ }
+ }
+ }
+ return @output;
+}