November: Procrastination Month
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

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

Keywords

none

install

npm i gray-code

Downloadsweekly downloads

3

version

0.0.0

license

none

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar