aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Anderson <mark@frontrangerunner.com>2020-12-21 11:51:23 -0700
committerMark Anderson <mark@frontrangerunner.com>2020-12-21 11:51:23 -0700
commitcf41d190ebc5542ccc4ca5db5df6431f67dfc35b (patch)
tree6ece6259859f50b2e2ba3e0b5eec3be7aa4acf2a
parent122c18bebe8097db1b5059619bc61ed1ba006fc4 (diff)
downloadperlweeklychallenge-club-cf41d190ebc5542ccc4ca5db5df6431f67dfc35b.tar.gz
perlweeklychallenge-club-cf41d190ebc5542ccc4ca5db5df6431f67dfc35b.tar.bz2
perlweeklychallenge-club-cf41d190ebc5542ccc4ca5db5df6431f67dfc35b.zip
initial
-rw-r--r--challenge-092/mark-anderson/raku/ch-1.raku35
-rw-r--r--challenge-092/mark-anderson/raku/ch-2.raku30
2 files changed, 65 insertions, 0 deletions
diff --git a/challenge-092/mark-anderson/raku/ch-1.raku b/challenge-092/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..07233f6b3d
--- /dev/null
+++ b/challenge-092/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,35 @@
+#!/usr/bin/env raku
+
+# Note: this program runs fine on rakudo 2020.05 but fails on 2020.01
+
+multi MAIN($A, $B) {
+ say is-isomorphic($A, $B);
+}
+
+multi MAIN {
+ use Test;
+ plan 3;
+
+ ok is-isomorphic("abc", "xyz"), "Example 1";
+ ok is-isomorphic("abb", "xyy"), "Example 2";
+ nok is-isomorphic("sum", "add"), "Example 3";
+}
+
+sub is-isomorphic($A, $B) {
+ my $h = Hash.new;
+ my $s = SetHash.new;
+
+ for $A.comb Z $B.comb -> ($a, $b) {
+ if $h{$a} {
+ return 0 unless $h{$a} eq $b;
+ }
+
+ else {
+ return 0 if $s{$b};
+ $h{$a} = $b;
+ $s.set($b);
+ }
+ }
+
+ return 1;
+}
diff --git a/challenge-092/mark-anderson/raku/ch-2.raku b/challenge-092/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..2fb0d146b7
--- /dev/null
+++ b/challenge-092/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,30 @@
+#!/usr/bin/env raku
+
+use Test;
+plan 3;
+
+is-deeply insert-interval(
+ (2,6), [(1,4), (8,10)]), [(1,6), (8,10)], "Example 1";
+is-deeply insert-interval(
+ (5,8), [(1,2), (3,7), (8,10)]), [(1,2), (3,10)], "Example 2";
+is-deeply insert-interval(
+ (10,11), [(1,5), (7,9)]), [(1,5), (7,9), (10,11)], "Example 3";
+
+sub insert-interval($N, @S) {
+ @S = sort @S.push: $N;
+
+ my @result;
+
+ while @S > 1 {
+ if @S[0;1] < @S[1;0] {
+ @result.push: @S.shift;
+ }
+
+ else {
+ @S[1] = (@S[0;0], @S[1;0]).min, (@S[0;1], @S[1;1]).max;
+ @S.shift;
+ }
+ }
+
+ @result.push: |@S;
+}