From 5b0ab77ba42c73a4cfbd0390f6f58cac55d428a2 Mon Sep 17 00:00:00 2001 From: Noud Aldenhoven Date: Sat, 4 Jul 2020 15:22:06 +0200 Subject: Solution to challenge 067 task 1 and 2 in Raku by Noud --- challenge-067/noud/raku/ch-1.p6 | 19 +++++++++++++++++++ challenge-067/noud/raku/ch-2.p6 | 28 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 challenge-067/noud/raku/ch-1.p6 create mode 100644 challenge-067/noud/raku/ch-2.p6 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 => , + 3 => , + 4 => , + 5 => , + 6 => , + 7 =>

, + 8 => , + 9 => ; + +sub phone-to-string($S) { + return [X~] gather { take %phone{$_} for $S.comb; }; +} + +.say for phone-to-string('35'); + + + -- cgit