aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-06-21 21:29:47 +0100
committerGitHub <noreply@github.com>2022-06-21 21:29:47 +0100
commitcc018256f654afb54f1aa81e955e491c16d7754e (patch)
tree357d57718221dfca18a04bcfc3d72b3168c7cc0b
parentece1939d957b8b5234cdf7969fd56248616757b0 (diff)
parent7c60319059cf9426677f2525317cb6ca77b052e4 (diff)
downloadperlweeklychallenge-club-cc018256f654afb54f1aa81e955e491c16d7754e.tar.gz
perlweeklychallenge-club-cc018256f654afb54f1aa81e955e491c16d7754e.tar.bz2
perlweeklychallenge-club-cc018256f654afb54f1aa81e955e491c16d7754e.zip
Merge pull request #6307 from 2colours/branch-for-challenge-170
Weekly solutions by 2colours
-rwxr-xr-xchallenge-170/2colours/raku/ch-1.raku11
-rwxr-xr-xchallenge-170/2colours/raku/ch-2.raku43
2 files changed, 54 insertions, 0 deletions
diff --git a/challenge-170/2colours/raku/ch-1.raku b/challenge-170/2colours/raku/ch-1.raku
new file mode 100755
index 0000000000..ec64423905
--- /dev/null
+++ b/challenge-170/2colours/raku/ch-1.raku
@@ -0,0 +1,11 @@
+#!/usr/bin/env raku
+
+(1 .. *)
+ .grep: &is-prime andthen
+ [\*] $_ andthen
+ .head: 10 andthen
+ .pairs
+ .map: { "P({.key + 1}) = {.value}" } andthen
+ .join: "\n" andthen
+ .say;
+
diff --git a/challenge-170/2colours/raku/ch-2.raku b/challenge-170/2colours/raku/ch-2.raku
new file mode 100755
index 0000000000..322415c159
--- /dev/null
+++ b/challenge-170/2colours/raku/ch-2.raku
@@ -0,0 +1,43 @@
+#!/usr/bin/env raku
+
+sub prompt-matrix($name) {
+ my $starting-prompt = "$name = ";
+ my $indent-prompt = ' ' x $starting-prompt.chars;
+ my @prompts = lazy flat $starting-prompt, $indent-prompt xx *;
+ gather for @prompts -> $prompt {
+ given prompt($prompt).comb(/ '-'? \d+ /)>>.Int {
+ last if .elems == 0;
+ .take;
+ }
+ } andthen .List;
+}
+
+sub infix:«~>»(@a, @b) {
+ |@a, |@b
+}
+
+sub infix:<⊗>($a, $b) {
+ my @by-matrix = @$a XX<<*<< $b;
+ [~>] @by-matrix.map({ [Z~>] $_ })
+}
+
+sub infix:«<_»($output, $size) {
+ sprintf('%*s', $size, $output)
+}
+
+sub show-matrix($caption, $lines) {
+ my $starting-prefix = "$caption = ";
+ my $indent = ' ' x $starting-prefix.chars;
+ my @prefixes = lazy flat $starting-prefix, $indent xx *;
+ my @cols = [Zmax] $lines>>.chars;
+ dd @cols;
+ $lines >><_>> (@cols,) andthen
+ .map: { "[ {.join: ' '} ]" } andthen
+ @prefixes <<~<< $_ andthen
+ .join: "\n" andthen
+ .say;
+}
+
+my $a = prompt-matrix('A');
+my $b = prompt-matrix('B');
+show-matrix 'A ⊗ B', $a ⊗ $b; \ No newline at end of file