Created
December 18, 2022 13:49
-
-
Save eloidrai/b860db429291f0eecf8c0556645507de 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
from collections import defaultdict | |
def generer_tableau(mot): | |
d = defaultdict(lambda : -1) | |
for i in range(len(mot)): | |
for j in range(i+1, len(mot)): | |
d[(mot[i], j)] = i | |
return d | |
def boyer_moore(t, m): | |
dico = generer_tableau(m) | |
i = 0 | |
while i <= len(t) - len(m): | |
for j in range(len(m)-1, -1, -1): | |
if t[i+j] != m[j]: | |
break | |
else: | |
print("Occurence trouvée en position", i) | |
i += j - dico[(t[i+j], j)] | |
boyer_moore("désencastrement", "en") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment