-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Need optimization for Project Euler problem 74 sol2.py #3869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This seems like a similar problem that I solved before when I submitted a solution for Euler 14 #2216 Since you're bound to do the same few calculations a few times over, here are some hints (which I can't be bothered to program in right now)
factorials = [1] # 0! = 1
for i in range(1,10):
factorials.append(factorials[-1]*i) That way you make use of the recursive nature of factorials while also providing a list of them Maybe that helps for the people that want to help optimize this problem |
Thanks a lot @crazazy One thing that definitely stands out is i sol2.py doctest runs twice and on large numbers: Changing this definitely saved me time locally. While I agree this is not the most elegant way out, but I feel it's rather smart. Also, when I compared the two solutions, I think, they will not always give identical results. For example, using the example for sol1.py in sol2.py gives: I would call it a bug, but maybe I missed something. I hope this is not expected behaviour. Would also be happy to work on it, if this is opened separately as an issue. |
…blem 74's Solution 2 (TheAlgorithms#3893) * Fixes: TheAlgorithms#3869: Optimize Project Euler's Problem 74's Solution 2 * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
…blem 74's Solution 2 (TheAlgorithms#3893) * Fixes: TheAlgorithms#3869: Optimize Project Euler's Problem 74's Solution 2 * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
…blem 74's Solution 2 (TheAlgorithms#3893) * Fixes: TheAlgorithms#3869: Optimize Project Euler's Problem 74's Solution 2 * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
…blem 74's Solution 2 (TheAlgorithms#3893) * Fixes: TheAlgorithms#3869: Optimize Project Euler's Problem 74's Solution 2 * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Due to the acceptance of Project Euler problem 74 sol2.py, our tests are taking a long time to finish.
validate-solutions
: [4:34] https://github.com/TheAlgorithms/Python/pull/3016/checks?check_run_id=1369207443#step:5:24project-euler
: [9:00] https://github.com/TheAlgorithms/Python/pull/3016/checks?check_run_id=1369207451#step:5:286NOTE: We do not want a new solution for the problem but rather an optimized version for it. Take it as a challenge in optimization. Good luck!
The text was updated successfully, but these errors were encountered: