Ulam numbers: Difference between revisions

J
(J)
Line 667:
| length as == 1 = True
| otherwise = False</syntaxhighlight>
 
=={{header|J}}==
 
Implementation:
 
<syntaxhighlight lang=J>require'stats'
nextulam=: , {{<./(#~ ({:y)<])(~. #~ 1 = #/.~) +/"1 y{~2 comb #y}}
ulam=: <: { (nextulam^:(<:@(>./)`(1 2"_)))</syntaxhighlight>
 
This could be optimized, for example: caching could help.
 
Examples:
 
<syntaxhighlight lang=J> ulam 1
1
ulam 10
18
ulam 100
690
ulam 1000
12294
ulam 10000
132788
ulam 20 30 40 50 60
69 126 189 253 341</syntaxhighlight>
 
=={{header|Java}}==
6,951

edits