diff options
| author | Polgár Márton <polgar@astron.hu> | 2022-06-21 06:18:54 +0200 |
|---|---|---|
| committer | Polgár Márton <polgar@astron.hu> | 2022-06-21 06:18:54 +0200 |
| commit | 7c60319059cf9426677f2525317cb6ca77b052e4 (patch) | |
| tree | e0b1346196896e766bf6842603e2451f9a7f3a21 | |
| parent | bb6f23fd223e77e35e199fbca2cc224ad21f0f1c (diff) | |
| download | perlweeklychallenge-club-7c60319059cf9426677f2525317cb6ca77b052e4.tar.gz perlweeklychallenge-club-7c60319059cf9426677f2525317cb6ca77b052e4.tar.bz2 perlweeklychallenge-club-7c60319059cf9426677f2525317cb6ca77b052e4.zip | |
Weekly solutions by 2colours
| -rwxr-xr-x | challenge-170/2colours/raku/ch-1.raku | 11 | ||||
| -rwxr-xr-x | challenge-170/2colours/raku/ch-2.raku | 43 |
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 |
