aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-10-14 03:45:37 +0100
committerGitHub <noreply@github.com>2021-10-14 03:45:37 +0100
commit5a794d6d6aa988988db2c90c98cea224c26c282a (patch)
treed6f72828f0504ee35a5373e03e2fbceea0e0bfdd
parentd8eb1c6609001b0e0f833490f78a8cbf41509b68 (diff)
parent6a5b842ebe7197d8fa85d5d84a2159328c685a72 (diff)
downloadperlweeklychallenge-club-5a794d6d6aa988988db2c90c98cea224c26c282a.tar.gz
perlweeklychallenge-club-5a794d6d6aa988988db2c90c98cea224c26c282a.tar.bz2
perlweeklychallenge-club-5a794d6d6aa988988db2c90c98cea224c26c282a.zip
Merge pull request #5020 from codereport/master
Beautiful 4 Character solutions in APL, BQN, J (+ Haskell & C++) for Week 88
-rw-r--r--challenge-088/conor-hoekstra/ch-01.apl10
-rw-r--r--challenge-088/conor-hoekstra/ch-01.bqn10
-rw-r--r--challenge-088/conor-hoekstra/ch-01.cpp12
-rw-r--r--challenge-088/conor-hoekstra/ch-01.hs7
-rw-r--r--challenge-088/conor-hoekstra/ch-01.ijs4
5 files changed, 43 insertions, 0 deletions
diff --git a/challenge-088/conor-hoekstra/ch-01.apl b/challenge-088/conor-hoekstra/ch-01.apl
new file mode 100644
index 0000000000..1cafa31091
--- /dev/null
+++ b/challenge-088/conor-hoekstra/ch-01.apl
@@ -0,0 +1,10 @@
+⍝ Two Suboptimal Solutions
+solution ← ⊃×/∘(¯1↓⍳∘≢⌽¨⊂) ⍝ Using rotates
+solution ← ×/¨((↓∘.≠⍨∘⍳∘≢)⊢⍤/¨⊂) ⍝ Using filters (compresses)
+
+⍝ The Actual Solution
+solution ← ×/÷⊢
+
+⍝ Tests
+solution 5 2 1 4 3 ⍝ 24 60 120 30 40
+solution 2 1 4 3 ⍝ 12 24 6 8
diff --git a/challenge-088/conor-hoekstra/ch-01.bqn b/challenge-088/conor-hoekstra/ch-01.bqn
new file mode 100644
index 0000000000..5bdeb4fe6a
--- /dev/null
+++ b/challenge-088/conor-hoekstra/ch-01.bqn
@@ -0,0 +1,10 @@
+# Two Suboptimal Solutions
+Solution ← ×´¨1↓¨(↕∘≠)⌽¨< # Using rotates
+Solution ← ×´¨(<˘≠⌜˜∘↕∘≠)/¨< # Using filters (replicates)
+
+# The Actual Solution
+Solution ← ×´÷⊢
+
+# Tests
+Solution 5‿2‿1‿4‿3 # ⟨ 24 60 120 30 40 ⟩
+Solution 2‿1‿4‿3 # ⟨ 12 24 6 8 ⟩
diff --git a/challenge-088/conor-hoekstra/ch-01.cpp b/challenge-088/conor-hoekstra/ch-01.cpp
new file mode 100644
index 0000000000..722df1bf47
--- /dev/null
+++ b/challenge-088/conor-hoekstra/ch-01.cpp
@@ -0,0 +1,12 @@
+// Godbolt Link: https://godbolt.org/z/dGGKzdYhn
+
+#include <algorithm>
+#include <numeric>
+#include <vector>
+#include <functional>
+
+auto array_product(std::vector<int> v) -> std::vector<int> {
+ auto const prod = std::accumulate(v.cbegin(), v.cend(), 1, std::multiplies{});
+ std::transform(v.cbegin(), v.cend(), v.begin(), [=] (auto e) { return prod / e; });
+ return v;
+}
diff --git a/challenge-088/conor-hoekstra/ch-01.hs b/challenge-088/conor-hoekstra/ch-01.hs
new file mode 100644
index 0000000000..0d862cf94a
--- /dev/null
+++ b/challenge-088/conor-hoekstra/ch-01.hs
@@ -0,0 +1,7 @@
+import Control.Monad (<*>)
+
+solution = flip (zipWith (div) . repeat) <*> product
+
+-- Tests
+solution [5,2,1,4,3] -- [24,60,120,30,40]
+solution [2,1,4,3] -- [12,24,6,8]
diff --git a/challenge-088/conor-hoekstra/ch-01.ijs b/challenge-088/conor-hoekstra/ch-01.ijs
new file mode 100644
index 0000000000..e4e66a2009
--- /dev/null
+++ b/challenge-088/conor-hoekstra/ch-01.ijs
@@ -0,0 +1,4 @@
+solution =. %~*/
+
+solution 5 2 1 4 3 NB. 24 60 120 30 40
+solution 2 1 4 3 NB. 12 24 6 8