Skip to content

Instantly share code, notes, and snippets.

@pgblu
Last active December 17, 2018 19:11
Show Gist options
  • Save pgblu/966ba012c36c54dcd16824ca71eab4fb to your computer and use it in GitHub Desktop.
Save pgblu/966ba012c36c54dcd16824ca71eab4fb to your computer and use it in GitHub Desktop.
gray code viewer

Beckett-Gray sequences

viz. https://arxiv.org/pdf/1608.06001.pdf for a definition and discussion. The authors of the linked article were kind enough to provide me with the sequences.

0102013201043210434230321404323
0102013214023143402321340214310
0102013420302134021014302143412
0102013420302134021014303214341
0102013420302134024213432014302
0102031201043231041423214042030
0102031202143212404230140432310
0102031202401323404103240421234
0102031210403214043242143210321
0102031210431024043242143023121
0102031210431342143021240430212
0102031240313412143021240430124
0102031242034042120341243134042
0102031420302403201423013142430
0102031420302404123410143230141
0102031420313424131032410230421
0102031420323142430124032014230
0102031420324042103410142303141
0102034120234314231013401023410
0102034120301340102341023241343
0102103201043120341423130214340
0102103412032341423201432010431
0102131024310134142304324210304
0102131024310341432104324201034
0102131243121043210403243401023
0102131402313404203431204312104
0102131402313424032341023141023
0102131402313424032341432014132
0102131423101340102340320214340
0102131423201413201432304243132
0102301214301341423143402324143
0102301243010241430242341324042
0102301243034234120241430124042
0102301243034241320241040312404
0102301243034241323404213040142
0102301243230424310241041324042
0102301423032434120341014203141
0102304123010341203432414230141
0102312021340210134041023404310
0102312143021404130241430320413
0102314123204341203013401023040
0102314123204341203240320104312
0102314202340420134010213402320
0102340123240410234101431324013
0102341023240302123401234143032
0102341230340201342021404312040
0102341230340230142021034120402
0102341231204131204031340234031
0102341232104321014301240304212
0102341232104321014303214030423
0120103202403231420431231434023
0120103202432314340131420430131
0120103204301234014123430412301
0120131024313040234301243412103
0120131234121034210403243401203
0120131234321043420210342104013
0120131420313404203431203412103
0120132023410243413231402431321
0120132023430214341213402413123
0120132134013412043123204341320
0120132134312043420213402141323
0120132420343212043121434013123
0120304123031434231420230401234
0120310421304342134042034012430
0120312134021404132041430320414
0120314123431014320140420302414
0120314230340134021404132042141
0120341023240302124301214314103
0120341213431012430120240304213
0123012023040123404121342410321
0123012023043124043121042413021
0123012023410242142314043132010
0123012023410242143124043103021
0123012023410324041310421423201
0123012043014243121404321040341
0123012043024143212043412043042
0123012043032043412042141324042
0123012132141032414030243401230
0123012132141302414303204341203
0123012134021434021234142034142
0123012134321043421204142304142
0123012142314124021434023034142
0123012413430141320414202434010
0123012423414023141034102434102
0123012430134042134124201432421
0123012430243410234301413204143
0123012431424012134042134032421
0123012432414021243401234301412
0123012432414032141034012434012
0123012432414032141034321043421
0123014023134010234102421423120
0123014123424012134010230423021
0123014123424012134014324032421
0123014123430413120410320432031
0123014123430413120414234023431
0123040123134041323420230124201
0123040123134041324124201432024
0123040123243042314214102341014
0123041023134041314213202340103
0123041023134041320432023124203
0123041023243020142301412341310
0123041023243020143013143214103
0123041213034101324120324030413
0123041232043412034312314021341
0123041232142401324030413204101
0123041232404210304142130423120
0123041232412312034210304142130
0123041232432132403124140301243
0123401023134041324032021324201
0123401023134041324124201432021
0123401023134041324320234102423
0123401023240410234120132314313
0123401023240410234120132413414
0123401023243012321410234104313
0123401023243020143201412413142
0123401230324013242140412304101
01020132010432104342132340412304
01020312403024041232414013234013
01020314203024041234214103234103
01020314203240421034214130324103
01020341202343142320143201043104
01023412032403041230341012340124
01201321402314340232134021431041
01203041230314043210403202413241
beckett_file = './beckett_gray_sequences_5.txt'
beckett_sequences = File.readlines(beckett_file).map(&:chomp)
class BinaryCode
attr_accessor :current_value
def initialize(init_value)
@current_value = init_value.to_s.split('')
end
def flip_bit(position)
if @current_value[position] == '1'
@current_value[position] = '0'
else
@current_value[position] = '1'
end
nil
end
def display_value
current_value.join
end
end
def explode_sequence(initial_state, sequence)
result = []
bitswitchers = sequence.split(//)
bc = BinaryCode.new(initial_state)
result.push bc.display_value
bitswitchers.each do |switcher_value|
bc.flip_bit(switcher_value.to_i)
result.push bc.display_value
end
result
end
initial_config = ARGV[0] || '00000'
ARGV.clear
beckett_sequences.each do |sequence|
puts sequence.to_s
puts explode_sequence(initial_config, sequence)
gets
puts
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment