gray-code

n-ary gray codes of radix k

npm install gray-code
2 downloads in the last week
14 downloads in the last month

gray-code

n-ary gray codes of radix k

browser support

build status

example

$ node
> var gray = require('gray-code')
> gray(2)
[ [ 0, 0 ],
  [ 0, 1 ],
  [ 1, 1 ],
  [ 1, 0 ] ]
> gray(3)
[ [ 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(2, 3)
[ [ 0, 0 ],
  [ 0, 1 ],
  [ 0, 2 ],
  [ 1, 2 ],
  [ 1, 0 ],
  [ 1, 1 ],
  [ 2, 1 ],
  [ 2, 2 ],
  [ 2, 0 ] ]
> gray(3, 3)
[ [ 0, 0, 0 ],
  [ 0, 0, 1 ],
  [ 0, 0, 2 ],
  [ 0, 1, 2 ],
  [ 0, 1, 0 ],
  [ 0, 1, 1 ],
  [ 0, 2, 1 ],
  [ 0, 2, 2 ],
  [ 0, 2, 0 ],
  [ 1, 2, 0 ],
  [ 1, 2, 1 ],
  [ 1, 2, 2 ],
  [ 1, 0, 2 ],
  [ 1, 0, 0 ],
  [ 1, 0, 1 ],
  [ 1, 1, 1 ],
  [ 1, 1, 2 ],
  [ 1, 1, 0 ],
  [ 2, 1, 0 ],
  [ 2, 1, 1 ],
  [ 2, 1, 2 ],
  [ 2, 2, 2 ],
  [ 2, 2, 0 ],
  [ 2, 2, 1 ],
  [ 2, 0, 1 ],
  [ 2, 0, 2 ],
  [ 2, 0, 0 ] ]

methods

var gray = require('gray-code')

gray(n, k=2)

Return the n-ary gray code for n digits in radix k.

The default radix is binary (k = 2).

install

With npm do:

npm install gray-code

license

MIT

npm loves you