Saturday, August 17, 2013

Optimization: Algorthm to share 5 Apples with 3 people - compute all valid permutations

Optimization: Algorthm to share 5 Apples with 3 people - compute all valid
permutations

Stuck with a problem.
Given 5 apples and 3 people, compute all possible distribution permutations.
For example:
1) Peter gets 5 Apples, Paul None, Mary None
2) Peter gets 4 Apples, Paul 1, Mary None
etc...
Peter Paul Mary
5 0 0
4 1 0
4 0 1
3 2 0
3 1 1
3 0 2
2 3 0
2 2 1
2 1 2
2 0 3
1 4 0
1 3 1
1 2 2
1 1 3
1 0 4
0 0 5
0 1 4
0 2 3
0 3 2
0 4 1
0 5 0
All 5 apples must be distributed and no more than 5 apples may be
distributed.
Is there an algorithm that will allow me to calculate all permutations,
when when the parameters change.
e.g. 7 Apples and 4 people.
Probably simple for you maths wizards?
Thanks! Harry

No comments:

Post a Comment