Grasshopper

algorithmic modeling for Rhino

List operation 0,1 ; 1,2 ; 2,3 ; 3,4 ;........

Hey guys, 
i have a list of numbers 0,1,2,3,4,5,6,7,8,...

i want them to be split into lists as followed:

0,1 ; 1,2 ; 2,3 ; 3,4 ; 3,5 ;....

how would i do this?

thanks

Views: 2837

Replies to This Discussion

Here's a simple way...shift, shortest list, graft + merge

Sheesh!  Can you (or anyone) please explain why 'Shortest List' is necessary here?

I had the series, shift and merge but no luck without 'Shortest List' - this stuff is SO HARD!!!

Attachments:

Here, because the original list and shifted lists are of unequal length, you use use "shortest list" to truncate the end of the longer one. But here it's also doing one other thing that's a bit trickier. One thing that the shift lists component does is it adds a new layer of data structure to your original list. So your original list is {0;0}, say, and after shift it appends a new one {0;0;0}. David has a post floating around that explains all conditions where this occurs. If you feed both the original list and the shifted list in "shortest list" it identifies that you're giving it two individual lists, and cleans up the data structure between the two such that they match. (Here it also does the nice bit of ensuring that you will always have two values in each grafted branch).

If you just graft and merge the outputs from the original list and the shifted list, then you end up with two distinct data structures: {0;0;x} and {0;0;0;x}. It can be annoying (and there are no shortage of people who are highly critical of the data tree as a means to manage nested lists), but it is at least always internally consistent. In this case, you can carefully use simplify to get rid of those extra lead-in zeros:

You'll notice that last bucket only has one value in it though...that's that other thing that using shortest list takes care of. Hope this helps!

Hi maxk, this is another way (which might be easier to understand):

That is simpler, which is good, but I would never have guessed the effect "-1" has of effectively removing the last item in that list...  Far from obvious.

Here is one more way, using 'Sub List (SubSet)', that makes more sense to me - no idea about relative performance.

One domain is constructed as '0 to Length-2' (A=0, B=x-2), the other as '1 to Length-1' (A=1, B=x-1):

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