aboutsummaryrefslogtreecommitdiff
path: root/examples/fifty.bqn
diff options
context:
space:
mode:
Diffstat (limited to 'examples/fifty.bqn')
-rw-r--r--examples/fifty.bqn14
1 files changed, 8 insertions, 6 deletions
diff --git a/examples/fifty.bqn b/examples/fifty.bqn
index c514ad7d..1b31814e 100644
--- a/examples/fifty.bqn
+++ b/examples/fifty.bqn
@@ -226,21 +226,23 @@ CRT ← {
! 2‿¯1‿1 ≡ 4 XEA 6
! 12‿9 ≡ 4‿1 CRT 6‿3
-# 46 (not working yet)
+# 46
Sieve←{
4≥𝕩 ? 𝕩⥊0‿0‿1‿1;
𝕊 n:
r←⌊√n
p ← 2‿3‿5‿7‿11‿13‿17‿19‿23‿29‿31‿37‿41‿43
- p ↩ •Show (1+⊑(n≤×`p)⊐⥊1)↑p
- b ← 0⌾(0⊸⊑)⋈ {(m⥊𝕩)>m⥊𝕨↑1 ⊣ m←n⌊𝕨×≢𝕩}´ ⌽1∾p
+ p ↩ (1+(×`p)⊸⍋⌾<n-1)↑p
+ b ← 0⌾(1⊸⊑) 1 {m←n⌊𝕨×≠𝕩 ⋄ (m⥊𝕩)>m⥊𝕨↑1}´ ⌽p
{
- r<⊑b⊐⥊1 ? b⊣b ↩ 1⌾(𝕩⊸⊑)b;
- q←⊑b⊐⥊1
- b ↩ 0⌾((q∾q×/b↑˜⌈n÷q)⊸⊑) b
+ r≥q←b⊸⊐⌾<1 ?
+ b 0¨⌾((q∾q×/b↑˜⌈n÷q)⊸⊏)↩
𝕊 𝕩∾q
+ ;
+ b 1¨⌾(𝕩⊸⊏)↩
}p
}
+! 2‿3‿5‿7‿11‿13‿17‿19‿23‿29 ≡ /Sieve 30
# 47
Pg ← •rand.Deal{