alphametics: Revised, increased speed#1097
Conversation
Reworked the solution, eliminated few inefficiencies
cmccandless
left a comment
There was a problem hiding this comment.
Just a minor change. Great work!
exercises/alphametics/example.py
Outdated
| for let, dig in zip(t_lowdigs, t_digvals)]) | ||
| if testsum % 10 == 0: | ||
| # Low digit test passed, check the main digits | ||
| # print(lowdigdict) |
There was a problem hiding this comment.
Please remove print() statements (even commented out).
|
I think we can do even better, like a recursive algorithm to check the lowest digits, |
|
Since the pull request is approved. Is there anything else I need to do on my side? Please, let me know |
|
@nikamirrr Regarding a recursive solution, it may not be as fast as you think. From this article by Lars Kruse (found on the Python Wiki):
If you are going to attempt another refactor, please just continue to use this PR. If you don't plan on adding work to this iteration, it should be good to merge. |
|
I understand the general impact of the recursion. But if it allows to drop bad paths early enough it will be beneficial |
|
@nikamirrr Fair enough. I'm curious to see how it turns out. |
|
Looks like run time is down to 0.5 seconds now compared to ~5 seconds with the previous iteration. |
N-Parsons
left a comment
There was a problem hiding this comment.
@nikamirrr, if you're planning to do any more work on this, let me know, but I think this is fine to merge as is.
|
Please, merge as is. Any further improvement is experimental and a bit less likely. |
|
@nikamirrr Merged. Thanks! |
|
@cmccandless |
Reworked the solution, eliminated few inefficiencies