further performance improvement
still room for optimisations; making deep copy because iterator is not modifiable in for loops
This commit is contained in:
@@ -18,7 +18,7 @@ def probe(key, substrings, words):
|
|||||||
|
|
||||||
|
|
||||||
def remove_crap_from_list(tree, max_depth, thr):
|
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():
|
for key, val in tree.items():
|
||||||
if val > best[len(key)]:
|
if val > best[len(key)]:
|
||||||
best[len(key)] = val
|
best[len(key)] = val
|
||||||
@@ -26,8 +26,10 @@ def remove_crap_from_list(tree, max_depth, thr):
|
|||||||
import copy
|
import copy
|
||||||
tmp = copy.copy(list(tree.items()))
|
tmp = copy.copy(list(tree.items()))
|
||||||
for key, val in tmp:
|
for key, val in tmp:
|
||||||
if val < (best[len(key)] - thr):
|
for i in range(len(key), max_depth+1):
|
||||||
del tree[key]
|
if val < (best[i] - thr + (i-len(key))*thr*1.5):
|
||||||
|
del tree[key]
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
def crack(substrings, words):
|
def crack(substrings, words):
|
||||||
@@ -35,15 +37,11 @@ def crack(substrings, words):
|
|||||||
while tree:
|
while tree:
|
||||||
curr = [key for key, val in sorted(
|
curr = [key for key, val in sorted(
|
||||||
tree.items(), key=lambda ele: ele[1])][-1]
|
tree.items(), key=lambda ele: ele[1])][-1]
|
||||||
print(curr)
|
|
||||||
if len(curr) == len(substrings[0]):
|
if len(curr) == len(substrings[0]):
|
||||||
return curr
|
return curr
|
||||||
del tree[curr]
|
del tree[curr]
|
||||||
tree.update(probe(curr, substrings, words))
|
tree.update(probe(curr, substrings, words))
|
||||||
print(tree)
|
|
||||||
remove_crap_from_list(tree, len(substrings[0]), 10)
|
remove_crap_from_list(tree, len(substrings[0]), 10)
|
||||||
print(tree)
|
|
||||||
print()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user