Hello everyone,
I would like to propose this kind of method
g = 1
z[1, 1] = [0, 0, 0, 0] #since this array has no 1s, then we can move to next
g = 2
z[2, 1] = [0, 0, 0, 1] #this array is generated first
#for the next step, the bit is moved to the next position
z[2, 2] = [0, 0, 1, 0]
z[2, 3] = [0, 1, 0, 0]
z[2, 4] = [1, 0, 0, 0] #for g = 1, we stop when bit hit this position
g = 3
z[3, 1] = [0, 0, 1, 1] #same as before, this array is generated
#then move the first left side of bit 1s
z[3, 2] = [0, 1, 0, 1]
z[3, 3] = [1, 0, 0, 1]
#after the first moved bit is hit the last position, we move the other bit
z[3, 4] = [1, 0, 1, 0]
z[3, 5] = [1, 1, 0, 0] #and here is the stopping condition for g = 2
g = 4
z[4, 1] = [0, 1, 1, 1] #this array also generated in the first step
z[4, 2] = [1, 0, 1, 1] #then move most left of bit 1s
z[4, 3] = [1, 1, 0, 1]
z[4, 4] = [1, 1, 1, 0] #and here we stop for g = 3
g = 5
z[5, 1] = [1, 1, 1, 1] #here the bit is generated and after that, we check the position. since there is no moving space then we will stop.
If there is any advice about this problem, please feel free to post it here.