Created
April 8, 2020 12:53
-
-
Save anhnguyen1618/3651231a4c03b55f704326a14b4ce846 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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