Last active
April 3, 2016 12:41
-
-
Save sbeyer/bb2731d4113d3da62dd8b44c262e9fc1 to your computer and use it in GitHub Desktop.
Generate-and-count code for OEIS A271205 using NetworkX
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
#!/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