Solving this problem using a csp formulation