Python
Python copied to clipboard
Optimize Project Euler solutions
Feature description
If someone would like to take a stab at optimizing these solutions, feel free to open a PR or ask for any help here:
Slowest 10 durations
- [ ] Problem 145 / sol1.py (25.00s)
- [ ] Problem 070 / sol1.py (13.86s)
- [ ] Problem 104 / sol1.py (6.84s)
- [ ] Problem 092 / sol1.py (6.01s)
- [ ] Problem 010 / sol2.py (3.90s)
- [ ] Problem 010 / sol1.py (3.76s)
- [ ] Problem 078 / sol1.py (3.67s)
- [ ] Problem 135 / sol1.py (3.59s)
- [ ] Problem 073 / sol1.py (2.64s)
- [ ] Problem 034 / sol1.py (2.54s)
Reference: https://github.com/TheAlgorithms/Python/actions/runs/4580132675/jobs/8088552368#step:5:356
Is this still open??
Is this still open??
Yes
Regarding problem 034, I've stumbled upon this proof .
This proof lowers the upper bound from the current limit = 7 * factorial(9) + 1 # 2,540,161
to 1,499,999, which eliminates 40% of values to be considered. Considering this eliminates the biggest values, this probably cuts runtime by more than 40%.
Additionally I'd prefer if that upper limit would have a comment / reference attached to it, stating their origin. Otherwise, this limit looks very arbitrary.
=============
Regarding the aforementioned proof: At first glance, admittedly it has two phrases, which are formulated incorrectly / ambiguously; but it looks solid.
- The sentence
This implies that if n is a 7 digit number, either the second digit must be 0 or 1 or the last digit is 1.
should end in
[...] the first digit is 1.
- The sentence
If the second digit is now 5, one of the remaining digits has to be at most 4.
should clarify
If the second digit is now at least 5 [...]
for problem 10, sol3.py
is a solution using sieve and is fast. I don't think we can make sol1 and sol2 faster, unless sieve is also used. In that case, they should just be deleted IMO...
for problem 10,
sol3.py
is a solution using sieve and is fast. I don't think we can make sol1 and sol2 faster, unless sieve is also used. In that case, they should just be deleted IMO...
Thanks for chiming in! I agree although for now we shouldn't delete existing solutions but we're disallowing any new solutions unless it takes a completely different approach.
@dhruvmanila I checked the boxes, but there is still a conflict, I can’t understand what? Euler 070
Hi @dhruvmanila,
I've submitted two pull requests (#10558, #10580) that I believe are ready for review and merging. Could you please take a look and assist with the merge process?
Also, I've tried improving performance of project euler 104. I'm wondering if it would be a good idea to include these improvements in the same pull request (#10615).
Your feedback and assistance are greatly appreciated! Thanks in advance.
Hey @ManpreetSingh2004, thanks and sorry to keep you waiting! I'll take a look at it this weekend.