Blum integer: Difference between revisions
Content added Content deleted
(→{{header|J}}: considerably faster) |
|||
Line 297: | Line 297: | ||
=={{header|J}}== |
=={{header|J}}== |
||
Implementation: <syntaxhighlight lang=J> |
Implementation: <syntaxhighlight lang=J>isblum=: {{ |
||
ab=. q: y |
|||
if. 2= #ab do. |
|||
if. </ab do. |
|||
⚫ | |||
L=. done=. 0 |
|||
else. 0 end. |
|||
else. 0 end. |
|||
}}"0 |
|||
P=. (#~ 1 p: ])<.3 4 p. b+i.1e3 |
|||
R1=. p (</ #&, */) P |
|||
blumseq=: {{ |
|||
R2=. (</~ #&, */~) P |
|||
b=. |
r=. (#~ isblum) }.i.b=. 1e4 |
||
while. y>#r do. |
|||
r=. |
r=. r, (#~ isblum) b+i.1e4 |
||
b=. b+1e4 |
|||
if. y<L do. |
|||
⚫ | |||
done=. (L=L0)*0=#$L0 |
|||
r=. (y+1){.r |
|||
end. |
|||
end. |
end. |
||
y{.r |
y{.r |
||
}}</syntaxhighlight> |
}}</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: |
Task examples: |