Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Get the n-th Gray code subset of a list
ResourceFunction["NthGrayCodeSubset"][n,list] gives the nth subset of list, listed in Gray code order. |
In Gray code order, subsets differ from their neighbors by by the insertion or deletion of exactly one element:
| In[2]:= |
| Out[2]= |
Sequentially reconstruct the subset list with NthGrayCodeSubset:
| In[3]:= |
| Out[3]= |
| In[4]:= |
| Out[4]= |
The resource function GrayCodeSubsetIndex gives back the index n of the subset constructed with NthGrayCodeSubset:
| In[5]:= |
| In[6]:= |
| In[7]:= |
| Out[7]= |
| In[8]:= |
| Out[8]= |
This work is licensed under a Creative Commons Attribution 4.0 International License