diff options
Diffstat (limited to '')
| -rw-r--r-- | benchmark/permutations.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/benchmark/permutations.ts b/benchmark/permutations.ts new file mode 100644 index 0000000..4465557 --- /dev/null +++ b/benchmark/permutations.ts @@ -0,0 +1,23 @@ +export function* permutations(pattern: string) { + let totalPerms = 1; + for (const char of pattern) { + if (char !== '0' && char !== '1') { + totalPerms *= 2; + } + } + + for (let permIndex = 0; permIndex < totalPerms; permIndex++) { + let varIndex = 0; + let value = 0; + for (const char of pattern) { + value *= 2; + if (char === '1') { + value++; + } else if (char !== '0') { + value += permIndex & (1 << varIndex) ? 1 : 0; + varIndex++; + } + } + yield value; + } +} |
