diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2023-06-12 03:34:32 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-12 03:34:32 +0100 |
| commit | 085301515265a7d30205a3ce7ac773132b46b398 (patch) | |
| tree | 93378897469331b45720299c50488715cebf7c9e | |
| parent | e70de2a6b310a14665880a47051971979756ddf3 (diff) | |
| parent | 6b3f6682a56f9f9f92bcb21d371dac59a2266778 (diff) | |
| download | perlweeklychallenge-club-085301515265a7d30205a3ce7ac773132b46b398.tar.gz perlweeklychallenge-club-085301515265a7d30205a3ce7ac773132b46b398.tar.bz2 perlweeklychallenge-club-085301515265a7d30205a3ce7ac773132b46b398.zip | |
Merge pull request #8188 from Scimon/master
Challenge 220
| -rw-r--r-- | challenge-220/simon-proctor/raku/ch-1.raku | 17 | ||||
| -rw-r--r-- | challenge-220/simon-proctor/raku/ch-2.raku | 30 |
2 files changed, 47 insertions, 0 deletions
diff --git a/challenge-220/simon-proctor/raku/ch-1.raku b/challenge-220/simon-proctor/raku/ch-1.raku new file mode 100644 index 0000000000..5f67297575 --- /dev/null +++ b/challenge-220/simon-proctor/raku/ch-1.raku @@ -0,0 +1,17 @@ +#!/usr/bin/env raku + +#| Given a list of words return a list of letters that appear in all of them +multi sub MAIN( *@words ) { + found-letters(@words).join(' ').say; +} + +multi sub MAIN('TEST') is hidden-from-USAGE { + use Test; + is found-letters( 'Perl', 'Rust', 'Raku' ), ('r'); + is found-letters( 'love', 'live', 'leave' ), ('e','l','v'); + done-testing; +} + +sub found-letters ( *@words ) { + ( [∩] @words.map( *.fc.comb ) ).keys.sort; +} diff --git a/challenge-220/simon-proctor/raku/ch-2.raku b/challenge-220/simon-proctor/raku/ch-2.raku new file mode 100644 index 0000000000..dec82ba7dc --- /dev/null +++ b/challenge-220/simon-proctor/raku/ch-2.raku @@ -0,0 +1,30 @@ +#!/usr/bin/env raku + +#|(Given a list of number print all permutations where each pair in the list +where the sum of the pair is a perfect square +) +multi sub MAIN( *@values where @values.all ~~ Int() ) { + all-perfect(@values).map(*.join(',')).join("\n").say; +} + +multi sub MAIN('TEST') is hidden-from-USAGE { + use Test; + ok perfect( 25 ); + ok ! perfect( 24 ); + ok perfect-list((1,8,17)); + is all-perfect((1,17,8)), ( (1,8,17), (17,8,1) ); + is all-perfect((2,2,2)), ( (2,2,2) ); + done-testing; +} + +sub all-perfect( @list ) { + @list.permutations.unique(:as(-> @a {@a.join(',')})).grep( -> @a { perfect-list(@a) } ); +} + +sub perfect-list( @list ) { + [&] @list.rotor(2 => -1).map(-> ($a,$b) {perfect( $a+$b )}); +} + +sub perfect( Int $v ) { + $v.sqrt.Int() ~~ $v.sqrt; +} |
