Grasshopper

algorithmic modeling for Rhino

Say I have a list as follows:

{0}

1. CAT

2. DOG

3. TREE

and I want to get every possible combination that does not necessarily use all the indices.  Essentially I want a tree that would look like this:

{0}

1.CAT

2.DOG

3.TREE

{1}

1.CAT

2.DOG

{2}

1.CAT

{3}

1.DOG

2.TREE

{3}

1.DOG

{4}

1.TREE

{5}

1.CAT

2.TREE

Can cross reference be used to produce a tree like this?

Views: 4502

Replies to This Discussion

A simple/terse solution to this class of problem, might be to use the permutations function found in the standard itertools module in Python. Note that it might not scale super well with large input sets, due to the cost of outputting large amount of data from the GHPython component. Attached this example: 


Edit: Mohamed beat me to it :)

Attachments:

There is also something called Variation

repeating elements the same length as the places like this (c,c,c,b,b,b,c,c,c) give as result like (cat, cat, cat) or zero as an option

adding empty value to variations elements (" ", "a", "b", "c") give us values like (cat) or (cat, cat)

You can say I have all variations of (a,b,c) like a, ab, abc

but I guess when you use the word combination you say all possible unique combinations in two places ([][])out of 3  elements (a,b,c)

(ab = ba)

but for permutations, you say all possible permutations for two places ([][]) from a pool of 3 elements (a,b,c)

(ab != ba)

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