Counting the Number of Combinations with Constraints [closed]

Although combination and permutation method are the standard way for solving such class of problems, often manipulations are needed for categorization of the final solution. In this case, a tree structure can help. Also note that the blue and green ball can be interchanged, hence without loss of generality, we assume that the blue ball, resides on the left side of the green ball. The final solution is then multiplied in $2$.

To proceed, note that the green ball must be in one of the two last positions (other cases are either impossible or repetitive).

(i) if the green ball is in the last position, then constraint $3$ is fulfilled and to fulfill constraint $1$, the blue and red balls must occupy the first two positions. The yellow and the orange balls then occupy the 3rd and 4th positions. This is possible to $2!\times 2!\times 1$ total cases.

(ii) if the green ball is in the one to last position, then the blue ball must be in the first position, which enforces the red ball to be positioned second. The yellow ball should either be in the 3rd or last position, where the latter is impossible. Hence there is a total of $1$ case.

The total cases are $(2!\times 2!\times 1+1)\times 2!=10$.


The answer is 10. I use Mathematica to solve this problem, you can write code like this:

Select[Permutations @{"Red", "Green", "Yellow", "Blue", 
    "Orange"}, (FirstPosition[#, "Red"][[1]] == 1  || 
      FirstPosition[#, "Red"][[1]] == 2 )
    && (Abs @ (FirstPosition[#, "Green"][[1]] - 
         FirstPosition[#, "Blue"][[1]] ) > 2) && 
    FirstPosition[#, "Yellow"][[1]] != 5
   &] // Length

enter image description here