Counting permutations

I want to calculate permutation of numbd-ers for example 4 is 1 + 1 + 1 + 1 and
1 + 2 + 1 and 1 + 1 + 2 and 2 + 1 + 1 and 3 + 1 and 1 + 3 so 6 different permutations for 4.How to calculate it with recusion please give some clue or advice
ooh this is tough on my head ...

let me think about it a few and i'll get back to ya if I can think it through...
Start with how you came up with that list. How can you systematically generate a list like that and know that it is complete? Do it manually first, and record what you do, step by step.

Determine what you are actually recursing over.

1 1 1 1 (1)
1 1 1 1 1 <doesn't work>
1 1 1 2 <doesn't work>
1 1 2 (2)
1 2 1 (3)
2 1 1 (4)
2 1 2 <doesn't work>
1 1 3 <doesn't work>
1 3 (5)
3 1 (6)
2 1 <doesn't work>
2 2 (7)
2 2 <same as before>
2 3 <doesn't work>
3 3 <doesn't work>
4 <end>



Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
int CountCombinations(int Number, int Minimal)
{
    int temp = 1;
    if(Number<=1){ return 1; }
    else
        {
         for(int i = 1; i <= floor(Number/2); i++ )
                 if (i>=Minimal){
                    temp = temp + CountCombinations(Number-i, i);
                 }
         }
  return temp;
}


in reference to this:
http://stackoverflow.com/questions/438540/projecteuler-sum-combinations
What is floor(Number/2)?Sorry ı do not understand
IIRC is the biggest integer that is less than that number.
Unnecessary, as integer division returns an integer.

@oonej: ¿why don't start at 'Minimal'?
The result is incorrect for 2 Ah, you are counting (n;0), sorry.
Last edited on
Topic archived. No new replies allowed.