Skip to content

Instantly share code, notes, and snippets.

@veiset
Last active August 29, 2015 14:11
Show Gist options
  • Save veiset/6daeebb1c37ac36f8d6b to your computer and use it in GitHub Desktop.
Save veiset/6daeebb1c37ac36f8d6b to your computer and use it in GitHub Desktop.
G = {0:[4, 6], 1:[6, 8], 2:[7, 9], 3:[4, 8], 4:[3, 9, 0], 5:[], 6:[1, 7, 0], 7:[2, 6], 8:[1, 3], 9:[2, 4]}
def walk(graph, node, d=1, m=10):
return 1 if d == m else sum([walk(graph, n, d+1, m) for n in graph[node]])
print walk(G, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment