aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Hood <hood@panix.com>2020-12-01 02:21:57 -0500
committerPhilip Hood <hood@panix.com>2020-12-01 02:21:57 -0500
commitd28f919766e5e70e4b420d64d3a803e8645e6007 (patch)
treed68cfde23c98a14292722c96e1878c74c004a500
parentd3f8a4ffd028c6c532ee4e97a434bcb351364120 (diff)
downloadperlweeklychallenge-club-d28f919766e5e70e4b420d64d3a803e8645e6007.tar.gz
perlweeklychallenge-club-d28f919766e5e70e4b420d64d3a803e8645e6007.tar.bz2
perlweeklychallenge-club-d28f919766e5e70e4b420d64d3a803e8645e6007.zip
challenge #89, nums #1 & 2.
-rwxr-xr-xchallenge-089/pkmnx/raku/ch-1.raku13
-rwxr-xr-xchallenge-089/pkmnx/raku/ch-2.raku29
2 files changed, 42 insertions, 0 deletions
diff --git a/challenge-089/pkmnx/raku/ch-1.raku b/challenge-089/pkmnx/raku/ch-1.raku
new file mode 100755
index 0000000000..2880fe34a7
--- /dev/null
+++ b/challenge-089/pkmnx/raku/ch-1.raku
@@ -0,0 +1,13 @@
+#!/usr/bin/env raku
+
+sub MAIN( Int $N where $N > 1 ) {
+
+ my $v = 0;
+ my $str = (1..$N).combinations(2).map(->($a,$b){ $v += $a gcd $b; "gcd($a,$b)"}).join(" + ");
+
+ "Input: $N".say;
+ "Output: $v\n".say;
+
+ $str.say;
+
+}
diff --git a/challenge-089/pkmnx/raku/ch-2.raku b/challenge-089/pkmnx/raku/ch-2.raku
new file mode 100755
index 0000000000..c20006f1c9
--- /dev/null
+++ b/challenge-089/pkmnx/raku/ch-2.raku
@@ -0,0 +1,29 @@
+#!/usr/bin/env raku
+
+sub MAIN() {
+
+ my $t = 15;
+ my @all = (1,2,3,4,5,6,7,8,9);
+ my @workers;
+
+ for @all -> $a {
+ push @workers, start {
+ for ( @all (^) ($a) ).keys.grep({ ($a + $_) < $t }) -> $b {
+ for ( @all (^) ($a,$b) ).keys -> $c {
+ next if ($a + $b + $c) != $t;
+
+ for ( @all (^) ($a,$b,$c) ).keys.permutations -> ($d,$e,$f,$g,$h,$i) {
+ if ( $t ==($d +$e +$f) ==($g +$h +$i) ==($a +$d +$g) ==($b +$e +$h) ==($c +$f +$i) ==($a +$e +$i) ==($c +$e +$g) ) {
+ ( ($a,$b,$c), ($d,$e,$f), ($g,$h,$i) ).join("\n").say;
+ print "\n";
+ }
+ }
+
+ }
+ }
+ }
+ }
+
+ await(@workers);
+
+}