Skip to content

Instantly share code, notes, and snippets.

@rmurphy2718
Last active June 10, 2019 20:01
Show Gist options
  • Save rmurphy2718/2fa0a59af158aa8d75333dc9fddc9ecc to your computer and use it in GitHub Desktop.
Save rmurphy2718/2fa0a59af158aa8d75333dc9fddc9ecc to your computer and use it in GitHub Desktop.
All binary lists of size NN
##########################################
# 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