Skip to content

Instantly share code, notes, and snippets.

@sbeyer
Last active April 3, 2016 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbeyer/bb2731d4113d3da62dd8b44c262e9fc1 to your computer and use it in GitHub Desktop.
Save sbeyer/bb2731d4113d3da62dd8b44c262e9fc1 to your computer and use it in GitHub Desktop.
Generate-and-count code for OEIS A271205 using NetworkX
#!/usr/bin/env python3
import networkx as nx
def populate(table, n):
treelist = nx.generators.nonisomorphic_trees(n)
for tree in treelist:
degrees = list(nx.degree(tree).values())
if 2 not in degrees:
l = degrees.count(1)
if (l, n) not in table:
table[(l, n)] = 0
table[(l, n)] += 1
def output_line(table, l):
print("l = %u: " % l, end='')
for n in range(l+1, 2*l - 1):
print("%u, " % table[(l, n)], end='')
del table[(l, n)]
print()
table = {}
n = 4
while True:
populate(table, n)
if n % 2 == 0:
output_line(table, n//2 + 1)
n += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment