diff options
| author | Mark <53903062+andemark@users.noreply.github.com> | 2023-06-05 12:52:21 +0000 |
|---|---|---|
| committer | Mark <53903062+andemark@users.noreply.github.com> | 2023-06-05 12:52:21 +0000 |
| commit | 00cf4b917c093cced6ec5e3a05a975fae65b9c76 (patch) | |
| tree | 88404280f416ca576296130e41c2a485523f6249 | |
| parent | 401be1861472af6d62bbdeb0fe65f6ced1ca8f31 (diff) | |
| download | perlweeklychallenge-club-00cf4b917c093cced6ec5e3a05a975fae65b9c76.tar.gz perlweeklychallenge-club-00cf4b917c093cced6ec5e3a05a975fae65b9c76.tar.bz2 perlweeklychallenge-club-00cf4b917c093cced6ec5e3a05a975fae65b9c76.zip | |
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 | 27 |
2 files changed, 37 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..c34c232700 --- /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>>.comb>>.lc +} 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..11ef39a5ef --- /dev/null +++ b/challenge-220/mark-anderson/raku/ch-2.raku @@ -0,0 +1,27 @@ +#!/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) +{ + gather for @a.permutations.unique(with => &[eqv]) + { + .take if 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; + + gather for @a.permutations.unique(with => &[eqv]) + { + .take if .rotor(2 => -1)>>.sum (<) $squares + } +} +=end alternate |
