mutwo.generators.gray

Algorithms which are related to US-American researcher Frank Gray.

Functions:

reflected_binary_code(length, modulus)

Make gray code where each tuple has length items with modulus different numbers.

reflected_binary_code(length, modulus)[source]

Make gray code where each tuple has length items with modulus different numbers.

Parameters
  • length (int) – how long one code is

  • modulus (int) – how many different numbers are included

Return type

Tuple[Tuple[int, …], …]

Example:

>>> from mutwo.generators import gray
>>> gray.reflected_binary_code(2, 2)
((0, 0), (0, 1), (1, 1), (1, 0))
>>> gray.reflected_binary_code(3, 2)
((0, 0, 0),
(0, 0, 1),
(0, 1, 1),
(0, 1, 0),
(1, 1, 0),
(1, 1, 1),
(1, 0, 1),
(1, 0, 0))
>>> gray.reflected_binary_code(2, 3)
((0, 0), (0, 1), (0, 2), (1, 2), (1, 1), (1, 0), (2, 0), (2, 1), (2, 2))
Basic code has been copied from:

https://yetalengthothermodulusathblog.com/tag/gray-codes/