Function Repository Resource:

GrayCodeSubsets

Source Notebook

Get subsets of a given set in minimum change order

Contributed by: Sriram V. Pemmaraju and Steven S. Skiena, submitted by Wolfram staff

ResourceFunction["GrayCodeSubsets"][l]

gives a binary reflected Gray code on set l.

Details and Options

Gray code order is a minimum change order.
ResourceFunction["GrayCodeSubsets"] returns a list in which adjacent subsets differ by the insertion or deletion of exactly one element.

Examples

Basic Examples (1) 

In a Gray code, each subset differs in exactly one element from its neighbors:

In[1]:=
ResourceFunction["GrayCodeSubsets"][{1, 2, 3}]
Out[1]=

Version History

  • 1.0.0 – 06 March 2020

Related Resources

License Information