Compare commits

...

2 Commits

Author SHA1 Message Date
Eggert Jung 6571c1dd2f further performance improvement
still room for optimisations; making deep copy because iterator is not
modifiable in for loops
5 years ago
Eggert Jung 139b78a417 add performance optimisation 5 years ago

@ -17,6 +17,21 @@ def probe(key, substrings, words):
return {key: val for key, val in key_hits.items() if val == best_val}
def remove_crap_from_list(tree, max_depth, thr):
best = [-x * thr for x in range(max_depth+2)]
for key, val in tree.items():
if val > best[len(key)]:
best[len(key)] = val
import copy
tmp = copy.copy(list(tree.items()))
for key, val in tmp:
for i in range(len(key), max_depth+1):
if val < (best[i] - thr + (i-len(key))*thr*1.5):
del tree[key]
break
def crack(substrings, words):
tree = {"": 0}
while tree:
@ -26,6 +41,7 @@ def crack(substrings, words):
return curr
del tree[curr]
tree.update(probe(curr, substrings, words))
remove_crap_from_list(tree, len(substrings[0]), 10)
if __name__ == "__main__":

Loading…
Cancel
Save