Skip to content

Instantly share code, notes, and snippets.

View inside-code-yt's full-sized avatar

Inside code inside-code-yt

View GitHub Profile
def rabin_karp(s, p, d=26, q=101):
n = len(s)
m = len(p)
h = pow(d, m-1) % q
hash_p = 0
hash_s = 0
output = []
for i in range(m):
hash_p = (d*hash_p + ord(p[i])) % q
hash_s = (d*hash_s + ord(s[i])) % q