< Back to IRCAM Forum

All combinations of n elemts of a list

Hi!
What would be an elegant way to get all combinations of n elements of a list? As a simple example: all combinations of two elements out of the list (1 2 3) should return ((1 1) (1 2) (1 3) (2 1) (2 2) (2 3) (3 1) (3 2) (3 3)). That’s pretty simple, but I’m struggling with all combinations of four elements out of list of fourteen items.
Thanks,
Catrin

hello catrin,

look for the combination function in the Combine library by Mikhail Malt. it does what you’re looking for. (it’s in the Permut submenu).
hope this helps,
perti

Thank you very much, perti!

Hi Catrin,

Since this will result in enourmous combinations, you can also try to use the 03-all permutaions patch in the OMCS library and using a partial search. This library is based on constraint rules limiting some solutions, as repetitions.

Best
K

Hi Karim,

thanks for pointing me to the omcs library, looks like a very powerful tool.

Best
Catrin