Skip to content

Instantly share code, notes, and snippets.

@jpwilliams
Created October 2, 2017 08:10
Show Gist options
  • Save jpwilliams/25fb219fea9f6c849048caa3fe9847e8 to your computer and use it in GitHub Desktop.
Save jpwilliams/25fb219fea9f6c849048caa3fe9847e8 to your computer and use it in GitHub Desktop.
Binary Combination Identifier
// Use binary to display all possible combinations of n booleans.
function bci (n) {
const prefix = '0'.repeat(n)
for (let i = 0; i < 2**n; i++) {
console.log((prefix + i.toString(2)).slice(-n))
}
}
> bci(3)
000
001
010
011
100
101
110
111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment