aboutsummaryrefslogtreecommitdiff
path: root/challenge-067
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2020-07-06 00:24:17 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2020-07-06 00:24:17 +0100
commit7b32c1d78a98d625710dc97ad8aef600a1a523d4 (patch)
treebe4a6e3ae2921501b09333c411132de9be79d9bc /challenge-067
parenta1693a58dc7619db3962e7f331714538bd76954b (diff)
downloadperlweeklychallenge-club-7b32c1d78a98d625710dc97ad8aef600a1a523d4.tar.gz
perlweeklychallenge-club-7b32c1d78a98d625710dc97ad8aef600a1a523d4.tar.bz2
perlweeklychallenge-club-7b32c1d78a98d625710dc97ad8aef600a1a523d4.zip
- Added APL solutions by Richard Park.
Diffstat (limited to 'challenge-067')
-rw-r--r--challenge-067/richard-park/apl/LetterPhone.aplf6
-rw-r--r--challenge-067/richard-park/apl/NumberCombinations.aplf16
-rw-r--r--challenge-067/richard-park/apl/ch-1.aplf16
-rw-r--r--challenge-067/richard-park/apl/ch-2.aplf6
-rw-r--r--challenge-067/richard-park/blog.txt1
5 files changed, 45 insertions, 0 deletions
diff --git a/challenge-067/richard-park/apl/LetterPhone.aplf b/challenge-067/richard-park/apl/LetterPhone.aplf
new file mode 100644
index 0000000000..dd200c706d
--- /dev/null
+++ b/challenge-067/richard-park/apl/LetterPhone.aplf
@@ -0,0 +1,6 @@
+ LetterPhone←{
+⍝ ⍵: Character vector of digits e.g. '35'
+⍝ ←: All possible letter combinations from a keypad defined by ⍺
+ ⍺←'_,@' 'ABC' 'DEF' 'GHI' 'JKL' 'MNO' 'PQRS' 'TUV' 'WXYZ'
+ ,⊃∘.,/⍺[⍎¨⍵]
+ }
diff --git a/challenge-067/richard-park/apl/NumberCombinations.aplf b/challenge-067/richard-park/apl/NumberCombinations.aplf
new file mode 100644
index 0000000000..5f7ad35d22
--- /dev/null
+++ b/challenge-067/richard-park/apl/NumberCombinations.aplf
@@ -0,0 +1,16 @@
+ NumberCombinations←{
+⍝ ←: All strictly ascending vectors of length ⍵
+⍝ which contain numbers in ⍳⍺
+⍝ Attempt 1
+⍝ =========
+ c←,((⍳⍺)∘.,⊢)⍣(¯1+⍵)⊢⍳⍺ ⍝ All combinations of digits in (⍳⍺)
+ ⍝ Of length ⍵
+ c⌿⍨{((∪≡⊢)⍵)∧((⊂⍋⍵)⌷⍵)≡⍵}¨c ⍝ Strictly ascending combinations
+⍝ Attempt 2
+⍝ =========
+⍝ e.g. 5 NumberCombinations 2
+ a←⍳¯1+⍺
+ b←(¯1+⍺)⍴⊂a ⍝ Maximal run repeated ¯1+⍺ times
+ c←1+0~⍨¨b×a≤b ⍝ Remove 0s and add 1
+ ⊃,/a,¨¨c ⍝ Catenate a's with c's
+ }
diff --git a/challenge-067/richard-park/apl/ch-1.aplf b/challenge-067/richard-park/apl/ch-1.aplf
new file mode 100644
index 0000000000..5f7ad35d22
--- /dev/null
+++ b/challenge-067/richard-park/apl/ch-1.aplf
@@ -0,0 +1,16 @@
+ NumberCombinations←{
+⍝ ←: All strictly ascending vectors of length ⍵
+⍝ which contain numbers in ⍳⍺
+⍝ Attempt 1
+⍝ =========
+ c←,((⍳⍺)∘.,⊢)⍣(¯1+⍵)⊢⍳⍺ ⍝ All combinations of digits in (⍳⍺)
+ ⍝ Of length ⍵
+ c⌿⍨{((∪≡⊢)⍵)∧((⊂⍋⍵)⌷⍵)≡⍵}¨c ⍝ Strictly ascending combinations
+⍝ Attempt 2
+⍝ =========
+⍝ e.g. 5 NumberCombinations 2
+ a←⍳¯1+⍺
+ b←(¯1+⍺)⍴⊂a ⍝ Maximal run repeated ¯1+⍺ times
+ c←1+0~⍨¨b×a≤b ⍝ Remove 0s and add 1
+ ⊃,/a,¨¨c ⍝ Catenate a's with c's
+ }
diff --git a/challenge-067/richard-park/apl/ch-2.aplf b/challenge-067/richard-park/apl/ch-2.aplf
new file mode 100644
index 0000000000..dd200c706d
--- /dev/null
+++ b/challenge-067/richard-park/apl/ch-2.aplf
@@ -0,0 +1,6 @@
+ LetterPhone←{
+⍝ ⍵: Character vector of digits e.g. '35'
+⍝ ←: All possible letter combinations from a keypad defined by ⍺
+ ⍺←'_,@' 'ABC' 'DEF' 'GHI' 'JKL' 'MNO' 'PQRS' 'TUV' 'WXYZ'
+ ,⊃∘.,/⍺[⍎¨⍵]
+ }
diff --git a/challenge-067/richard-park/blog.txt b/challenge-067/richard-park/blog.txt
new file mode 100644
index 0000000000..9615e69ee9
--- /dev/null
+++ b/challenge-067/richard-park/blog.txt
@@ -0,0 +1 @@
+https://www.youtube.com/watch?v=tSQOOzyD4Qw