Skip to content
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

Optimize Project Euler solutions #8594

Open
10 tasks
dhruvmanila opened this issue Apr 1, 2023 · 8 comments
Open
10 tasks

Optimize Project Euler solutions #8594

dhruvmanila opened this issue Apr 1, 2023 · 8 comments
Labels
enhancement This PR modified some existing files help wanted optimization

Comments

@dhruvmanila
Copy link
Member

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 dhruvmanila added enhancement This PR modified some existing files optimization labels Apr 1, 2023
@ankit-gautam23
Copy link

Is this still open??

@dhruvmanila
Copy link
Member Author

Is this still open??

Yes

@MatthiasHeinz
Copy link

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

@Bjiornulf
Copy link
Contributor

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

@dhruvmanila
Copy link
Member Author

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.

Bjiornulf added a commit to Bjiornulf/the_algorithms_python that referenced this issue Aug 31, 2023
Dividing number number and using remainder is about 25% faster.
Bjiornulf added a commit to Bjiornulf/the_algorithms_python that referenced this issue Aug 31, 2023
Dividing number number and using remainder is about 25% faster.
@quant12345
Copy link
Contributor

quant12345 commented Sep 11, 2023

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

@ManpreetXSingh
Copy link
Contributor

ManpreetXSingh commented Oct 18, 2023

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.

@dhruvmanila
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This PR modified some existing files help wanted optimization
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants
@MatthiasHeinz @quant12345 @Bjiornulf @tianyizheng02 @ManpreetXSingh @dhruvmanila @ankit-gautam23 and others