Last active
July 26, 2016 01:55
-
-
Save lemire/492d68e9ec7dfb897a41608301f66be8 to your computer and use it in GitHub Desktop.
This file contains 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
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