aboutsummaryrefslogtreecommitdiff
path: root/challenge-322
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-05-20 09:14:23 +0100
committerGitHub <noreply@github.com>2025-05-20 09:14:23 +0100
commita28f9a673f339462eae61cfd5e0ff2f0053ec43d (patch)
treedaf50fbdacbc6182b2f395853f12375633c9a34c /challenge-322
parent695a0fa6c7e38feaa49871cf8d9e7a0e4b935ef2 (diff)
parentbe4730a3a5f224a5f1c6fa57f72fbfa65f1b21e5 (diff)
downloadperlweeklychallenge-club-a28f9a673f339462eae61cfd5e0ff2f0053ec43d.tar.gz
perlweeklychallenge-club-a28f9a673f339462eae61cfd5e0ff2f0053ec43d.tar.bz2
perlweeklychallenge-club-a28f9a673f339462eae61cfd5e0ff2f0053ec43d.zip
Merge pull request #12055 from codereport/master
:sparkles: Week 322 in BQN
Diffstat (limited to 'challenge-322')
-rw-r--r--challenge-322/conor-hoekstra/ch-1.bqn14
-rw-r--r--challenge-322/conor-hoekstra/ch-2.bqn15
2 files changed, 29 insertions, 0 deletions
diff --git a/challenge-322/conor-hoekstra/ch-1.bqn b/challenge-322/conor-hoekstra/ch-1.bqn
new file mode 100644
index 0000000000..3af00f74a2
--- /dev/null
+++ b/challenge-322/conor-hoekstra/ch-1.bqn
@@ -0,0 +1,14 @@
+# For up to date code:
+# https://github.com/codereport/bqn-code/blob/main/pwc/322-1.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"
+
+Tf ← '-'s.Join fn.Chunk⟜∾ # tail format
+Sf ← { n𝕊x:{ n>≠⊑𝕩 ? (⊑𝕩)∾"-"∾n Tf 1↓𝕩 ; n Tf 𝕩 } '-'s.Split x } # string format
+
+# Tests
+u.UnitTest (3 Sf "ABC-D-E-F") ≡ "ABC-DEF"
+u.UnitTest (2 Sf "A-BC-D-E") ≡ "A-BC-DE"
+u.UnitTest (4 Sf "-A-B-CD-E") ≡ "A-BCDE"
diff --git a/challenge-322/conor-hoekstra/ch-2.bqn b/challenge-322/conor-hoekstra/ch-2.bqn
new file mode 100644
index 0000000000..b981bdfb46
--- /dev/null
+++ b/challenge-322/conor-hoekstra/ch-2.bqn
@@ -0,0 +1,15 @@
+# For up to date code:
+# https://github.com/codereport/bqn-code/blob/main/pwc/322-2.bqn
+
+u ⇐ •Import "/home/cph/bqn-test/test.bqn"
+
+RankArray ← { 1+𝕩⊐˜∧⍷𝕩 } # explicit
+RankArray2 ← 1+∧∘⍷⊐⊢ # tacit
+
+# Tests
+u.UnitTest (RankArray 55‿22‿44‿33) ≡ 4‿1‿3‿2
+u.UnitTest (RankArray 10‿10‿10) ≡ 1‿1‿1
+u.UnitTest (RankArray 5‿1‿1‿4‿3) ≡ 4‿1‿1‿3‿2
+u.UnitTest (RankArray2 55‿22‿44‿33) ≡ 4‿1‿3‿2
+u.UnitTest (RankArray2 10‿10‿10) ≡ 1‿1‿1
+u.UnitTest (RankArray2 5‿1‿1‿4‿3) ≡ 4‿1‿1‿3‿2