Recaman sequence

Hello RH/GH comunity!

I’m a beginner in using Grasshopper and I have a question:
Is it possible to define the Recamán sequence using the Expression component? Or, more basic, how do you go about when you are dealing with recursive sequences in general. What is the proper syntax or method for such situations.

The sequence in question is described here:
https://oeis.org/A005132
https://en.wikipedia.org/wiki/Sequence (given as an example under the Defining a sequence by recursion section)

Thanks

Grasshopper has some support for making recursive sequences (with the Sequence component) but not if the sequence requires conditional logic or looping over the entire sequence. Then it requires custom programming. Python, C#, VB, …

1 Like

That is exactly what I was afraid of…
I was hoping that there would be a workaround using something like Anemone.

Anemone may well make it possible. I don’t know enough about how it works to say one way or another.

1 Like

Here’s some C# for it… recaman.gh (24.8 KB)

2 Likes

Here’s a Recamán’s Sequence GHPython script, I wrote a while back, inspired by this Numberphile video on YouTube. Apart from iteratively generating a sequence for a desired length, it also draws arc.

Feel free to check it out!

recaman_sequence.gh (7.5 KB)

2 Likes

Thank you so much, David! I really appreciate the time you took to help me out!
Much obliged

I can’t wait to get back home and give it a spin.

Thanks a lot! That exact same video sparked my interest regarding this particular sequence.
As I’m trying to learn GH I took it as a nice example to crack my head with.
Although doubtful, I’ll come back to this thread if I find a “pure” GH solution.

Cheers

1 Like