This repository was archived by the owner on Aug 1, 2021. It is now read-only.
Repository navigation
Fix #540 : Added more tests to nth-prime and altered example code - #542
Merged
Merged
Conversation
Contributor
|
@gavinhenderson looks great. I took a similar approach with my solution a while back! Though you can see I was lazy and imported my prior I appreciate the fact that you commented explaining the magical math. It might be improved slightly by referring to a citation that explains the formula. By way of example, here's that old solution I mentioned: import sieve from './sieve'; //my Sieve class from earlier
export default class Prime{
// see http://en.wikipedia.org/wiki/Prime_number_theorem#Approximations_for_the_nth_prime_number
nth(n) {
if (n < 1) throw new Error("Prime is not possible");
let approximateLimit = n * Math.log(n) + n * Math.log(Math.log(n));
approximateLimit < 15 ? approximateLimit = 15 : {};
return sieve(approximateLimit).primes[n - 1];
}
}Would you mind making that comment change? Otherwise this PR looks good to me. |
Contributor
Author
|
@matthewmorgan Thats the link added now |
Contributor
|
@gavinhenderson awesome-- thank you. Can I ask you to squash your commits to one for this PR? Please let me know if you need assistance with this, I'd be happy to help. |
Contributor
Author
|
@matthewmorgan So I think I might have done it? |
Contributor
|
Nicely done. Thanks for your contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The test execute time has gone from
2.975swith the old example code and the old tests to3.200swith the new tests and the new example code.