Hofstadter Figure-Figure sequences: Difference between revisions
Content deleted Content added
C++ language versions |
CoffeeScript version |
||
Line 485:
69
Verified</pre>
=={{header|CoffeeScript}}==
{{trans|Ruby}}
<lang coffeescript>R = [ null, 1 ]
S = [ null, 2 ]
extend_sequences = (n) ->
current = Math.max(R[R.length - 1], S[S.length - 1])
i = undefined
while R.length <= n or S.length <= n
i = Math.min(R.length, S.length) - 1
current += 1
if current == R[i] + S[i]
R.push current
else
S.push current
ffr = (n) ->
extend_sequences n
R[n]
ffs = (n) ->
extend_sequences n
S[n]
[1..10].map (i) -> console.log 'R(' + i + ') = ' + ffr(i)
int_array = [1..40].map ffr
int_array.concat [1..960].map ffs
int_array.sort (a, b) -> a - b
i = 1
while i <= 1000
if int_array[i - 1] != i
throw 'Something\'s wrong!'
else
console.log '1000 integer check ok.'
i += 1</lang>
{{out}}
As JavaScript.
=={{header|Common Lisp}}==
|