aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-08-31 16:49:20 +0100
committerGitHub <noreply@github.com>2021-08-31 16:49:20 +0100
commitdbb8e4faaf0d161f7b5afe122124fcec3401ca38 (patch)
treefe61b68d5704c7d5214282d516316b746126b1c6
parent0db17584adf904ac1b9b40735a32230b28946f0b (diff)
parenta9e447d933fc8253b3445662f6a291b514772dab (diff)
downloadperlweeklychallenge-club-dbb8e4faaf0d161f7b5afe122124fcec3401ca38.tar.gz
perlweeklychallenge-club-dbb8e4faaf0d161f7b5afe122124fcec3401ca38.tar.bz2
perlweeklychallenge-club-dbb8e4faaf0d161f7b5afe122124fcec3401ca38.zip
Merge pull request #4826 from andemark/branch-for-challenge-128
ch-2.raku
-rw-r--r--challenge-128/mark-anderson/raku/ch-1.raku52
-rw-r--r--challenge-128/mark-anderson/raku/ch-2.raku34
2 files changed, 58 insertions, 28 deletions
diff --git a/challenge-128/mark-anderson/raku/ch-1.raku b/challenge-128/mark-anderson/raku/ch-1.raku
index 7e33cfec7d..ffb423f775 100644
--- a/challenge-128/mark-anderson/raku/ch-1.raku
+++ b/challenge-128/mark-anderson/raku/ch-1.raku
@@ -1,32 +1,28 @@
#!/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>);
+use Test;
+plan 3;
+
+is-deeply max-sub-matrix(<1 0 0 0 1 0>,
+ <1 1 0 0 0 1>,
+ <1 0 0 0 0 0>), ['2 x 3', '3 x 2'];
+
+is-deeply max-sub-matrix(<0 0 1 1>,
+ <0 0 0 1>,
+ <0 0 1 0>), ['3 x 2'];
+
+is-deeply 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>), ['4 x 3', '6 x 2'];
sub max-sub-matrix(+$matrix)
{
@@ -52,5 +48,5 @@ sub max-sub-matrix(+$matrix)
}
}
- %results.maxpairs;
+ %results.maxpairs>>.key.sort.Array;
}
diff --git a/challenge-128/mark-anderson/raku/ch-2.raku b/challenge-128/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..0b54764864
--- /dev/null
+++ b/challenge-128/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,34 @@
+#!/usr/bin/env raku
+
+use Test;
+plan 2;
+
+is minimum-platforms(<11:20 14:30>, <11:50 15:00>), 1, 'Example 1';
+
+is minimum-platforms(<10:20 11:00 11:10 12:20 16:20 19:00>,
+ <10:30 13:20 12:40 12:50 20:20 21:20>), 3, 'Example 2';
+
+sub minimum-platforms($arrivals, $departures)
+{
+ my $result;
+ my $platforms;
+ my @arrivals = $arrivals.sort;
+ my @departures = $departures.sort;
+
+ while @arrivals
+ {
+ if @arrivals.head lt @departures.head
+ {
+ @arrivals.shift;
+ $result = max $result, ++$platforms;
+ }
+
+ else
+ {
+ @departures.shift;
+ $platforms--;
+ }
+ }
+
+ $result;
+}