aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-220/simon-proctor/raku/ch-1.raku3
-rw-r--r--challenge-220/simon-proctor/raku/ch-2.raku30
2 files changed, 32 insertions, 1 deletions
diff --git a/challenge-220/simon-proctor/raku/ch-1.raku b/challenge-220/simon-proctor/raku/ch-1.raku
index c6043d4548..5f67297575 100644
--- a/challenge-220/simon-proctor/raku/ch-1.raku
+++ b/challenge-220/simon-proctor/raku/ch-1.raku
@@ -5,10 +5,11 @@ multi sub MAIN( *@words ) {
found-letters(@words).join(' ').say;
}
-multi sub MAIN('TEST') {
+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 ) {
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;
+}