aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-335/conor-hoekstra/ch-1.bqn14
-rw-r--r--challenge-335/conor-hoekstra/ch-2.bqn20
2 files changed, 34 insertions, 0 deletions
diff --git a/challenge-335/conor-hoekstra/ch-1.bqn b/challenge-335/conor-hoekstra/ch-1.bqn
new file mode 100644
index 0000000000..947c76fcb5
--- /dev/null
+++ b/challenge-335/conor-hoekstra/ch-1.bqn
@@ -0,0 +1,14 @@
+# For up to date code:
+# https://github.com/codereport/bqn-code/blob/main/pwc/335-1.bqn
+
+u ⇐ •Import "/home/cph/bqn-test/test.bqn"
+
+a ← 'a'+↕25
+CommonCharacters ← a/˜·⌊´(+´˘a⊸(=⌜))¨
+
+# Tests
+u.UnitTest (CommonCharacters ⟨"bella", "label", "roller"⟩) ≡ "ell"
+u.UnitTest (CommonCharacters ⟨"cool", "lock", "cook"⟩) ≡ "co"
+u.UnitTest (CommonCharacters ⟨"hello", "world", "pole"⟩) ≡ "lo"
+u.UnitTest (CommonCharacters ⟨"abc", "def", "ghi"⟩) ≡ ""
+u.UnitTest (CommonCharacters ⟨"aab", "aac", "aaa"⟩) ≡ "aa"
diff --git a/challenge-335/conor-hoekstra/ch-2.bqn b/challenge-335/conor-hoekstra/ch-2.bqn
new file mode 100644
index 0000000000..c7d7504f5f
--- /dev/null
+++ b/challenge-335/conor-hoekstra/ch-2.bqn
@@ -0,0 +1,20 @@
+# For up to date code:
+# https://github.com/codereport/bqn-code/blob/main/pwc/335-2.bqn
+
+u ⇐ •Import "/home/cph/bqn-test/test.bqn"
+
+wins ← 8‿3⥊0‿4‿8‿0‿1‿2‿3‿4‿5‿6‿7‿8‿0‿3‿6‿1‿4‿7‿2‿5‿8‿2‿4‿6
+Play ← { 𝕨⌾(𝕩⊸⊑)9⥊0 }
+Pos ← { +´3‿1×𝕩 }
+State ← { ∧´⎉1⟨1,2⟩=⌜wins⊏𝕩 }
+FindWinner ← {
+ x ← +´1‿2×+´˘State ⌈´{ 𝕊p‿ab: ab Play Pos p }¨𝕩⋈¨1‿2⥊˜≠𝕩
+ (1+x-9=≠𝕩)⊑⟨"Draw","Pending","A","B"⟩
+}
+
+# Tests
+u.UnitTest (FindWinner ⟨0‿0,2‿0,1‿1,2‿1,2‿2⟩) ≡ "A"
+u.UnitTest (FindWinner ⟨0‿0,1‿1,0‿1,0‿2,1‿0,2‿0⟩) ≡ "B"
+u.UnitTest (FindWinner ⟨0‿0,1‿1,2‿0,1‿0,1‿2,2‿1,0‿1,0‿2,2‿2⟩) ≡ "Draw"
+u.UnitTest (FindWinner ⟨0‿0,1‿1⟩) ≡ "Pending"
+u.UnitTest (FindWinner ⟨1‿1,0‿0,2‿2,0‿1,1‿0,0‿2⟩) ≡ "B"