aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-10-13 11:02:25 +0100
committerGitHub <noreply@github.com>2020-10-13 11:02:25 +0100
commitf64f228444d4d1fa90f3b397a256d93830ce0c9b (patch)
treeb5aad5f622165de6d2ac7da2e9f5a9dc03dec665
parent2ca4ce5d0552f534e9085716d12294d4268de695 (diff)
parent9655f76d11321542dd380753eae28f36febc5961 (diff)
downloadperlweeklychallenge-club-f64f228444d4d1fa90f3b397a256d93830ce0c9b.tar.gz
perlweeklychallenge-club-f64f228444d4d1fa90f3b397a256d93830ce0c9b.tar.bz2
perlweeklychallenge-club-f64f228444d4d1fa90f3b397a256d93830ce0c9b.zip
Merge pull request #2508 from Scimon/master
Morning
-rw-r--r--challenge-082/simon-proctor/raku/ch-1.raku12
-rw-r--r--challenge-082/simon-proctor/raku/ch-2.raku12
2 files changed, 24 insertions, 0 deletions
diff --git a/challenge-082/simon-proctor/raku/ch-1.raku b/challenge-082/simon-proctor/raku/ch-1.raku
new file mode 100644
index 0000000000..3215cb071a
--- /dev/null
+++ b/challenge-082/simon-proctor/raku/ch-1.raku
@@ -0,0 +1,12 @@
+#!/usr/bin/env raku
+
+use v6;
+
+#| Given two positive integers print the common factors (not including the values themselves).
+sub MAIN ( UInt $M, UInt $N ) {
+ say "({(fac($M) (&) fac($N)).keys.sort.join(', ')})"
+}
+
+sub fac( UInt $v ) {
+ (1..^$v).grep( $v %% * )
+}
diff --git a/challenge-082/simon-proctor/raku/ch-2.raku b/challenge-082/simon-proctor/raku/ch-2.raku
new file mode 100644
index 0000000000..916919eb9c
--- /dev/null
+++ b/challenge-082/simon-proctor/raku/ch-2.raku
@@ -0,0 +1,12 @@
+#!/usr/bin/env raku
+
+use v6;
+
+#| Given three strings return 1 if the third string ($C) can be made by interleaving $A and $B
+sub MAIN ( Str $A, Str $B, Str $C ) {
+ ( any( |possible-interleaves($A,$B), |possible-interleaves($B,$A) ) ~~ $C ).Int.say;
+}
+
+sub possible-interleaves( Str $out, Str $sub ) {
+ (0..$out.codes).map( { my $x = $out; $x.substr-rw($_,0) = $sub; $x } )
+}