mathematica program for recaman

Santi Spadaro spados at katamail.com
Tue Oct 9 20:59:29 CEST 2001


I'm trying to write a Mathematica program to generate Recaman's 
sequence. I've written this code:

okQ[n_] := (Count[l[n - 1], g[n]] == 0  && g[n] > 0)

l[n_] := Append[l[n - 1], f[n]]

l[1] = {1}

f[1] = 1

g[n_] := f[n - 1] - n

f[n_?okQ] := g[n]

f[n_] := f[n - 1] + n

So f[n] is the nth term in Recaman's sequence. This works but the 
output is quite slow on the computer I'm using (An Imac)
Can anyone suggest me a faster program? (maybe a non-iterative one?)

Cheers,

Santi Spadaro

-- 





More information about the SeqFan mailing list