Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Get the subset of a list for a given index
ResourceFunction["NthSubset"][n,list] gives the nth subset of list in canonical order. |
The first 16 subsets of a list:
In[1]:= |
Out[1]= |
NthSubset does not sort its input, so the ordering of subsets is based on positions in the original list:
In[2]:= |
Out[2]= |
The 69,381st subset returned by Subsets:
In[3]:= |
Out[3]= |
Or by the zero-indexed NthSubset:
In[4]:= |
Out[4]= |
The ordering of subsets is based on length (smaller subsets come first), followed by lexicographic list positions. This is not the fastest ordering for computing subsets:
In[5]:= |
Out[5]= |
A faster enumeration can be attained if one imposes only lexicographic position ordering:
In[6]:= |
In[7]:= |
Out[7]= |
Check that these have the same subsets:
In[8]:= |
Out[8]= |
This work is licensed under a Creative Commons Attribution 4.0 International License