Grasshopper

algorithmic modeling for Rhino

I'm trying to construct a Hofstadter Sequence of Any Number

the Equation for the Sequence are :

G(n) = n-G(G(n-1)), n>0

i need some help with that cuz i dont know how to implement it Through the component Funtion or the component expresion.

the goal for this its construct a Series like this

0 1 1 2 2 3 3 4

Views: 863

### Replies to This Discussion

The sequence formula

G(n) = n - G(G(n-1))

is not a formula that can be written in a Grasshopper Expression. You'll need some form of recursion or looping which in turn means you'll need a script component for this.

You'll also have to decide whether you want to just find a single number in the sequence (which will probably involve recursion and delegates) or whether you want to create the first N numbers of the sequence.

Attached is a sequence generator written in VB.

--

David Rutten

david@mcneel.com

Attachments:

If you can't open the file, here's a screenshot:

--

David Rutten

david@mcneel.com

If you must use a GH Expression, this is the closest I could get:

--

David Rutten

david@mcneel.com

It's Weird the VB sequence have an error i dont know if the Expression its wrong but

the Sequence have to be

0 1 1 2 2 3 3 4 4 5 5 6 6......

And

the Result of the script its

0 1 1 2 3 3 4 4 5 6 6 6.......

the Number 2 and number 5 have to be twice in the Sequence and only appear just one time

weird behavior

--

David Rutten

david@mcneel.com

My mistake i'm wrong what i want to do its not Hofstadter Sequence.

its Pair Sequence more simple

:D

Try the duplicate component.

--

David Rutten

david@mcneel.com

Or alternatively if you are using a c# or similar component you could use the following function to create the number sequence you need:

int numberFrequency = 2;

int myList = {};
for (int i = 0; i < 10; ++i)
{
myList[i] = Ceiling(i / numberFrequency);
}

Notice that by changing the numberFrequency controls the number of repeating integers for a given sequence.

In case he wants the code to work:

int numberFrequency = 2;

int[] myList = new int[10];

for (int i = 0; i < 10; ++i)

{

myList[i] = (i + numberFrequency - 1) / numberFrequency;

}

A = myList;

If you prefer using Math.Ceiling replace the longest line with:

myList[i] = (int) Math.Ceiling((double) i / numberFrequency);

But the duplicate component is faster and easier...

Yes, my post (i thought) was quite obviously not presented in a format which was intended to be useable, but rather used to convey a simple/useful concept for repetitive number sequencing for future reference (i.e. not necessarily within the confines of GH). But thanks for idiot-proofing nonetheless.

• View All