aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-09-22 23:50:54 +0100
committerGitHub <noreply@github.com>2025-09-22 23:50:54 +0100
commitfcd04ce133bb23dc5fe17c73019120d3843a59e9 (patch)
treee0aa9764b5a8f44e9b7d647b4fc4839a30008dd8
parent5f2ddb536f7714e88eb8bfaf7bdeef60f2312bc7 (diff)
parent2c144195f02878836875ff351e57ecb92292c665 (diff)
downloadperlweeklychallenge-club-fcd04ce133bb23dc5fe17c73019120d3843a59e9.tar.gz
perlweeklychallenge-club-fcd04ce133bb23dc5fe17c73019120d3843a59e9.tar.bz2
perlweeklychallenge-club-fcd04ce133bb23dc5fe17c73019120d3843a59e9.zip
Merge pull request #12720 from codereport/master
✨ Week 339 and 340 in BQN
-rw-r--r--challenge-339/conor-hoekstra/ch-1.bqn28
-rw-r--r--challenge-339/conor-hoekstra/ch-2.bqn13
-rw-r--r--challenge-340/conor-hoekstra/ch-1.bqn14
-rw-r--r--challenge-340/conor-hoekstra/ch-2.bqn15
4 files changed, 70 insertions, 0 deletions
diff --git a/challenge-339/conor-hoekstra/ch-1.bqn b/challenge-339/conor-hoekstra/ch-1.bqn
new file mode 100644
index 0000000000..a54b321e16
--- /dev/null
+++ b/challenge-339/conor-hoekstra/ch-1.bqn
@@ -0,0 +1,28 @@
+# For up to date code:
+# https://github.com/codereport/bqn-code/blob/main/pwc/339-1.bqn
+
+u ⇐ •Import "/home/cph/bqn-test/test.bqn"
+fn ⇐ •Import "/home/cph/bqn-code/lib/fun.bqn"
+
+MaxProductDiff ← { ⌈´{ 𝕊a‿b‿c‿d: (a×b)-c×d }¨4 fn.ChooseWR 𝕩 } # solution 1
+MaxProductDiff2 ← { ⌈´{ -´×˝2‿2⥊𝕩 }¨4 fn.ChooseWR 𝕩 } # solution 2 (explicit)
+MaxProductDiff3 ← ⌈´·(-´·×˝2‿2⊸⥊)¨4⊸fn.ChooseWR # solution 3 (tacit)
+
+# Tests
+u.UnitTest (MaxProductDiff ⟨5, 9, 3, 4, 6⟩) ≡ 42
+u.UnitTest (MaxProductDiff ⟨1, ¯2, 3, ¯4⟩) ≡ 10
+u.UnitTest (MaxProductDiff ⟨¯3, ¯1, ¯2, ¯4⟩) ≡ 10
+u.UnitTest (MaxProductDiff ⟨10, 2, 0, 5, 1⟩) ≡ 50
+u.UnitTest (MaxProductDiff ⟨7, 8, 9, 10, 10⟩) ≡ 44
+
+u.UnitTest (MaxProductDiff2 ⟨5, 9, 3, 4, 6⟩) ≡ 42
+u.UnitTest (MaxProductDiff2 ⟨1, ¯2, 3, ¯4⟩) ≡ 10
+u.UnitTest (MaxProductDiff2 ⟨¯3, ¯1, ¯2, ¯4⟩) ≡ 10
+u.UnitTest (MaxProductDiff2 ⟨10, 2, 0, 5, 1⟩) ≡ 50
+u.UnitTest (MaxProductDiff2 ⟨7, 8, 9, 10, 10⟩) ≡ 44
+
+u.UnitTest (MaxProductDiff3 ⟨5, 9, 3, 4, 6⟩) ≡ 42
+u.UnitTest (MaxProductDiff3 ⟨1, ¯2, 3, ¯4⟩) ≡ 10
+u.UnitTest (MaxProductDiff3 ⟨¯3, ¯1, ¯2, ¯4⟩) ≡ 10
+u.UnitTest (MaxProductDiff3 ⟨10, 2, 0, 5, 1⟩) ≡ 50
+u.UnitTest (MaxProductDiff3 ⟨7, 8, 9, 10, 10⟩) ≡ 44
diff --git a/challenge-339/conor-hoekstra/ch-2.bqn b/challenge-339/conor-hoekstra/ch-2.bqn
new file mode 100644
index 0000000000..367b144c92
--- /dev/null
+++ b/challenge-339/conor-hoekstra/ch-2.bqn
@@ -0,0 +1,13 @@
+# For up to date code:
+# https://github.com/codereport/bqn-code/blob/main/pwc/339-2.bqn
+
+u ⇐ •Import "/home/cph/bqn-test/test.bqn"
+
+PeakPoint ← 0⌈´+`
+
+# Tests
+u.UnitTest (PeakPoint ⟨¯5, 1, 5, ¯9, 2⟩) ≡ 1
+u.UnitTest (PeakPoint ⟨10, 10, 10, ¯25⟩) ≡ 30
+u.UnitTest (PeakPoint ⟨3, -4, 2, 5, ¯6, 1⟩) ≡ 6
+u.UnitTest (PeakPoint ⟨¯1, -2, -3, -4⟩) ≡ 0
+u.UnitTest (PeakPoint ⟨¯10, 15, 5⟩) ≡ 10
diff --git a/challenge-340/conor-hoekstra/ch-1.bqn b/challenge-340/conor-hoekstra/ch-1.bqn
new file mode 100644
index 0000000000..c43f038cd2
--- /dev/null
+++ b/challenge-340/conor-hoekstra/ch-1.bqn
@@ -0,0 +1,14 @@
+# For up to date code:
+# https://github.com/codereport/bqn-code/blob/main/pwc/340-1.bqn
+
+u ⇐ •Import "/home/cph/bqn-test/test.bqn"
+fn ⇐ •Import "/home/cph/bqn-code/lib/fun.bqn"
+
+RemoveDuplicates ← (∾·(1<≠)◶⟨⊢,2⊸↓⟩¨fn.Group)⍟≠
+
+# Tests
+u.UnitTest (RemoveDuplicates "abbaca") ≡ "ca"
+u.UnitTest (RemoveDuplicates "azxxzy") ≡ "ay"
+u.UnitTest (RemoveDuplicates "aaaaaaaa") ≡ ""
+u.UnitTest (RemoveDuplicates "aabccba") ≡ "a"
+u.UnitTest (RemoveDuplicates "abcddcba") ≡ ""
diff --git a/challenge-340/conor-hoekstra/ch-2.bqn b/challenge-340/conor-hoekstra/ch-2.bqn
new file mode 100644
index 0000000000..904f0729c4
--- /dev/null
+++ b/challenge-340/conor-hoekstra/ch-2.bqn
@@ -0,0 +1,15 @@
+# For up to date code:
+# https://github.com/codereport/bqn-code/blob/main/pwc/340-2.bqn
+
+u ⇐ •Import "/home/cph/bqn-test/test.bqn"
+s ⇐ •Import "/home/cph/bqn-code/lib/string.bqn"
+fn ⇐ •Import "/home/cph/bqn-code/lib/fun.bqn"
+
+AscendingNumbers ← ∧´0<·fn.Deltas s.Nats
+
+# Tests
+u.UnitTest (AscendingNumbers "The cat has 3 kittens 7 toys 10 beds") ≡ 1
+u.UnitTest (AscendingNumbers "Alice bought 5 apples 2 oranges 9 bananas") ≡ 0
+u.UnitTest (AscendingNumbers "I ran 1 mile 2 days 3 weeks 4 months") ≡ 1
+u.UnitTest (AscendingNumbers "Bob has 10 cars 10 bikes") ≡ 0
+u.UnitTest (AscendingNumbers "Zero is 0 one is 1 two is 2") ≡ 1