diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-08-12 13:24:09 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-12 13:24:09 +0100 |
| commit | ac2aaac5d4aba5dcf4a86f1beb88751ca0d64ebb (patch) | |
| tree | d59d452649f8532ce6fa322739cbe06dd289e086 /challenge-334 | |
| parent | 93759a600dd661a59eebe6b221bb2f7aa82700ff (diff) | |
| parent | 002e05f0608e5e7cad70215d9365bb8993ac521e (diff) | |
| download | perlweeklychallenge-club-ac2aaac5d4aba5dcf4a86f1beb88751ca0d64ebb.tar.gz perlweeklychallenge-club-ac2aaac5d4aba5dcf4a86f1beb88751ca0d64ebb.tar.bz2 perlweeklychallenge-club-ac2aaac5d4aba5dcf4a86f1beb88751ca0d64ebb.zip | |
Merge pull request #12505 from codereport/master
:sparkles: Week 334 in BQN
Diffstat (limited to 'challenge-334')
| -rw-r--r-- | challenge-334/conor-hoekstra/ch-1.bqn | 13 | ||||
| -rw-r--r-- | challenge-334/conor-hoekstra/ch-2.bqn | 16 |
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 |
