100825/tex/py100325hash.py

# (c) David Vajda
# 10/03/25
# python 3 - hash excersize

def hash_davevajda (X,n,m,b):
    i = 0
    y = 0
    while i < n:
        y = (b*X[i]+y)%m
        i = i + 1
    return y


print ("(c) David Vajda")
print ("10/03/25")
print ("python 3 - hash excersize")

X = [2, 87, 16, 41, 76, 65, 33, 91, 7, 32]
i = 0
n = len (X)

print (end="X = [")
while i < n - 1:
    print (X[i], end=", ")
    i = i + 1
print (X[i], "]")

i=0
y=0
m=97
b=64

print ("m=97, base=64, hashval=",hash_davevajda(X,n,m,b))
print ("m=97, base=64, hashval=",hash_davevajda(X,n,m,100))