Created
May 13, 2011 01:58
-
-
Save shoke/969840 to your computer and use it in GitHub Desktop.
Hexagon/Armchair Lines
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
import networkx as nx | |
import sys | |
g = nx.Graph() | |
for i in range(6): | |
g.add_node(i+1) | |
if (i+1) > 1: | |
g.add_edge(i+1,i) | |
g.add_edge(6,1) | |
numNodes = 6 | |
rows = 1 | |
if len(sys.argv) > 1: | |
if sys.argv[1].isdigit(): | |
rows = int(sys.argv[1]) | |
evenRow = True | |
left = 2 | |
right = 4 | |
if rows > 1: | |
for j in range(rows-1): | |
if evenRow: | |
l = left | |
r = right | |
for addnodes in range(4): | |
g.add_node(numNodes+1) | |
g.add_edge(l, numNodes+1) | |
l = numNodes + 1 | |
numNodes += 1 | |
g.add_edge(numNodes, left + 1) | |
for addnodes in range(3): | |
g.add_node(numNodes+1) | |
g.add_edge(r, numNodes+1) | |
r = numNodes + 1 | |
numNodes += 1 | |
g.add_edge(l, r) | |
evenRow = False | |
right = r | |
left = r - 4 | |
else: | |
l = left | |
r = right | |
for addnodes in range(3): | |
g.add_node(numNodes+1) | |
g.add_edge(l, numNodes+1) | |
l = numNodes + 1 | |
numNodes += 1 | |
g.add_edge(numNodes, r) | |
evenRow = True | |
right = numNodes | |
left = numNodes - 2 | |
print g.nodes() | |
print g.edges() | |
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
import networkx as nx | |
import sys | |
g = nx.Graph() | |
for i in range(6): | |
g.add_node(i+1) | |
if (i+1) > 1: | |
g.add_edge(i+1,i) | |
g.add_edge(6,1) | |
numNodes = 6 | |
rows = 1 | |
columns = 1 | |
if len(sys.argv) > 1: | |
if sys.argv[1].isdigit(): | |
rows = int(sys.argv[1]) | |
if len(sys.argv) > 2: | |
if sys.argv[2].isdigit(): | |
columns = int(sys.argv[2]) | |
start = 4 | |
end = 5 | |
if rows > 1: | |
for j in range(rows-1): | |
s = start | |
for addnodes in range(4): | |
g.add_node(numNodes+1) | |
g.add_edge(s, numNodes+1) | |
s = numNodes + 1 | |
numNodes += 1 | |
g.add_edge(numNodes, end) | |
start += 4 | |
end += 4 | |
print g.nodes() | |
print g.edges() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment