Created
July 28, 2011 07:17
-
-
Save alexbowe/1111139 to your computer and use it in GitHub Desktop.
Ranks k-composites that sum to n
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
def gam_to_lam(c, n): | |
i, m = 0, 0 | |
L = [0] * n | |
while 1: | |
i = i+1 | |
if c[i-1] > 0: | |
for j in range(1, c[i-1] + 1): | |
m = m + 1 | |
L[m-1] = i | |
if m == n: return L | |
def lam_to_k(L, n): | |
K = [0] * n | |
for i in range(0, n): | |
K[i] = L[i] + i | |
return K | |
def rank_combination(a, k, n): | |
r = 0 | |
for j in range(1, k+1): | |
r += binomial(n - a[j-1], k - j + 1) | |
return r | |
def rank_class(a, k, n): | |
c = gam_to_lam(a, n) | |
c = lam_to_k(c, n) | |
r = rank_combination(c, n, n+k-1) | |
return r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment