diff options
| -rw-r--r-- | challenge-128/mark-anderson/raku/ch-1.raku | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/challenge-128/mark-anderson/raku/ch-1.raku b/challenge-128/mark-anderson/raku/ch-1.raku new file mode 100644 index 0000000000..7e33cfec7d --- /dev/null +++ b/challenge-128/mark-anderson/raku/ch-1.raku @@ -0,0 +1,56 @@ +#!/usr/bin/env raku + +say "Example 1"; +.say for max-sub-matrix(<1 0 0 0 1 0>, + <1 1 0 0 0 1>, + <1 0 0 0 0 0>); + +say " "; + +say "Example 2"; +.say for max-sub-matrix(<0 0 1 1>, + <0 0 0 1>, + <0 0 1 0>); + +say " "; + +say "Example 3"; +.say for max-sub-matrix(<1 0 1 0 1 0 1 0 1 0 0 1>, + <1 0 1 0 1 0 1 0 1 0 0 1>, + <1 0 0 0 1 0 0 0 1 1 0 0>, + <1 0 0 0 1 0 0 0 1 1 0 0>, + <1 0 0 0 1 0 1 0 1 0 1 1>, + <1 0 0 0 1 0 0 0 1 0 0 1>, + <1 0 1 0 1 0 1 0 1 0 0 1>, + <1 0 1 0 1 0 1 0 1 0 0 0>, + <1 0 1 0 1 0 1 0 1 0 0 1>, + <1 0 1 0 1 0 1 0 1 0 0 1>, + <1 0 1 0 1 0 1 0 1 0 0 0>, + <1 0 0 0 0 0 0 0 1 0 1 0>); + +sub max-sub-matrix(+$matrix) +{ + my %h; + my %results; + + for ^$matrix -> $i + { + for $matrix[$i].join ~~ m:g/00+/ + { + %h{$i}.push: .from .. .pos-1; + } + } + + for (^$matrix).combinations: 2 -> ($head, $tail) + { + for [X] %h{$head .. $tail} -> @rows + { + my $cols = +([(&)] @rows); + my $rows = $tail - $head + 1; + my $area = $rows * $cols; + %results{"$rows x $cols"} = $area; + } + } + + %results.maxpairs; +} |
