Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

My initial problem was solved here. It is about enumerating all n-tuples of a permutation in a specific order.

The solution algorithm is very simple and I'm sure has been used before. However, I did not find any scientific references. Do you know it, or do you know how to search for it better?

The code itself:

def seq(n, k):
    if (k == 0):
        yield ()
        return

    for i in range(n+1):
        for subseq in seq(i, k-1):
            for j in range(k):
                yield subseq[:j] + (i,) + subseq[j:]
                if j != k-1 and subseq[j] == i:
                    break

Output for n=4, k=2:

00
10 01 11
20 02 21 12 22
30 03 31 13 32 23 33
40 04 41 14 42 24 43 34 44
share|improve this question
    
I'm not sure if this is on topic here, if not, please redirect me :) –  mafutrct Sep 12 '12 at 12:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.