Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Find the index of a subset in Gray code order
ResourceFunction["GrayCodeSubsetIndex"][list,s] gives the zero-based index of the subset s in the Gray code ordering of the subsets of list. |
The index of a subset in Gray code order:
In[1]:= | ![]() |
Out[1]= | ![]() |
Define a List:
In[2]:= | ![]() |
Use the resource function GrayCodeSubsets to get the subsets of the List in Gray code order:
In[3]:= | ![]() |
Out[3]= | ![]() |
Use GrayCodeSubsetIndex to find the index of each subset:
In[4]:= | ![]() |
Out[4]= | ![]() |
Positions are offset by one:
In[5]:= | ![]() |
Out[5]= | ![]() |
Get the subsets in Gray code order sequentially using the resource function NthGrayCodeSubset:
In[6]:= | ![]() |
Out[6]= | ![]() |
Their respective indices:
In[7]:= | ![]() |
Out[7]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License