aboutsummaryrefslogtreecommitdiff
path: root/challenge-067
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-07-04 14:46:40 +0100
committerGitHub <noreply@github.com>2020-07-04 14:46:40 +0100
commitbd756d4c4f5d3b19ddfa7699887fdcc1133103e9 (patch)
treec2768a066bc4e88efacdd10713206d1aed8c95e9 /challenge-067
parentbf3c787d83e8be64c6824de9233615ce46d65e09 (diff)
parent5b0ab77ba42c73a4cfbd0390f6f58cac55d428a2 (diff)
downloadperlweeklychallenge-club-bd756d4c4f5d3b19ddfa7699887fdcc1133103e9.tar.gz
perlweeklychallenge-club-bd756d4c4f5d3b19ddfa7699887fdcc1133103e9.tar.bz2
perlweeklychallenge-club-bd756d4c4f5d3b19ddfa7699887fdcc1133103e9.zip
Merge pull request #1901 from noudald/challenge-067-noud
Solution to challenge 067 task 1 and 2 in Raku by Noud
Diffstat (limited to 'challenge-067')
-rw-r--r--challenge-067/noud/raku/ch-1.p619
-rw-r--r--challenge-067/noud/raku/ch-2.p628
2 files changed, 47 insertions, 0 deletions
diff --git a/challenge-067/noud/raku/ch-1.p6 b/challenge-067/noud/raku/ch-1.p6
new file mode 100644
index 0000000000..a13d89a85d
--- /dev/null
+++ b/challenge-067/noud/raku/ch-1.p6
@@ -0,0 +1,19 @@
+# You are given two integers $m and $n. Write a script print all possible
+# combinations of $n numbers from the list 1 2 3 … $m.
+#
+# Every combination should be sorted i.e. [2,3] is valid combination but [3,2]
+# is not.
+#
+# Example:
+#
+# Input: $m = 5, $n = 2
+#
+# Output: [ [1,2], [1,3], [1,4], [1,5], [2,3], [2,4], [2,5], [3,4], [3,5],
+# [4,5] ]
+
+sub number-combinations($m, $n) {
+ return (1..$m).combinations($n);
+}
+
+number-combinations(5, 2).say;
+
diff --git a/challenge-067/noud/raku/ch-2.p6 b/challenge-067/noud/raku/ch-2.p6
new file mode 100644
index 0000000000..3e9d19c72c
--- /dev/null
+++ b/challenge-067/noud/raku/ch-2.p6
@@ -0,0 +1,28 @@
+# You are given a digit string $S. Write a script to print all possible letter
+# combinations that the given digit string could represent.
+#
+# Example:
+#
+# Input: $S = '35'
+#
+# Output: ["dj", "dk", "dl", "ej", "ek", "el", "fj", "fk", "fl"].
+
+my %phone =
+ 1 => <_ , @>,
+ 2 => <a b c>,
+ 3 => <d e f>,
+ 4 => <g h i>,
+ 5 => <j k l>,
+ 6 => <m n o>,
+ 7 => <p q r s>,
+ 8 => <t u v>,
+ 9 => <w x y z>;
+
+sub phone-to-string($S) {
+ return [X~] gather { take %phone{$_} for $S.comb; };
+}
+
+.say for phone-to-string('35');
+
+
+