Ulam numbers: Difference between revisions

Content deleted Content added
Created page with "With the following initial conditions: <big><big> u<sub>1</sub> = 1 </big></big> <big><big> u<sub>2</sub> = 2 </big></big> we define the n-th Ulam number u<sub>n..."
 
PureFox (talk | contribs)
Added Wren
Line 15:
 
===Lazy List===
<lang haskell>ulam
ulam
:: Integral i =>
Int -> i
Line 42 ⟶ 41:
isSingleton as
| length as == 1 = True
| otherwise = False</lang>
 
=={{header|Wren}}==
{{libheader|Wren-set}}
<lang ecmascript>import "/set" for Set
 
var ulam = Fn.new() { |n|
var ulams = [1, 2]
var set = Set.new(ulams)
var i = 3
while (true) {
var count = 0
for (j in 0...ulams.count) {
if (set.contains(i - ulams[j]) && ulams[j] != (i - ulams[j])) {
count = count + 1
}
if (count > 2) break
}
if (count == 2) {
ulams.add(i)
set.add(i)
if (ulams.count == n) break
}
i = i + 1
}
return ulams[-1]
}
 
var n = 1
while (true) {
n = n * 10
System.print("The %(n)th Ulam number is %(ulam.call(n))")
if (n == 10000) break
}</lang>
 
{{out}}
<pre>
The 10th Ulam number is 18
The 100th Ulam number is 690
The 1000th Ulam number is 12294
The 10000th Ulam number is 132788
</pre>