Skip to content

Instantly share code, notes, and snippets.

@Scinawa
Created March 24, 2016 05:23
Show Gist options
  • Save Scinawa/c54d11ec4b8d28c3bd10 to your computer and use it in GitHub Desktop.
Save Scinawa/c54d11ec4b8d28c3bd10 to your computer and use it in GitHub Desktop.
Stirling number of the first kind
@memo # can be memoized, otherwise comment this line
def stirling1(n,k):
"""Returns the stirling number of the first kind using recursion.."""
if n == 0 and k == 0:
return 1
if k == 0 and n >= 1:
return 0
if k > n:
return 0
return stirling1(n-1, k-1) - (n - 1) * stirling1(n-1, k)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment