gray-code
v0.0.0
Published
n-ary gray codes of radix k
Downloads
6
Readme
gray-code
n
-ary gray codes of radix k
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