Question: I've been looking into combinations lately, I've tried various 3rd party solutions, and tried to get my head around it myself. Without success I might add.

I need to generate a 13 length string with all possible combinations of say.. int 0-2, I.E

```
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 2
0 0 0 0 0 0 0 0 0 0 0 1 0
... 
2 2 2 2 2 2 2 2 2 2 2 2 2

```

You probably get the drill, I'm aware I could just wrap this up in loops if I wanted a dirty solution. Any guidance or pointers are appreciated.

Answer: 
I'd be happy to write the code for you, but it seems like you are looking for intuition into the problem. So maybe this feels more like a "teach a man to fish" moment.

So let me ask you a few questions:

Let's generalize the problem to strings of length N. What does the N=1 case look like? It's

```
0
1
2

```

And what does the N=2 case look like? It's

```
00
01
02
10
11
12
20
21
22

```

I wonder if you can see how, given the N=1 case, we can easily derive (aka generate) the N=2 case in a very mechanical fashion. Now if you see the pattern for this specific case, can you say what the pattern is for the general case? i.e. If you happened to already have in your hand the answer for strings of length N, and I asked you to provide me with the answer for strings of length N+1 could you do so? If so you have the very definition of a recursive algorithm.

PS I think I'd call these combinations rather than permutations.
I've written quickly function that returns list of permutations, so if you have not time to write your own method, you can use it. length is permutation length, max is maximum number (in your case, it would be 2)

```
    static List<int[]> getPermutationList(int length, int max)
    {
        List<int[]> perm_list = new List<int[]>();
        int[] perm = new int[length];
        for (int i = 0; i < length; ++i)
            perm[i] = 0;
        while(true)
        {
            for (int i = length - 1; ; --i)
            {
                if (i == -1)
                    return perm_list;
                if (perm[i] < max)
                {
                    perm[i]++;
                    for (int j = i + 1; j < length; ++j)
                        perm[j] = 0;
                    break;
                }

            }
            int[] perm_copy = new int[length];

            for (int i = 0; i < length; ++i)
            {
                perm_copy[i] = perm[i];
            }
            perm_list.Add(perm_copy);
        }
        return perm_list;
    }

```