Skip to content

Instantly share code, notes, and snippets.

@Krailon
Created May 21, 2016 23:23
Show Gist options
  • Save Krailon/9534bcc3dcad89b0f8b55fbcdbd73e31 to your computer and use it in GitHub Desktop.
Save Krailon/9534bcc3dcad89b0f8b55fbcdbd73e31 to your computer and use it in GitHub Desktop.
Binary Permutation Generator
def gen_bins(bit_count):
bins = []
indx = 0
bin = [0] * bit_count
while bin != [1] * bit_count:
while bin[indx]:
indx += 1
del bin[indx]
bin.insert(indx, 1)
if indx > 0:
bin = ([0] * indx) + bin[indx:]
indx = 0
bins.append(bin.copy())
return bins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment