Python icon indicating copy to clipboard operation
Python copied to clipboard

Optimize Project Euler solutions

Open dhruvmanila opened this issue 1 year ago • 8 comments

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

dhruvmanila avatar Apr 01 '23 05:04 dhruvmanila

Is this still open??

ankit-gautam23 avatar Apr 07 '23 20:04 ankit-gautam23

Is this still open??

Yes

dhruvmanila avatar Apr 08 '23 00:04 dhruvmanila

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.

  1. 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.

  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 [...]

MatthiasHeinz avatar Jun 16 '23 16:06 MatthiasHeinz

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...

Bjiornulf avatar Aug 15 '23 13:08 Bjiornulf

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 avatar Aug 26 '23 12:08 dhruvmanila

@dhruvmanila I checked the boxes, but there is still a conflict, I can’t understand what? Euler 070

quant12345 avatar Sep 11 '23 06:09 quant12345

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.

ManpreetXSingh avatar Oct 18 '23 08:10 ManpreetXSingh

Hey @ManpreetSingh2004, thanks and sorry to keep you waiting! I'll take a look at it this weekend.

dhruvmanila avatar Oct 25 '23 05:10 dhruvmanila