From 6a5b842ebe7197d8fa85d5d84a2159328c685a72 Mon Sep 17 00:00:00 2001 From: Conor Hoekstra Date: Wed, 13 Oct 2021 22:29:03 -0400 Subject: Week 88 --- challenge-088/conor-hoekstra/ch-01.apl | 10 ++++++++++ challenge-088/conor-hoekstra/ch-01.bqn | 10 ++++++++++ challenge-088/conor-hoekstra/ch-01.cpp | 12 ++++++++++++ challenge-088/conor-hoekstra/ch-01.hs | 7 +++++++ challenge-088/conor-hoekstra/ch-01.ijs | 4 ++++ 5 files changed, 43 insertions(+) create mode 100644 challenge-088/conor-hoekstra/ch-01.apl create mode 100644 challenge-088/conor-hoekstra/ch-01.bqn create mode 100644 challenge-088/conor-hoekstra/ch-01.cpp create mode 100644 challenge-088/conor-hoekstra/ch-01.hs create mode 100644 challenge-088/conor-hoekstra/ch-01.ijs 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 +#include +#include +#include + +auto array_product(std::vector v) -> std::vector { + 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 -- cgit