aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-06-22 08:17:52 +0100
committerGitHub <noreply@github.com>2022-06-22 08:17:52 +0100
commit36f0e93990612be7e47efde4fa9277b184593984 (patch)
tree48366e3cac34a6e1839796d61cc257dd83620856
parentc1f1338bbb7b8c80fff8e6ee8c4882e95eca10f0 (diff)
parent5d87533c2c140831ee0c86284a82a1f0b4137213 (diff)
downloadperlweeklychallenge-club-36f0e93990612be7e47efde4fa9277b184593984.tar.gz
perlweeklychallenge-club-36f0e93990612be7e47efde4fa9277b184593984.tar.bz2
perlweeklychallenge-club-36f0e93990612be7e47efde4fa9277b184593984.zip
Merge pull request #6314 from 0rir/170
170
-rw-r--r--challenge-170/0rir/raku/ch-1.raku20
-rw-r--r--challenge-170/0rir/raku/ch-2.raku74
2 files changed, 94 insertions, 0 deletions
diff --git a/challenge-170/0rir/raku/ch-1.raku b/challenge-170/0rir/raku/ch-1.raku
new file mode 100644
index 0000000000..c5dda4e9d8
--- /dev/null
+++ b/challenge-170/0rir/raku/ch-1.raku
@@ -0,0 +1,20 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # ∅ ≡ ∩ ≢
+use v6.d;
+
+=begin comment
+Task 1: Primorial Numbers Submitted by: Mohammad S Anwar
+
+Generate the first 10 Primorial Numbers or primal factorials.
+P(0) = 1 (1)
+P(1) = 2 (1x2)
+P(2) = 6 (1x2×3)
+P(3) = 30 (1x2×3×5)
+P(4) = 210 (1x2×3×5×7)
+
+=end comment
+
+my constant @prime = gather for 1, 2, 3, 5, 7 … ∞ { .is-prime and .&take};
+my constant @primordial = lazy gather for 0 … ∞ { take [×] @prime[0..^ $_]};
+
+.say for @primordial[0 ..^ 10];
diff --git a/challenge-170/0rir/raku/ch-2.raku b/challenge-170/0rir/raku/ch-2.raku
new file mode 100644
index 0000000000..346199b237
--- /dev/null
+++ b/challenge-170/0rir/raku/ch-2.raku
@@ -0,0 +1,74 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # ∅ ≡ ∩ ≢ ⊗
+use v6.d;
+use lib $?FILE.IO.parent(2).add("lib");
+use Test;
+
+=begin comment
+Task 2: Kronecker Product Submitted by: Mohammad S Anwar
+
+You are given 2 matrices.
+
+Write a script to implement Kronecker Product on the given 2 matrices.
+For more information, please refer wikipedia page.
+
+A = [ 1 2 ]
+ [ 3 4 ]
+
+B = [ 5 6 ]
+ [ 7 8 ]
+0
+A x B = [ 1x5 1x6 2x5 2x6 ]
+ [ 1x7 1x8 2x7 2x8 ]
+ [ 3x5 3x6 4x5 4x6 ]
+ [ 3x7 3x8 4x7 4x8 ]
+=end comment
+
+my constant TEST = False;
+
+if TEST {
+ my @Test =
+ { L => [], R => [], E => [],
+ },
+ { L => [[ 1, ], [ 2,]], R => [[ 3, ], [ 4,]],
+ E => [[ 3,], [ 4,], [ 6,], [ 8,]],
+ },
+ { L => [[ 1, 2 ], [ 3, 4 ]], R => [[ 5, 6 ], [ 7, 8 ]],
+ E => [[ 5,6,10,12 ], [ 7,8,14,16 ], [ 15,18,20,24 ], [ 21,24,28,32 ]],
+ },
+ { L => [[ 1, 2, 3, 0], [2,3,4,5]],
+ R => [[ 6,7,8 ], [0,10,11]],
+ E => [[ 6,7,8, 12,14,16, 18,21,24, 0,0,0],
+ [ 0,10,11, 0,20,22, 0,30,33, 0,0,0],
+ [ 12,14,16, 18,21,24, 24,28,32, 30,35,40],
+ [ 0,20,22, 0,30,33, 0,40,44, 0,50,55]],
+ },
+ ;
+
+ plan @Test.elems;
+
+ for @Test -> %t {
+ is-deeply kronecker( %t<L>, %t<R>), %t<E>;
+ }
+ done-testing;
+ exit;
+}
+
+my @L = [ 1, 2 ], [ 3, 4 ];
+my @R = [ 5, 6 ], [ 7, 8 ];
+
+sub kronecker( @l, @r ) {
+ my @ret;
+ for @l -> @mult {
+ for @r -> @plier {
+ @ret.push( [ @mult X* @plier ] );
+ }
+ }
+ @ret;
+}
+
+say kronecker( @L, @R);
+
+
+
+