Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Generate all possible orderless lists of a given length with a given set of elements
ResourceFunction["OrderlessCombinations"][list,n] gives all possible orderless sets comprised of the elements of list up to length n. | |
ResourceFunction["OrderlessCombinations"][list,{n}] gives sets of exactly length n. | |
ResourceFunction["OrderlessCombinations"][list,{n,m}] gives sets containing between n and m elements. |
There are nine possible orderless sets of up to two elements chosen from three possible elements:
In[1]:= |
Out[1]= |
There are six possible orderless sets of exactly two elements chosen from three possible elements:
In[2]:= |
Out[2]= |
Get length four sets from a list of length two:
In[3]:= |
Out[3]= |
Elements need not be integers:
In[4]:= |
Out[4]= |
A company makes three different heating units. The customer needs a row of five heating units for a large room. How many different purchase combinations are available to the customer:
In[5]:= |
Out[5]= |
The same sets can be generated by sorting and deduplicating the output of Tuples, but OrderlessCombinations is faster, and uses much less memory for larger problems:
In[6]:= |
Out[6]= |
In[7]:= |
Out[7]= |
This work is licensed under a Creative Commons Attribution 4.0 International License