Last active
May 16, 2016 13:24
-
-
Save armanbilge/48f71b2bec824eb285f2c0effd4598d8 to your computer and use it in GitHub Desktop.
This file contains 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
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