let’s assume i have the following logical matrix:
log = [1 1 0;
0 1 1;
1 0 1;
0 0 1];
the columns describe something like a basket and the single rows describe some objects identified by a certain attribute (e.g. balls of different colors) you could put into those baskets. 1 means, you can put it in (into the basket described by the column), 0 you can’t.
Each basket can only contain ONE object at once.
I’m wondering how to compute the permutations on how to put in objects for a given configurations, that means I say: I want to have objects in basket 1 and 3 but none in basket 2, which would be [1 0 1]:
So I have the following possibilities:
- basket 2: 0 items
- basket 1: can contain either object 1 or obj. 3
- basket 3: can contain either object 2, obj. 3 or obj. 4
so all in all, I have the complete permutations (one line describes one permutation, the column describe the baskets and the number describes the object):
1 0 2
1 0 3
1 0 4
2 0 2
2 0 3
2 0 4
how to make this into a nice algorithm, which adapts to arbitrary number of baskets and objects? i can only think of nested and ugly looping 🙁
thanks a lot!
I would make it recursively:
gives the output you describe: