From 002e05f0608e5e7cad70215d9365bb8993ac521e Mon Sep 17 00:00:00 2001 From: Conor Hoekstra Date: Mon, 11 Aug 2025 13:20:22 -0400 Subject: :sparkles: Week 334 in BQN --- challenge-334/conor-hoekstra/ch-1.bqn | 13 +++++++++++++ challenge-334/conor-hoekstra/ch-2.bqn | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 challenge-334/conor-hoekstra/ch-1.bqn create mode 100644 challenge-334/conor-hoekstra/ch-2.bqn 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 -- cgit