diff options
| author | Stephen Lynn <bizlsg@localhost.localdomain> | 2023-06-06 16:35:31 +0800 |
|---|---|---|
| committer | Stephen Lynn <bizlsg@localhost.localdomain> | 2023-06-06 16:35:31 +0800 |
| commit | a23e55532b71e04ec91b07038aa92164a99c65d1 (patch) | |
| tree | b174cd16c55cf73aaf99d481fe90bacb2ac98353 | |
| parent | 401be1861472af6d62bbdeb0fe65f6ced1ca8f31 (diff) | |
| download | perlweeklychallenge-club-a23e55532b71e04ec91b07038aa92164a99c65d1.tar.gz perlweeklychallenge-club-a23e55532b71e04ec91b07038aa92164a99c65d1.tar.bz2 perlweeklychallenge-club-a23e55532b71e04ec91b07038aa92164a99c65d1.zip | |
pwc 220
| -rw-r--r-- | challenge-220/steve-g-lynn/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-220/steve-g-lynn/raku/ch-1.p6 | 8 | ||||
| -rwxr-xr-x | challenge-220/steve-g-lynn/raku/ch-2.p6 | 17 |
3 files changed, 26 insertions, 0 deletions
diff --git a/challenge-220/steve-g-lynn/blog.txt b/challenge-220/steve-g-lynn/blog.txt new file mode 100644 index 0000000000..2ae85994be --- /dev/null +++ b/challenge-220/steve-g-lynn/blog.txt @@ -0,0 +1 @@ +https://thiujiac.blogspot.com/2023/06/pwc-220.html diff --git a/challenge-220/steve-g-lynn/raku/ch-1.p6 b/challenge-220/steve-g-lynn/raku/ch-1.p6 new file mode 100755 index 0000000000..1229f35306 --- /dev/null +++ b/challenge-220/steve-g-lynn/raku/ch-1.p6 @@ -0,0 +1,8 @@ +#!/usr/bin/perl6 + +sub common_characters( @words ) { + [(&)] @words.map( {$_.lc.comb.Set} ) +} + +say &common_characters(('Perl','Rust','Raku')); #Set(r) +say &common_characters(('love','live','leave')); #Set(e l v) diff --git a/challenge-220/steve-g-lynn/raku/ch-2.p6 b/challenge-220/steve-g-lynn/raku/ch-2.p6 new file mode 100755 index 0000000000..712e9eb8e8 --- /dev/null +++ b/challenge-220/steve-g-lynn/raku/ch-2.p6 @@ -0,0 +1,17 @@ +#!/usr/bin/perl6 + +multi sub is_perfect_square( Int $a, Int $b ) { + ($a+$b).sqrt %% 1; +} + +multi sub is_perfect_square( @ints ) { + ( [&&] (0 .. @ints-2).map( {&is_perfect_square( @ints[$_], @ints[$_+1] ) } ) ); +} + +sub squareful (@ints where @ints.elems==3) { + @ints.permutations.grep( {$_.&is_perfect_square} ) +} + +say &squareful((1,17,8)); #(1,8,17),(17,8,1) +say &squareful((2,2,2)); #((2 2 2) (2 2 2) (2 2 2) (2 2 2) (2 2 2) (2 2 2)) .permutations treats each element of @ints as unique, so all 6 permutations are returned. + |
