We present a new formulation to automatically solve jigsaw puzzles considering only the information contained on the image. Our formulation maps the problem of solving a jigsaw puzzle to the maximization of a constrained quadratic function that can be solved by a numerical method. The proposed method is deterministic and it can handle arbitrary rectangular pieces. We tested the validity of the method to solve problems up to 3300 puzzle pieces, and we compared our results to the current state-of-the-art, obtaining superior accuracy.