Skip to content

Instantly share code, notes, and snippets.

@back-seat-driver
Created July 25, 2017 22:33
Show Gist options
  • Save back-seat-driver/51390fd7ebdb9bd29b03f40ac464bfce to your computer and use it in GitHub Desktop.
Save back-seat-driver/51390fd7ebdb9bd29b03f40ac464bfce to your computer and use it in GitHub Desktop.
Grey Code
def reverse(LIST):
to_return=[]
for i in range(1,len(LIST)+1):
to_return.append(LIST[-i])
return(to_return)
def initialized_set(n):
set_multiple = int(0.5*(2**n))
return([[0]]*set_multiple + [[1]]*set_multiple)
def list_zip(LIST_0,LIST_1):
to_return=[]
for i in range(len(LIST_0)):
insert = LIST_0[i] + LIST_1[i]
to_return.append(insert)
return(to_return)
def G_C(n):
i=1
initialized = [[0],[1]]
while i != n:
i+=1
zip_0 = list(initialized_set(i))
zip_1 = list(initialized) + list(reverse(initialized))
zip_3 = list(list_zip(zip_0,zip_1))
initialized = list(zip_3)
return(initialized)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment