Created
May 21, 2016 23:23
-
-
Save Krailon/9534bcc3dcad89b0f8b55fbcdbd73e31 to your computer and use it in GitHub Desktop.
Binary Permutation Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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