Created
July 24, 2020 14:22
-
-
Save yannayl/297926c7739ac4be8f8b40f9cc0cdaf9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def db(word_size, alphabet_size): | |
L1 = alphabet_size**(word_size-1) | |
lookup_table = {} | |
i = 0 | |
for _ in range(L1*alphabet_size): | |
if i not in lookup_table: | |
lookup_table[i] = alphabet_size - 1 | |
s = lookup_table[i] | |
yield alphabet_size - s - 1 | |
if s != 0: | |
lookup_table[i] = s - 1 | |
else: | |
lookup_table.pop(i) | |
i = (i * alphabet_size + s) % L1 | |
for _ in range(word_size-1): | |
yield 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the lookup table is at most about
alphabet_size
times smaller thanL1
and it's maximum range is roughly the same