aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-082/gugod/raku/ch-1.raku10
-rw-r--r--challenge-082/gugod/raku/ch-2.raku32
2 files changed, 42 insertions, 0 deletions
diff --git a/challenge-082/gugod/raku/ch-1.raku b/challenge-082/gugod/raku/ch-1.raku
new file mode 100644
index 0000000000..f2d918b47b
--- /dev/null
+++ b/challenge-082/gugod/raku/ch-1.raku
@@ -0,0 +1,10 @@
+#!/usr/bin/env raku
+
+sub MAIN (Int $M, Int $N) {
+ my ($a, $b) = ($M, $N).sort;
+ say common-factors($a, $b);
+}
+
+sub common-factors (Int $a, Int $b) {
+ (1, 2..$a/2, $a).flat.grep(-> $n { 0 == $a % $n == $b % $n });
+}
diff --git a/challenge-082/gugod/raku/ch-2.raku b/challenge-082/gugod/raku/ch-2.raku
new file mode 100644
index 0000000000..047c4e0c4d
--- /dev/null
+++ b/challenge-082/gugod/raku/ch-2.raku
@@ -0,0 +1,32 @@
+#!/usr/bin/env raku
+
+sub MAIN (Str $A, Str $B, Str $C) {
+ say interleaves($A, $B, $C) ?? 1 !! 0;
+}
+
+sub interleaves (Str $A, Str $B, Str $C) {
+ my @stash;
+ @stash.push([-1, -1]);
+
+ my $i = 0;
+ while $i < $C.chars && @stash.elems > 0 {
+ my $c = $C.substr($i++, 1);
+ my @stash2 = gather {
+ while @stash.elems > 0 {
+ my $it = @stash.pop();
+ my $a = $A.substr($it[0]+1, 1);
+ my $b = $B.substr($it[1]+1, 1);
+ if $c eq $a {
+ take [$it[0]+1, $it[1]];
+ }
+ if $c eq $b {
+ take [$it[0], $it[1]+1];
+ }
+ }
+ };
+
+ @stash = @stash2.unique(:with(&[eqv]));
+ }
+
+ return $i == $C.chars && @stash.elems > 0 && @stash[0][0].succ == $A.chars && @stash[0][1].succ == $B.chars;
+}