From 12955fd0811be31d2de6d1194d3c9ba5dd276e5d Mon Sep 17 00:00:00 2001 From: Simon Proctor Date: Mon, 6 Jul 2020 10:15:32 +0100 Subject: Bit brute force but it works --- challenge-068/simon-proctor/raku/ch-1.raku | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 challenge-068/simon-proctor/raku/ch-1.raku 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; +} -- cgit