aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-089/feng-chang/raku/ch-1.raku27
-rwxr-xr-xchallenge-089/feng-chang/raku/ch-1b.raku31
-rwxr-xr-xchallenge-089/feng-chang/raku/ch-2.raku32
3 files changed, 90 insertions, 0 deletions
diff --git a/challenge-089/feng-chang/raku/ch-1.raku b/challenge-089/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..4bfaf7bc8c
--- /dev/null
+++ b/challenge-089/feng-chang/raku/ch-1.raku
@@ -0,0 +1,27 @@
+#!/bin/env raku
+
+=begin Challenge
+
+You are given a positive integer $N.
+
+Write a script to sum GCD of all possible unique pairs between 1 and $N.
+
+Example 1:
+
+Input: 3
+Output: 3
+
+gcd(1,2) + gcd(1,3) + gcd(2,3)
+
+Example 2:
+
+Input: 4
+Output: 7
+
+gcd(1,2) + gcd(1,3) + gcd(1,4) + gcd(2,3) + gcd(2,4) + gcd(3,4)
+
+=end Challenge
+
+sub MAIN(UInt:D $N) {
+ (1..$N-1 X 2..$N).grep({.[1] > .[0]}).map({.[0] gcd .[1]}).sum.put;
+}
diff --git a/challenge-089/feng-chang/raku/ch-1b.raku b/challenge-089/feng-chang/raku/ch-1b.raku
new file mode 100755
index 0000000000..833a76c8bb
--- /dev/null
+++ b/challenge-089/feng-chang/raku/ch-1b.raku
@@ -0,0 +1,31 @@
+#!/bin/env raku
+
+=begin Challenge
+
+You are given a positive integer $N.
+
+Write a script to sum GCD of all possible unique pairs between 1 and $N.
+
+Example 1:
+
+Input: 3
+Output: 3
+
+gcd(1,2) + gcd(1,3) + gcd(2,3)
+
+Example 2:
+
+Input: 4
+Output: 7
+
+gcd(1,2) + gcd(1,3) + gcd(1,4) + gcd(2,3) + gcd(2,4) + gcd(3,4)
+
+=end Challenge
+
+sub MAIN(UInt:D $N) {
+ (1..$N-1) X (2..$N) ==>
+ grep { .[1] > .[0] } ==>
+ map { .[0] gcd .[1] } ==>
+ sum() ==>
+ put();
+}
diff --git a/challenge-089/feng-chang/raku/ch-2.raku b/challenge-089/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..6fe22b02a8
--- /dev/null
+++ b/challenge-089/feng-chang/raku/ch-2.raku
@@ -0,0 +1,32 @@
+#!/bin/env raku
+
+=begin Challenge
+
+Write a script to display matrix as below with numbers 1 - 9. Please make sure numbers are used once.
+
+[ a b c ]
+[ d e f ]
+[ g h i ]
+
+So that it satisfies the following:
+
+a + b + c = 15
+d + e + f = 15
+g + h + i = 15
+a + d + g = 15
+b + e + h = 15
+c + f + i = 15
+a + e + i = 15
+c + e + g = 15
+
+=end Challenge
+
+(1..9).permutations
+ .grep({ all(
+ .[0]+.[1]+.[2], .[3]+.[4]+.[5], .[6]+.[7]+.[8],
+ .[0]+.[3]+.[6], .[1]+.[4]+.[7], .[2]+.[5]+.[8],
+ .[0]+.[4]+.[8], .[2]+.[4]+.[6]
+ ) == 15 })
+ .map({ "{.[0]} {.[1]} {.[2]}\n{.[3]} {.[4]} {.[5]}\n{.[6]} {.[7]} {.[8]}" })
+ .join("\n\n")
+ .put;