Blum integer: Difference between revisions
Content added Content deleted
(J draft) |
|||
Line 294: | Line 294: | ||
Same as Wren example. |
Same as Wren example. |
||
</pre> |
</pre> |
||
=={{header|J}}== |
|||
Implementation: <syntaxhighlight lang=J>blumseq=: {{ |
|||
b=. 1e3 |
|||
p=. (#~ 1 p: ])<.3 4 p.i.b |
|||
r=. /:~ (</~ #&, */~) p |
|||
L=. done=. 0 |
|||
while. -.done do. |
|||
L0=. L |
|||
P=. (#~ 1 p: ])<.3 4 p. b+1+i.1e3 |
|||
R1=. p (</ #&, */) P |
|||
R2=. (</~ #&, */~) P |
|||
b=. b+1e3 |
|||
p=. p,P |
|||
r=. /:~ r, R1, R2 |
|||
L=. r I. {.R2 |
|||
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: |
|||
<syntaxhighlight lang=J> 5 10$blumseq 50 |
|||
21 33 57 69 77 93 129 133 141 161 |
|||
177 201 209 213 217 237 249 253 301 309 |
|||
321 329 341 381 393 413 417 437 453 469 |
|||
473 489 497 501 517 537 553 573 581 589 |
|||
597 633 649 669 681 713 717 721 737 749 |
|||
{: blumseq 26828 |
|||
524621</syntaxhighlight> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |