gray-code

0.0.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i gray-code

Weekly Downloads

10

Version

0.0.0

License

MIT

Last publish

Collaborators

  • nopersonsmodules