diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2023-06-12 03:36:09 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-12 03:36:09 +0100 |
| commit | 1348d5199c62e99a2fa04e5b7fcd0ca9d3bffdb0 (patch) | |
| tree | 031c0b28c9725e04581e0300ea9021736b5dfae6 | |
| parent | 085301515265a7d30205a3ce7ac773132b46b398 (diff) | |
| parent | 7798f536121ed5bcba1fd8c9e0b145b3a605e04a (diff) | |
| download | perlweeklychallenge-club-1348d5199c62e99a2fa04e5b7fcd0ca9d3bffdb0.tar.gz perlweeklychallenge-club-1348d5199c62e99a2fa04e5b7fcd0ca9d3bffdb0.tar.bz2 perlweeklychallenge-club-1348d5199c62e99a2fa04e5b7fcd0ca9d3bffdb0.zip | |
Merge pull request #8189 from andemark/challenge-220-Raku
Challenge 220 Solutions (Raku)
| -rw-r--r-- | challenge-220/mark-anderson/raku/ch-1.raku | 10 | ||||
| -rw-r--r-- | challenge-220/mark-anderson/raku/ch-2.raku | 23 |
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-220/mark-anderson/raku/ch-1.raku b/challenge-220/mark-anderson/raku/ch-1.raku new file mode 100644 index 0000000000..9f4ce69b18 --- /dev/null +++ b/challenge-220/mark-anderson/raku/ch-1.raku @@ -0,0 +1,10 @@ +#!/usr/bin/env raku +use Test; + +is-deeply common-characters(<Perl Rust Raku>), ("r",); +is-deeply common-characters(<love live leave>), <e l v>; + +sub common-characters +{ + sort .keys given [(&)] @^a>>.lc>>.comb +} diff --git a/challenge-220/mark-anderson/raku/ch-2.raku b/challenge-220/mark-anderson/raku/ch-2.raku new file mode 100644 index 0000000000..99b1091536 --- /dev/null +++ b/challenge-220/mark-anderson/raku/ch-2.raku @@ -0,0 +1,23 @@ +#!/usr/bin/env raku +use Test; + +is-deeply squareful(1, 17, 8), ((1, 8, 17), (17, 8, 1)); +is-deeply squareful(2, 2, 2), ((2, 2, 2),); + +sub squareful(+@a) +{ + @a.permutations.unique(with => &[eqv]) + .grep({ all(.rotor(2 => -1)).sum.sqrt.narrow ~~ UInt }) +} + +=begin alternate +sub squareful(+@a) +{ + my $s = @a.sort.tail(2).sum; + + my $squares := (0..$s Z* 0..$s).List; + + @a.permutations.unique(with => &[eqv]) + .grep({ .rotor(2 => -1)>>.sum (<=) $squares }) +} +=end alternate |
