Skip to content

Instantly share code, notes, and snippets.

@yannayl
Created July 24, 2020 14:22
Show Gist options
  • Save yannayl/297926c7739ac4be8f8b40f9cc0cdaf9 to your computer and use it in GitHub Desktop.
Save yannayl/297926c7739ac4be8f8b40f9cc0cdaf9 to your computer and use it in GitHub Desktop.
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
@yannayl
Copy link
Author

yannayl commented Jul 24, 2020

the lookup table is at most about alphabet_size times smaller than L1 and it's maximum range is roughly the same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment