further performance improvement

still room for optimisations; making deep copy because iterator is not
modifiable in for loops
breakmono2
Eggert Jung 5 years ago
parent 139b78a417
commit 6571c1dd2f

@ -18,7 +18,7 @@ def probe(key, substrings, words):
def remove_crap_from_list(tree, max_depth, thr):
best = [0 for x in range(max_depth+1)]
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
@ -26,8 +26,10 @@ def remove_crap_from_list(tree, max_depth, thr):
import copy
tmp = copy.copy(list(tree.items()))
for key, val in tmp:
if val < (best[len(key)] - thr):
del tree[key]
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):
@ -35,15 +37,11 @@ def crack(substrings, words):
while tree:
curr = [key for key, val in sorted(
tree.items(), key=lambda ele: ele[1])][-1]
print(curr)
if len(curr) == len(substrings[0]):
return curr
del tree[curr]
tree.update(probe(curr, substrings, words))
print(tree)
remove_crap_from_list(tree, len(substrings[0]), 10)
print(tree)
print()
if __name__ == "__main__":

Loading…
Cancel
Save