2SAT is a restricted version of the boolean satisfiability problem where the number of variables per clause is at most 2. Works both in node.js and in the browser using browserify.
var twoSat =//Solve problem://// (x1 | !x2) & (x3 | x1) & (x3 | x2)//console
Finds a satisfying assignment for a 2SAT problem written in conjunctive normal form. If no assignment is possible returns
numVariablesis the number of variables
clausesis a list of binary clauses. Variables are indexed in clauses starting at
1and negative values indicate negation.
Returns A vector of assignments to the variables of the clause. If problem is not satisfiable, returns
(c) 2013 Mikola Lysenko. MIT License