Last active
February 23, 2021 16:12
-
-
Save smithcommajoseph/d260125e533cdc7f52b6402878d7eb95 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
// truth table POC | |
let vars = ['x1', 'x2', 'x3', 'x4'], | |
r = Math.pow(2, vars.length), | |
str = '', | |
i, | |
j; | |
str += `\r\n\r\n` | |
for (i = 0; i < vars.length; i++) { | |
str += `${vars[i]}\t` | |
} | |
str += `\r\n\r\n` | |
for (i = 0; i < r; i++) { | |
for (j = 0; j < vars.length; j++) { | |
let tmp = parseInt( | |
i | |
/ parseInt( | |
(r / Math.pow(2, j)) | |
/ 2 | |
) | |
) % 2; | |
str += `${tmp}\t` | |
} | |
str += `\r\n` | |
} | |
console.log(str); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment