laziness, impatience, and hubris | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Howdy all, I have a function that I use sometimes when I need permutations (I do permutation-testing often for stats problems). Currently I require the user to pass the "cardinality": how many different elements to put in each class. Let me give a simple example first, before I show the code:
I hope that's reasonably clear: cardinality defines the size of the group I wish to obtain permutations of. The first example above was: all possible pairs of groups of one element. The second example was: all possible pairs of groups of three elements (triplets). Within a single permutation, no element can be repeated, and I take only unique permutations. I am generating all these permutations into a data-structure for later use (e.g. passing them to other software, writing them to file with their results, sending them to a DB, etc.). The code that does this is pretty simple, but unfortunately it has required me to HARDCODE the cardinality. It looks like this:
And so on for higher cardinality. I would prefer to have a generalized way of doing this, rather than needing a separate set of for-loops for each cardinality. Is that possible? I'm turned it over in my head, and haven't found a way yet. In reply to Generalizing Code: Generating Unique Permutations by Anonymous Monk
|
|