aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Hood <hood@panix.com>2021-04-21 13:42:13 -0400
committerPhilip Hood <hood@panix.com>2021-04-21 13:42:13 -0400
commit16814906f220961e56b95cf544b20bf1ac16e890 (patch)
treed557ca4a52099108943309c813197ec44beb9f39
parent39c3ac8c65f6fa3d0a86e5af47727eec086e162a (diff)
downloadperlweeklychallenge-club-16814906f220961e56b95cf544b20bf1ac16e890.tar.gz
perlweeklychallenge-club-16814906f220961e56b95cf544b20bf1ac16e890.tar.bz2
perlweeklychallenge-club-16814906f220961e56b95cf544b20bf1ac16e890.zip
challenge 109, in raku
-rwxr-xr-xchallenge-109/pkmnx/raku/ch-1.raku6
-rwxr-xr-xchallenge-109/pkmnx/raku/ch-2.raku27
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-109/pkmnx/raku/ch-1.raku b/challenge-109/pkmnx/raku/ch-1.raku
new file mode 100755
index 0000000000..4d31c01eed
--- /dev/null
+++ b/challenge-109/pkmnx/raku/ch-1.raku
@@ -0,0 +1,6 @@
+#!/usr/bin/env raku
+
+
+my $upr = 20;
+my @chwla = (1 .. $upr).map(-> $n { (2..$n -1).grep({ !($n % $_) }).sum() });
+@chwla.say;
diff --git a/challenge-109/pkmnx/raku/ch-2.raku b/challenge-109/pkmnx/raku/ch-2.raku
new file mode 100755
index 0000000000..f71cf17e84
--- /dev/null
+++ b/challenge-109/pkmnx/raku/ch-2.raku
@@ -0,0 +1,27 @@
+#!/usr/bin/env raku
+
+# See usage:
+# pk@pkx:~/stuff/.../challenge-109/pkmnx/raku$ time ./ch-2.raku 1 2 3 5 4 6 7
+# 3 + 7 == 7 + 2 + 1 == 1 + 5 + 4 == 4 + 6
+# 5 + 6 == 6 + 2 + 3 == 3 + 1 + 7 == 7 + 4
+# 4 + 5 == 5 + 3 + 1 == 1 + 6 + 2 == 2 + 7
+# 4 + 7 == 7 + 1 + 3 == 3 + 2 + 6 == 6 + 5
+# 6 + 4 == 4 + 1 + 5 == 5 + 2 + 3 == 3 + 7
+# 6 + 4 == 4 + 5 + 1 == 1 + 2 + 7 == 7 + 3
+# 7 + 2 == 2 + 6 + 1 == 1 + 3 + 5 == 5 + 4
+# 7 + 3 == 3 + 2 + 5 == 5 + 1 + 4 == 4 + 6
+#
+# real 0m0.337s
+
+sub MAIN( *@N where @N.elems == 7 && @N.all ~~ Numeric ) {
+
+ @N.permutations.grep({ val(|$_) }).map({ disp(|$_) }).join("\n").say;
+
+}
+
+sub val ( $a, $b, $c, $d, $e, $f, $g ) {
+ $a + $b == $b + $c + $d == $d + $e + $f == $f + $g;
+}
+sub disp ( $a, $b, $c, $d, $e, $f, $g ) {
+ "$a + $b == $b + $c + $d == $d + $e + $f == $f + $g";
+}