require 'lib/codon_mod'
module Mapper
class CodonGray < CodonMod
def initialize( bits=8 )
super
self.bit_size = bits
end
def bit_size= bit_size
super
x = ['0','1']
(bit_size-1).times do
y = (x.map { |i| '0'+i }).concat( x.reverse.map { |i| '1'+i } )
x=y
end
@gray = x.map { |i| i.to_i(2) }
@reverse = []
@gray.each_with_index { |g,i| @reverse[g] = i }
end
def interpret( numof_choices, codon, dummy=nil )
super( numof_choices, @reverse[codon] )
end
def generate( numof_choices, index, dummy=nil )
@gray[super]
end
def raw_read codon
@reverse[codon]
end
end
end