Function Repository Resource:

NextGrayCodeSubset

Source Notebook

Get the successor of a given subset in Gray code order

Contributed by: Igor Bakshee, after Sriram V. Pemmaraju and Steven S. Skiena

ResourceFunction["NextGrayCodeSubset"][l,s]

gives the successor of s in the list of Gray code subsets of set l.

Examples

Basic Examples (1) 

In a Gray code, each subset differs by the insertion or deletion of exactly one element:

In[1]:=
ResourceFunction["NextGrayCodeSubset"][{a, b, c, d}, {a, b, c}]
Out[1]=
In[2]:=
ResourceFunction["NextGrayCodeSubset"][{a, b, c, d}, %]
Out[2]=

Properties and Relations (1) 

NextGrayCodeSubset[l,s] gives the successor to s in the list returned by the resource function GrayCodeSubsets:

In[3]:=
list = {a, b, c, d};
In[4]:=
NestList[ResourceFunction["NextGrayCodeSubset"][list, #] &, {}, 15]
Out[4]=
In[5]:=
ResourceFunction["GrayCodeSubsets"][list]
Out[5]=
In[6]:=
% === %%
Out[6]=

Version History

  • 1.0.0 – 06 March 2020

Related Resources

License Information