aboutsummaryrefslogtreecommitdiff
path: root/challenge-076
diff options
context:
space:
mode:
authorConor Hoekstra <codereport@outlook.com>2024-11-27 16:33:08 -0500
committerConor Hoekstra <codereport@outlook.com>2024-11-27 16:33:08 -0500
commit592407d506c11c8e536b08e605a6bc8bb3d73d72 (patch)
tree895d3c82d3043f8ca3eb199adfaebc6b28ace9b5 /challenge-076
parent669755670125995913c1fd5fbd593859ac66fbcb (diff)
downloadperlweeklychallenge-club-592407d506c11c8e536b08e605a6bc8bb3d73d72.tar.gz
perlweeklychallenge-club-592407d506c11c8e536b08e605a6bc8bb3d73d72.tar.bz2
perlweeklychallenge-club-592407d506c11c8e536b08e605a6bc8bb3d73d72.zip
:sparkles: Week 76 in BQN
Diffstat (limited to 'challenge-076')
-rw-r--r--challenge-076/conor-hoekstra/ch-1.bqn13
-rw-r--r--challenge-076/conor-hoekstra/ch-2.bqn22
2 files changed, 35 insertions, 0 deletions
diff --git a/challenge-076/conor-hoekstra/ch-1.bqn b/challenge-076/conor-hoekstra/ch-1.bqn
new file mode 100644
index 0000000000..b91b717341
--- /dev/null
+++ b/challenge-076/conor-hoekstra/ch-1.bqn
@@ -0,0 +1,13 @@
+# For up to date code:
+# https://github.com/codereport/bqn-code/blob/main/pwc/076-1.bqn
+
+⟨UnitTest⟩ ⇐ •Import "/home/cph/bqn-test/test.bqn"
+⟨PrimesTo⟩ ⇐ •Import "/home/cph/bqn-code/lib/primes.bqn"
+
+PrimeSum ← { +´⊑∘⌽¨(⌊|˜⋈÷)○⊑`0⋈˜¨𝕩∾⟜(⌽PrimesTo)𝕩 }
+
+# Tests
+UnitTest (PrimeSum 9 ) ≡ 2
+UnitTest (PrimeSum 17 ) ≡ 1
+UnitTest (PrimeSum 21 ) ≡ 2
+UnitTest (PrimeSum 100) ≡ 2
diff --git a/challenge-076/conor-hoekstra/ch-2.bqn b/challenge-076/conor-hoekstra/ch-2.bqn
new file mode 100644
index 0000000000..ecfae2e03b
--- /dev/null
+++ b/challenge-076/conor-hoekstra/ch-2.bqn
@@ -0,0 +1,22 @@
+# For up to date code:
+# https://github.com/codereport/bqn-code/blob/main/pwc/076-2.bqn
+
+⟨UnitTest⟩ ⇐ •Import "/home/cph/bqn-test/test.bqn"
+s ⇐ •Import "/home/cph/bqn-code/lib/string.bqn"
+
+# Constants
+file ← "/home/cph/bqn-code/pwc/076-search-grid.txt"
+dict ← "/home/cph/scrabble/scrabble/dictionary/nwl_2020.txt"
+
+FindWords ← {
+ d ← (5≤≠¨)⊸/⊑∘s.Words¨•file.Lines dict # dictionary
+ l ← >' '⊸≠⊸/¨•file.Lines 𝕩 # lines
+ Cs ← {(1<≠¨)⊸/∾∾(↑¨↓)¨𝕩} # contiguous substrings
+ Ad ← (+⌜´↕¨∘≢)⊸⊔ # anti-diagonals
+ d/˜d∊⍷Cs∾{𝕎𝕩}⟜l¨⟨Ad·⍉⌽,Ad⍉,Ad⌽,Ad,<˘⍉,<˘⌽˘,<˘⌽⟩
+}
+
+# Test
+expected ← s.Upper¨ ", " s.Split "aimed, align, antes, arose, ashed, blunt, blunts, broad, buries, clove, cloven, constitution, constitutions, croon, depart, departed, enter, filch, garlic, goats, grieve, grieves, hazard, liens, malign, malignant, malls, midst, ought, ovary, parted, pudgiest, quash, quashed, ruses, shrine, shrines, social, socializing, spasm, spasmodic, succor, succors, theorem, theorems, virus, viruses, wigged"
+
+UnitTest ((res ← FindWords file) (¬∘∊⊸/⊣) expected) ≡ ⟨⟩