0
$\begingroup$

I'm trying to figure out how to get all combinations of putting x*n balls into n boxes.

There should be the same number of balls in each box.

If it was about putting n balls into n boxes, the result would be n! and the pseudocode:

for b1 in set:
   for b2 in set-b2:
      for b3 in set-b2-b3:
          results.append(b1,b2,b3,b4) 

How can I get this way combinations of x*n instead of n balls so in one box there is x balls exactly?

$\endgroup$
3
  • $\begingroup$ This is a math question and belongs to math.se. The answer is $(xn)!/x!^n$. $\endgroup$ Apr 24, 2016 at 10:35
  • $\begingroup$ @YuvalFilmus Counting the number of combinations is math, but an algorithm to generate them is CS. $\endgroup$ Apr 26, 2016 at 11:54
  • $\begingroup$ Generating them is even easier using the trivial recursive approach. The difficult part is counting the number of solutions. $\endgroup$ Apr 26, 2016 at 11:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.