Skip to content

Instantly share code, notes, and snippets.

@louisswarren
Created November 18, 2019 11:10
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 louisswarren/9e3b9c0f796f1e4b6e0ab096837f1920 to your computer and use it in GitHub Desktop.
Save louisswarren/9e3b9c0f796f1e4b6e0ab096837f1920 to your computer and use it in GitHub Desktop.
Graph sequence thing
def run(G, n):
for _ in range(n):
i = len(G[0]) - 1
for j in range(len(G)):
s = 0
if 0 <= j - 1:
s += G[j - 1][i]
if j + 1 < len(G):
s += G[j + 1][i]
G[j] += (s, )
return ((x for x in seq if x != 0) for seq in G)
def output(k, n):
G = [(1,)] + [(0,)] * (k - 1)
for seq in run(G, n):
print(', '.join(map(str, seq)))
output(5, 20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment