aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;
+}