Grasshopper

algorithmic modeling for Rhino

How can i create a series like (a,(a+b),(a+b+c),(a+b+c+d)).
if i have a list of no. like a,b,c,d.
 

Views: 2529

Replies to This Discussion

Hello Yousuf,

You can use nested for-loops to do this. For example, inserting the following code snippet in the C# script component will do the trick! If you need any help in understanding the code, let me know.

for (int i = 0; i < givenSet.Length; i++)
{
      resultingSet[i] = 0;

      for (int j = 0; j <= i; j++)
      {
            resultingSet[i] += givenSet[j];
      }
}

Cheers,

Sridevi

Since list "a b c d e f g..." can be replaced with any list, you can add numbers with mass addition component.

 

The Mass addition Component has a partial results output which will achieve the results you want.

Hahaha... such a simple solution! Too bad I cannot "up-vote" your answer like on http://stackoverflow.com

Thank you all very much for suggesting me with different methods!!
But the one Danny  Suggested was so much easier and it is working perfectly!!!
Thank you all once again.:) 

Attachments:

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service