Last active
June 10, 2019 20:01
-
-
Save rmurphy2718/2fa0a59af158aa8d75333dc9fddc9ecc to your computer and use it in GitHub Desktop.
All binary lists of size NN
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
########################################## | |
# Ryan Murphy | |
# Create all binary lists of length N | |
# E.g.: [[0, 0], [0, 1], [1, 0], [1, 1]] | |
########################################## | |
def all_binary_lists(num): | |
superset = [] | |
def f(starter): | |
if len(starter) > (num-1): | |
superset.append(starter) | |
return | |
f(starter + [0]) | |
f(starter + [1]) | |
f([]) | |
return superset | |
if __name__ == "__main__": | |
nn = 6 | |
result = all_binary_lists(nn) | |
print("Expected: {}, Actual: {}".format(len(result), 2**nn)) | |
for res in result: | |
print(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment