Mathematical Programming Formulation

The formulation shown here generalizes the problem to an $n \times n \times n$ array and an arbitrary number of colors.