## Determining Combinations with Restraints

I'm loosely familiar with the formulas for combinations and permutations. However, I don't know how to use the formula with restraints.

Here is the specific issue I am having:

Number of Objects: 16
Number of States: 2
Number of Black Objects 8
Number of White Objects: 8

How many unique permutations color permutations are possible?

I know that for the first and last 8 both have 2^8 permutations, so there is a minimum of 512 permutations.

 I'm sorry, I don't understand the question.
 Hey Altermeris and welcome to the forums. Your question is unclear but one recommendation to make it clearer is to write the scenarios and then write how many states per scenario. For example 2 states per object for 16 objects is 32 states, or 2 states per combination of every pair of objects selected without replacemet is 2*16*15 = 480 or 512 if with replacement. This kind of thing would be a lot more informative and cause less confusion.

## Determining Combinations with Restraints

I wrote a brute force program to solve the problem. By punching in the output of the brute forcing algorithm into WolframAlpha, I was able to find the sequence formula to solve this problem.

An=C(2n,n)

Code:
public class BruteForcePermutation {

public static boolean countUniqueChar(int num, char symb, String text){
int count = 0;
int textLength = text.length();
char[] charArray = new char[textLength];

charArray = text.toCharArray();

for(int i = 0; i<textLength; i++)
if(charArray[i]==symb)count++;

if(count==num) return true;
else return false;
}

public static String intToBinary(int num, int size){
String result = "";

while(num!=0){
result = (num%2) + result;
num /= 2;
size--;
}

while(size>0){
result = "0" + result;
size--;
}

return result;
}

public static void main(String[] args){
String currentBin = "";
int permutations;

int terms = 10;
for(int size = 2; size<=terms*2;size+=2){
permutations = 0;
for(int i = 0; i<Math.pow(2,size) ;i++){
currentBin = intToBinary(i,size);
if(countUniqueChar((size/2),'1',currentBin)){
//System.out.println(currentBin);
permutations++;
}
}
System.out.print(permutations + " ");
}
}
}
I was working on this problem in particular in hope of creating a more efficient algorithm for a pathing problem.

 OK, so have you solved the problem to your satisfaction? If not, then could you please post a better description of your problem, because I don't want to read through Java to try to figure out what you mean.

 Quote by Robert1986 OK, so have you solved the problem to your satisfaction? If not, then could you please post a better description of your problem, because I don't want to read through Java to try to figure out what you mean.
I am still unsure about how to determine the formula by observation.

I'll try describing the problem differently.

If you have a bag of n-Coins that contain (n/2) black coins and (n/2) white coins, how many ways can you place the white and black coins in a line of n?

 Quote by Altermeris I am still unsure about how to determine the formula by observation. I'll try describing the problem differently. If you have a bag of n-Coins that contain (n/2) black coins and (n/2) white coins, how many ways can you place the white and black coins in a line of n?
$$\binom{n}{n/2}$$
the number of combinations of n objects taken n/2 at a time.