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
Tags:
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
Poprad, Slovakia
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
http://en.wikipedia.org/wiki/Hofstadter_sequence#Hofstadter_G_sequence
--
David Rutten
david@mcneel.com
Poprad, Slovakia
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
Poprad, Slovakia
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.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by