# Thread: Basic combinatorics

1. ## Basic combinatorics

you have 3 integers given X,Y,Z
X is amount of black soldiers
Y is amount of purple soldiers
Z is amount of white soldiers

Calculate how many variations there are if black and white can't stand togethere (a purple must be inbetween). What would be the formula in the case if variations can't and if they can repeat.

2. This literally has nothing to do at all with C++.

3. I must solve that in code but I am wondering how this would be done.

4. Originally Posted by Tobias Mihel
I must solve that in code but I am wondering how this would be done.
As with any problem, before you can hope to solve this in code you need to know how to do it on paper.

If n = x * y * z then there are n! permutations of soldiers. That's as far as my high-school level combinatorics goes, so what i'd do is to generate all permutations and then discard any permutation where a black and white soldier are neighbours, this should leave you with the remaining legal permutations. This is the naiive approach though, and it would (very) quickly become infeasible as n grows.

Instead, figure out how to do this using math and a piece of paper, and THEN try to translate it to code.

Popular pages Recent additions