Blum integer: Difference between revisions

→‎{{header|J}}: considerably faster
(→‎{{header|J}}: considerably faster)
Line 297:
=={{header|J}}==
 
Implementation: <syntaxhighlight lang=J>blumseqisblum=: {{
bab=. 1e3q: y
p=if. (2= #~ab 1 p: ])<.3 4 p.ido.b
r= if. /:~ (</~ab #&, */~) pdo.
L=*. y{r/3=4|ab
L=. done=. 0
while. - else.done do0 end.
else. 0 L0=end. L
}}"0
P=. (#~ 1 p: ])<.3 4 p. b+i.1e3
 
R1=. p (</ #&, */) P
blumseq=: {{
R2=. (</~ #&, */~) P
r=. (#~ isblum) }.i.b=. b+1e31e4
while. y>#r p=do. p,P
r=. /:~ r, R1,(#~ isblum) R2b+i.1e4
Lb=. r I. {.R2b+1e4
if. y<L do.
L=. y{r
done=. (L=L0)*0=#$L0
r=. (y+1){.r
end.
end.
y{.r
}}</syntaxhighlight>
 
In other words, generate some blum numbers and keep adding to them until the smallest number being added to the sequence exceeds the largest value within the desired sequence length.
 
Task examples:
6,951

edits