,
my “constraint” is that for all the results of the possible permutations I need 50 % of x and 50 % of Y.
All the boxes in the grid must be filled by x or y.

I would like also to have 2 colors instead of the “X” and the “Y”, could you help me to write the good definition ?

Thank you very much, I was more looking for a grasshopper definition eheh, but thank you for the idea… I will try to find an application with grasshopper rhino

Thank you very much for your grasshopper approach its much more explicit to me (sorry not a great mathematic background!), In fact I’m looking for all the possible permutation of X and Y (with 50 perrcent of X and 50 percent of Y) In grids like this… I would like to know how many combinaisons are possible…

Theophile, I don’t mean to be rude, but that’s literally what both Nathan and me already showed you.
You probably should have taken a closer look and experimented a little yourself, since that’s really what learning is about.

Ok sorry about that, It seems that I have not enough maths/grasshopper skills to use your definition in this case ^^ sorry about that !
I don’t need all the possible permutations between XY I would like only the permutations with 50% of X and 50% of Y in the same grid… I’m sorry if I’m not so clear :S like in the following drawing…
There are less more possible permutations in this case…

ghenv.Component.Name = "Pythonic Cartesian Product"
ghenv.Component.NickName = "CProd"
from ghpythonlib import treehelpers
import itertools
def satisfy_50(I,l):
s = "".join(l)
c = s.count(I[0])
if c == 0:
return False
return (len(s) / c) == 2
if __name__ == "__main__":
product_one = ["".join(p) for p in itertools.product(I, repeat=2)]
all_permutations = [list(p) for p in itertools.product(product_one, repeat=R)]
permutations = [p for p in all_permutations if satisfy_50(I, p)]
P = treehelpers.list_to_tree(permutations)
AP = treehelpers.list_to_tree(all_permutations)

Do you have any idea of the best way to transpose visually this approach ?
I mean the best would be to have instead of the X and the Y some colors or pictures in tables (like in my following drawing in the piece attachee) how would you proceed to achieve that ?

I think I missed something or maybe there is a mistake in your permutation script, @nathanletwory, because for example I can’t find the following permutations (see attachee) in the results that is given by your pythonic cartesian product… It would means that there are not all the possible permutations between X and Y (with the constraint of 50% of X and 50% of Y) with this approach of the cartesian product !?