Skip to content

Instantly share code, notes, and snippets.

@lemire
Last active July 26, 2016 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lemire/492d68e9ec7dfb897a41608301f66be8 to your computer and use it in GitHub Desktop.
Save lemire/492d68e9ec7dfb897a41608301f66be8 to your computer and use it in GitHub Desktop.
w = 2
def hash(a,x):
return ((a * x) >> w) % ( 1<< w)
def isItUniversal():
for x in range(1<<w):
for y in range(x+1,1<<w):
collisions = 0
for a in range(1 << (2*w)):
if(hash(a,x) == hash(a,y)):
collisions+=1
if(collisions > (1<<w)):
return False
return True
if __name__ == "__main__":
print("words values range from 0 to ", 1<<w)
print("is it universal?",isItUniversal())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment