I have two types of objects: M and N, identifiable by a name.Additionally, multiple Ms can be grouped into one or more M-Group (also identifiable by a name), same for Ns. (If it makes your life easier, you can assume that nesting is not allowed, however nesting would be nice.)A Rule consists of multiple Ms and multiple Ns. If I have a list of Ms = [M(1), M(2), M(3)] and a list of Ns = [N(A), N(B), N(C)], I need to generate a list of rules that looks like this:M=1, N=AM=2, N=AM=3, N=AM=1, N=BM=2, N=BM=3, N=BM=1, N=CM=2, N=CM=3, N=CAs multiple Ms can be grouped into M-groups, assuming that our Ms list is condensed into a M-Group called MG1, then my list of text would look like this:MG=MG1, N=AMG=MG1, N=BMG=MG1, N=CIf we group Ns in a similar way (NG1), then my list of rules would look like this:MG=MG1, NG=NG1Obviously this can be done pretty easily with two layers of for loops, but the added complexity of the user choosing to output the rules with groups instead of individual Ms and Ns means that I would need to check whether the user is using a group, therefore I would need to write 4 if blocks (one for M-Group -> N, one for M -> N-Group, one for both, and one for neither). If we add another dimension O, then I would need 16 if blocks to cater for all solutions, etc.Is there is a solution that will allow me to generate this list without writing 2^n if blocks (where n is the dimension in the array)?(To those wondering: Yes, this is in the context of generating firewall access rules)
Laying out all the relations in an n-dimensional array
algorithms