aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConor Hoekstra <codereport@outlook.com>2021-10-13 22:29:03 -0400
committerConor Hoekstra <codereport@outlook.com>2021-10-13 22:29:03 -0400
commit6a5b842ebe7197d8fa85d5d84a2159328c685a72 (patch)
treef23d8e81ddab49df73b66ca88d4b85ba75e543f5
parentfe117d2fc5884464f681a2dd4d21456efe6c64f1 (diff)
downloadperlweeklychallenge-club-6a5b842ebe7197d8fa85d5d84a2159328c685a72.tar.gz
perlweeklychallenge-club-6a5b842ebe7197d8fa85d5d84a2159328c685a72.tar.bz2
perlweeklychallenge-club-6a5b842ebe7197d8fa85d5d84a2159328c685a72.zip
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