Counting permutations

Apr 13, 2012 at 3:44pm
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
Apr 13, 2012 at 4:03pm
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...
Apr 13, 2012 at 4:04pm
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.

Apr 13, 2012 at 4:10pm
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 Apr 13, 2012 at 4:19pm
Apr 14, 2012 at 4:39am
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
May 9, 2012 at 5:30pm
What is floor(Number/2)?Sorry ı do not understand
May 9, 2012 at 6:09pm
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 May 9, 2012 at 7:08pm
Topic archived. No new replies allowed.