Created
January 15, 2013 04:20
-
-
Save cammckinnon/4536013 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from itertools import combinations | |
# in is the number of dimensions of the cube (3 for a 3d cube) | |
def generate_vertices(n): | |
for number_of_ones in xrange(0, n + 1): | |
for location_of_ones in combinations(xrange(0,n), number_of_ones): | |
location_of_ones = set(location_of_ones) | |
yield [1 if i in location_of_ones else 0 for i in xrange(0, n) ] | |
for vertex in generate_vertices(3): | |
print vertex | |
# result: | |
# [0, 0, 0] | |
# [1, 0, 0] | |
# [0, 1, 0] | |
# [0, 0, 1] | |
# [1, 1, 0] | |
# [1, 0, 1] | |
# [0, 1, 1] | |
# [1, 1, 1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment