Skip to content

Instantly share code, notes, and snippets.

@anhnguyen1618
Created April 8, 2020 12:53
Show Gist options
  • Save anhnguyen1618/3651231a4c03b55f704326a14b4ce846 to your computer and use it in GitHub Desktop.
Save anhnguyen1618/3651231a4c03b55f704326a14b4ce846 to your computer and use it in GitHub Desktop.
function count(numOfVars, evaluate) {
const num = Math.pow(2, numOfVars);
let counter = 0;
for (let i = 0; i < num; i++) {
const evals = [];
for (let j = 0; j < numOfVars; j++) {
evals.push((i >> j) & 1);
}
const x = evaluate(evals);
counter += x;
}
return counter;
}
const result = count(4, ([a, b, c, d]) => {
return (!a || b) && (!b || c) && (!c || d);
});
console.log(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment