Skip to content

Generate the sequence of changing positions in a Gray code

License

Notifications You must be signed in to change notification settings

BenjaminRemez/GrayCodePosition.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GrayCodePosition

Lightweight package for Gray codes and their transient index sequences.

Stable Dev Build Status Coverage

Usage

Gray codes can be easily generated.

using GrayCodePosition
code = GrayCode(3) # Gray code (collection of all codewords) over 3 bits
for c in code println(bitstring(c)[end-2:end]) end
#= 
000
001
011
010
110
111
101
100
=#

Note the position of the bit changing between two successive codewords: 1, 2, 1, 3, 1, 2, and finally 1. These positions are called the transient indices. They can be generated and iterated as follows

using GrayCodePosition
code = GrayCode(3)
gcp = GrayCodePositions(code) # Equivalently, gcp = diff(code)
collect(gcp)'
# 1×7 adjoint(::Vector{Int64}) with eltype Int64:
# 1  2  1  3  1  2  1

About

Generate the sequence of changing positions in a Gray code

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages