diff options
| author | Simon Proctor <simon.proctor@zoopla.co.uk> | 2020-07-06 10:15:32 +0100 |
|---|---|---|
| committer | Simon Proctor <simon.proctor@zoopla.co.uk> | 2020-07-06 10:15:32 +0100 |
| commit | 12955fd0811be31d2de6d1194d3c9ba5dd276e5d (patch) | |
| tree | b38a417ddd82d9dc72241e73bc3d8a75f74041e2 /challenge-068 | |
| parent | 5293ff2999ca96715e38bff3a90c0710e0ff66e3 (diff) | |
| download | perlweeklychallenge-club-12955fd0811be31d2de6d1194d3c9ba5dd276e5d.tar.gz perlweeklychallenge-club-12955fd0811be31d2de6d1194d3c9ba5dd276e5d.tar.bz2 perlweeklychallenge-club-12955fd0811be31d2de6d1194d3c9ba5dd276e5d.zip | |
Bit brute force but it works
Diffstat (limited to 'challenge-068')
| -rw-r--r-- | challenge-068/simon-proctor/raku/ch-1.raku | 37 |
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; +} |
