aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-088/richard-park/apl/ch-1.aplf1
-rw-r--r--challenge-088/richard-park/apl/ch-2.aplf1
-rw-r--r--challenge-088/richard-park/javascript/ch-1.js5
-rw-r--r--challenge-088/richard-park/javascript/ch-2.js8
-rw-r--r--challenge-088/richard-park/python/ch-1.py21
-rw-r--r--challenge-088/richard-park/python/ch-2.py18
6 files changed, 54 insertions, 0 deletions
diff --git a/challenge-088/richard-park/apl/ch-1.aplf b/challenge-088/richard-park/apl/ch-1.aplf
new file mode 100644
index 0000000000..ed4a45b17b
--- /dev/null
+++ b/challenge-088/richard-park/apl/ch-1.aplf
@@ -0,0 +1 @@
+ ArrayOfProduct←{×/⍵⌷⍤1 99⍨↑(⊢~⍥,⍤99 0⊢)⍳⍴⍵}
diff --git a/challenge-088/richard-park/apl/ch-2.aplf b/challenge-088/richard-park/apl/ch-2.aplf
new file mode 100644
index 0000000000..4af6643008
--- /dev/null
+++ b/challenge-088/richard-park/apl/ch-2.aplf
@@ -0,0 +1 @@
+ SpiralMatrix←{0∊⍴⍵:⍬ ⋄ (1⌷⍵),∇⍉⌽1↓⍵}
diff --git a/challenge-088/richard-park/javascript/ch-1.js b/challenge-088/richard-park/javascript/ch-1.js
new file mode 100644
index 0000000000..362d5b1519
--- /dev/null
+++ b/challenge-088/richard-park/javascript/ch-1.js
@@ -0,0 +1,5 @@
+// Inspired by {×/⍵⌷⍤1 99⍨↑(⊢~⍥,⍤99 0⊢)⍳⍴⍵}
+RemoveFrom=(a,i)=>a.slice(0,i).concat(a.slice(i+1,))
+I = n => [...Array(n).keys()]
+P = a => a.reduce((x,y)=>x*y)
+ArrayOfProduct=a=>I(a.length).map(i=>P(RemoveFrom(a,i)))
diff --git a/challenge-088/richard-park/javascript/ch-2.js b/challenge-088/richard-park/javascript/ch-2.js
new file mode 100644
index 0000000000..e69cdb7bdf
--- /dev/null
+++ b/challenge-088/richard-park/javascript/ch-2.js
@@ -0,0 +1,8 @@
+// Translation of {0∊⍴⍵:⍬ ⋄ (1⌷⍵),∇⍉⌽1↓⍵}
+I = n => [...Array(n).keys()] // Iota ⍳
+R = a=>a.map((e,i)=>a[a.length-i-1]) // Reverse ⊖
+T = m => { // Transpose ⍉
+ let r=m.length;let c=m[0].length; var a=[]
+ return I(c).map((e,i)=>I(r).map((_,j)=>m[r-j-1][i])).map(R)
+}
+SpiralMatrix = m => 1==m.length?m[0]:m[0].concat(SpiralMatrix(T(m.slice(1,).map(R))))
diff --git a/challenge-088/richard-park/python/ch-1.py b/challenge-088/richard-park/python/ch-1.py
new file mode 100644
index 0000000000..9c08f54b45
--- /dev/null
+++ b/challenge-088/richard-park/python/ch-1.py
@@ -0,0 +1,21 @@
+from numpy import array, concatenate
+from functools import reduce
+# Inspired by {×/⍵⌷⍤1 99⍨↑(⊢~⍥,⍤99 0⊢)⍳⍴⍵}
+
+def RemoveFrom(a,i): # Remove element at index i from array a
+ arr = array(a)
+ return list(concatenate((a[0:i],a[i+1:])))
+
+def Times(x,y):
+ return x*y
+def Product(a):
+ return reduce(Times,a)
+
+def ArrayOfProduct(m):
+ r = []
+ for i in range(len(m)):
+ r.append(Product(RemoveFrom(m,i)))
+ return r
+
+a = [5,2,1,4,3]
+print(ArrayOfProduct(a))
diff --git a/challenge-088/richard-park/python/ch-2.py b/challenge-088/richard-park/python/ch-2.py
new file mode 100644
index 0000000000..ee935d8d1e
--- /dev/null
+++ b/challenge-088/richard-park/python/ch-2.py
@@ -0,0 +1,18 @@
+# Inspired by {0∊⍴⍵:⍬ ⋄ (1⌷⍵),∇⍉⌽1↓⍵}
+from numpy import concatenate, transpose
+
+def Reverse(a):
+ return list(reversed(a))
+
+def SpiralMatrix(m):
+ if 1==len(m):
+ return m[0:1]
+ else:
+ return concatenate((m[0:1],SpiralMatrix(transpose(list(map(Reverse,m[1:]))))),axis=1)
+
+m = [[1,2,3],[4,5,6],[7,8,9]]
+
+print(list(list(SpiralMatrix(m))[0]))
+
+
+