aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-109/simon-proctor/raku/ch-1.raku10
-rw-r--r--challenge-109/simon-proctor/raku/ch-2.raku16
2 files changed, 26 insertions, 0 deletions
diff --git a/challenge-109/simon-proctor/raku/ch-1.raku b/challenge-109/simon-proctor/raku/ch-1.raku
new file mode 100644
index 0000000000..99d71ecc19
--- /dev/null
+++ b/challenge-109/simon-proctor/raku/ch-1.raku
@@ -0,0 +1,10 @@
+#!/usr/bin/env raku
+
+#| Give the Chowla number up to X (default 20)
+sub MAIN ( Int \X = 20 ) {
+ (1..X).map( { chowla($_) } ).join(",").say;
+}
+
+sub chowla($x) {
+ [+] (2..^$x).grep( $x %% * );
+}
diff --git a/challenge-109/simon-proctor/raku/ch-2.raku b/challenge-109/simon-proctor/raku/ch-2.raku
new file mode 100644
index 0000000000..1420f24e6d
--- /dev/null
+++ b/challenge-109/simon-proctor/raku/ch-2.raku
@@ -0,0 +1,16 @@
+#!/usr/bin/env raku
+
+#| Given a list of numbers a through g find a result where a+b == b+c+d == d+e+f == f+g
+sub MAIN ( *@values where @values.elems == 7 && @values.all ~~ IntStr && [!==] @values.sort) {
+ my @res = @values.permutations.first( -> @v { [==] (@v[0]+@v[1] , @v[1]+@v[2]+@v[3], @v[3]+@v[4]+@v[5], @v[5]+@v[6]) } );
+
+ if ( ! defined @res[0] ) {
+ say "Can't find a solution";
+ } else {
+ say "{@res[0]} + {@res[1]} = {@res[0] + @res[1]}";
+ say "{@res[1]} + {@res[2]} + {@res[3]} = {@res[1] + @res[2] + @res[3]}";
+ say "{@res[3]} + {@res[4]} + {@res[5]} = {@res[3] + @res[4] + @res[5]}";
+ say "{@res[5]} + {@res[6]} = {@res[5] + @res[6]}";
+ }
+
+}