It is surprising difficult to find a CSP Solver for solving CSP Problems directly in Javascript. One such systems is Sentient https://sentient-lang.org/. The following demonstrates how to solve our initial 2019 Magic Square program using Sentient. The program is a slightly modified version of the example given in https://sentient-lang.org/examples/magic-square.
Sentinent 4x4 Magic Square Program
To solve the Magic Square the following JavaScript code is executed in this post:
var myProgram = Sentient.compile(myProgram);
Sentient.run({
program: myProgram,
// assignments are used to preset some of the values
// in our case the year 1514 of the Duerer Magic Square
assignments: { target: 34, magic_square: { 3: { 1: 15, 2: 14 } }},
callback: function (result) {
process_result(result);
}
});
If you want to try out your own programs directly in the browser use these instructions: https://sentient-lang.org/tutorial/browser