ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 13 Jun 2013 11:57:57 +0200Generating permutations of coefficientshttps://ask.sagemath.org/question/10229/generating-permutations-of-coefficients/I have created the following function to return all pairs `(n, k)` such that a slightly altered binomial coefficient is less than or equal to a certain `N`:
bin = lambda n, k : binomial(n + k - 1, k)
def nkfilter(N):
pairs = []
for n in range(2, N+1):
for k in range(1, n):
if bin(n, k) <= N:
pairs.append([n, k])
print '\n (n, k)\n'
return pairs
This prints out the following:
example = nkfilter(8); print example
(n, k)
[[2, 1], [3, 1], [3, 2], [4, 1], [5, 1], [6, 1], [7, 1], [8, 1]]
I now would like to take this `n` and generate a tuple of length `n`: `(a_1,..., a_n)`, for which all the `a_i`s are less than or equal to `k`. I have been considering `permutations` to accomplish this, but I believe I need to first generate `list_of_numbers_less_than_k` and then take `permutations(n, list_of_numbers)`.
However I am not sure which data types to use, and how to generate these `n`-length tuples. JoshIzzardThu, 13 Jun 2013 11:57:57 +0200https://ask.sagemath.org/question/10229/