aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-334/conor-hoekstra/ch-1.bqn13
-rw-r--r--challenge-334/conor-hoekstra/ch-2.bqn16
2 files changed, 29 insertions, 0 deletions
diff --git a/challenge-334/conor-hoekstra/ch-1.bqn b/challenge-334/conor-hoekstra/ch-1.bqn
new file mode 100644
index 0000000000..f19d77fa48
--- /dev/null
+++ b/challenge-334/conor-hoekstra/ch-1.bqn
@@ -0,0 +1,13 @@
+# For up to date code:
+# https://github.com/codereport/bqn-code/blob/main/pwc/334-1.bqn
+
+u ⇐ •Import "/home/cph/bqn-test/test.bqn"
+
+RangeSum ← { a‿b𝕊𝕩: +´(1+b-a)↑a↓𝕩 }
+
+# Tests
+u.UnitTest (0‿2 RangeSum ⟨¯2,0,3,¯5,2,¯1⟩) ≡ 1
+u.UnitTest (1‿3 RangeSum ⟨1,¯2,3,¯4,5⟩) ≡ ¯3
+u.UnitTest (3‿4 RangeSum ⟨1,0,2,¯1,3⟩) ≡ 2
+u.UnitTest (0‿3 RangeSum ⟨¯5,4,¯3,2,¯1,0⟩) ≡ ¯2
+u.UnitTest (0‿2 RangeSum ⟨¯1,0,2,¯3,¯2,1⟩) ≡ 1
diff --git a/challenge-334/conor-hoekstra/ch-2.bqn b/challenge-334/conor-hoekstra/ch-2.bqn
new file mode 100644
index 0000000000..35f6ebd7f5
--- /dev/null
+++ b/challenge-334/conor-hoekstra/ch-2.bqn
@@ -0,0 +1,16 @@
+# For up to date code:
+# https://github.com/codereport/bqn-code/blob/main/pwc/334-2.bqn
+
+u ⇐ •Import "/home/cph/bqn-test/test.bqn"
+
+Dist ← +´|∘-
+NearestValidPoint ← { x‿y𝕊p:
+ v ← (y⍷⊢´¨p)∨x⍷⊑¨p # valid points
+ { 0=+´v ? ¯1 ; ⊑p⊐(v/p)/˜⌊´⊸=(x∾y)⊸Dist¨v/p }
+}
+
+# Tests
+u.UnitTest (3‿4 NearestValidPoint ⟨1‿2, 3‿1, 2‿4, 2‿3⟩) ≡ 2
+u.UnitTest (2‿5 NearestValidPoint ⟨3‿4, 2‿3, 1‿5, 2‿5⟩) ≡ 3
+u.UnitTest (1‿1 NearestValidPoint ⟨2‿2, 3‿3, 4‿4⟩) ≡ ¯1
+u.UnitTest (0‿0 NearestValidPoint ⟨0‿1, 1‿0, 0‿2, 2‿0⟩) ≡ 0