aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-109/pjdurai/raku/ch-1.raku25
-rw-r--r--challenge-109/pjdurai/raku/ch-2.raku34
2 files changed, 59 insertions, 0 deletions
diff --git a/challenge-109/pjdurai/raku/ch-1.raku b/challenge-109/pjdurai/raku/ch-1.raku
new file mode 100755
index 0000000000..f66ba47b0b
--- /dev/null
+++ b/challenge-109/pjdurai/raku/ch-1.raku
@@ -0,0 +1,25 @@
+#! /usr/bin/env raku
+
+# Returns a list of divisors except 1 and Self.
+
+sub get-divisors ($num){
+ reduce sub (@acc,$i){
+ if $num %% $i && $i != 1 && $i != $num {
+ @acc.push($i) ;
+ my $m = $num / $i;
+ @acc.push($m) if $m != $i;
+ }
+ @acc;
+ }, [], | (1..$num.sqrt.floor);
+}
+
+# Print 20 Chowla Numbers.
+# To input the count do
+
+# 'raku ch-1.raku --N=25'
+
+sub MAIN(
+ Int :$N = 20,
+) {
+ say ([1..$N].map( {[+] get-divisors($_)} )).join(",");
+}
diff --git a/challenge-109/pjdurai/raku/ch-2.raku b/challenge-109/pjdurai/raku/ch-2.raku
new file mode 100644
index 0000000000..65b4e2e906
--- /dev/null
+++ b/challenge-109/pjdurai/raku/ch-2.raku
@@ -0,0 +1,34 @@
+#! /usr/bin/env raku
+
+# Call as 'raku ch-2.raku --numbers="1,2,3,4,5,6,7"'
+# Defaults to "1,2,3,4,5,6,7"
+#
+# The problme has multiple solutions. It prints all solutions.
+
+sub MAIN(
+ Str :$numbers = "1,2,3,4,5,6,7"
+){
+ my @labels = ["a".."z"];
+ my @arr = $numbers.split(/\,/);
+
+ my @solutions = @arr.permutations.grep(
+ ->@l
+ {
+ @l[0] + @l[1] == @l[1] + @l[2] + @l[3] == @l[3] + @l[4] + @l[5] == @l[5] + @l[6];
+
+ });
+
+ for @solutions -> @solution {
+ say "Solution: ", @solution;
+ for zip(@labels, @solution) -> @pair {
+ say "@pair[0] = @pair[1]";
+ }
+ say "";
+ say "Box 1: a + b = @solution[0] + @solution[1] = ", @solution[0] + @solution[1];
+ say "Box 2: b + c + d = @solution[1] + @solution[2] + @solution[3] = ", @solution[1] + @solution[2] + @solution[3];
+ say "Box 3: d + e + f = @solution[3] + @solution[4] + @solution[5] = ", @solution[3] + @solution[4] + @solution[5];
+ say "Box 4: a + b = @solution[5] + @solution[6] = ", @solution[5] + @solution[6];
+ say "---------\n";
+
+ }
+}