Skip to content

Instantly share code, notes, and snippets.

@armanbilge
Last active May 16, 2016 13:24
Show Gist options
  • Save armanbilge/48f71b2bec824eb285f2c0effd4598d8 to your computer and use it in GitHub Desktop.
Save armanbilge/48f71b2bec824eb285f2c0effd4598d8 to your computer and use it in GitHub Desktop.
from functools import lru_cache
import itertools as it
from scipy.misc import comb
@lru_cache(None)
def f(k, n):
if k == 0:
return 0
return k ** n - sum(int(comb(k, i)) * f(i, n) for i in range(k))
def g(k, n):
return sum(1 for x in it.product(range(k), repeat=n) if len(set(x)) == k)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment