diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-08-30 23:51:52 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-30 23:51:52 +0100 |
| commit | f7668df0586c800e3cb9fe47b311b4d76f5f4c48 (patch) | |
| tree | 643480ff84de594ab55d40aade163492b4ac9869 | |
| parent | 5c85fdaafb2786eaa6154e0a5d9269f82ee5fe35 (diff) | |
| parent | 5d0d8804def60294f33cd5c023c822577161ed9b (diff) | |
| download | perlweeklychallenge-club-f7668df0586c800e3cb9fe47b311b4d76f5f4c48.tar.gz perlweeklychallenge-club-f7668df0586c800e3cb9fe47b311b4d76f5f4c48.tar.bz2 perlweeklychallenge-club-f7668df0586c800e3cb9fe47b311b4d76f5f4c48.zip | |
Merge pull request #4821 from andemark/branch-for-challenge-128
initial ch-1.raku
| -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; +} |
