aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-347/conor-hoekstra/ch-1.bqn16
-rw-r--r--challenge-347/conor-hoekstra/ch-2.bqn17
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-347/conor-hoekstra/ch-1.bqn b/challenge-347/conor-hoekstra/ch-1.bqn
new file mode 100644
index 0000000000..c6962a357d
--- /dev/null
+++ b/challenge-347/conor-hoekstra/ch-1.bqn
@@ -0,0 +1,16 @@
+# For up to date code:
+# https://github.com/codereport/bqn-code/blob/main/pwc/347-1.bqn
+
+u ⇐ •Import "/home/cph/bqn-test/test.bqn"
+s ⇐ •Import "/home/cph/bqn-code/lib/string.bqn"
+
+months ← ""‿"Jan"‿"Feb"‿"Mar"‿"Apr"‿"May"‿"Jun"‿"Jul"‿"Aug"‿"Sep"‿"Oct"‿"Nov"‿"Dec"
+Pad ← (1=≠)◶⟨⊢,"0"⊸∾⟩
+Format ← { 𝕊d‿m‿y: "-" s.Join ⟨y,Pad•Fmt⊑months⊐⋈m,Pad ¯2↓d⟩ } s.Words
+
+# Tests
+u.UnitTest (Format "1st Jan 2025") ≡ "2025-01-01"
+u.UnitTest (Format "22nd Feb 2025") ≡ "2025-02-22"
+u.UnitTest (Format "15th Apr 2025") ≡ "2025-04-15"
+u.UnitTest (Format "23rd Oct 2025") ≡ "2025-10-23"
+u.UnitTest (Format "31st Dec 2025") ≡ "2025-12-31"
diff --git a/challenge-347/conor-hoekstra/ch-2.bqn b/challenge-347/conor-hoekstra/ch-2.bqn
new file mode 100644
index 0000000000..8ccb7f2339
--- /dev/null
+++ b/challenge-347/conor-hoekstra/ch-2.bqn
@@ -0,0 +1,17 @@
+# For up to date code:
+# https://github.com/codereport/bqn-code/blob/main/pwc/347-2.bqn
+
+u ⇐ •Import "/home/cph/bqn-test/test.bqn"
+s ⇐ •Import "/home/cph/bqn-code/lib/string.bqn"
+
+Hj ← '-'⊸s.Join
+Last ← (2-˜≠)◶⟨⋈,⋈,2⊸(↑⋈↓)⟩
+Rec ← { 4≥≠𝕩 ? ⋈ Hj Last 𝕩 ; (⋈3↑𝕩)∾𝕊3↓𝕩 }
+Format ← Hj·Rec(¬∊⟜"- ")⊸/
+
+# Tests
+u.UnitTest (Format "1-23-45-6") ≡ "123-456"
+u.UnitTest (Format "1234") ≡ "12-34"
+u.UnitTest (Format "12 345-6789") ≡ "123-456-789"
+u.UnitTest (Format "123 4567") ≡ "123-45-67"
+u.UnitTest (Format "123 456-78") ≡ "123-456-78"