-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Added a solution for Project Euler Problem 203 "Squarefree Binomial Coefficients" #3513
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
Added a solution for Project Euler Problem 203 "Squarefree Binomial Coefficients" #3513
Conversation
…ngle. Changes based on review suggestion.
project_euler/problem_203/sol1.py
Outdated
{1, 2, 3, 5, 6, 7, 35, 10, 15, 21} | ||
""" | ||
|
||
def get_squared_primes_to_use( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A function within a function is mostly used as a wrapper. This doesn't seem like that so please separate them out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks for the advice!
Taking out the function also revealed that one doctest of get_squared_primes_to_use
was failing. I fixed it and revisited the function to gracefully handle that failing case.
can you please help me in participating in the 2020 hacktoberfest, submitting the preferred PR and contributing as required by hacktoberfest thereby being eligible for the T-shirt and swags or planting a tree |
hey @fernandobperezm i am intrested in doing it ..could uh plz assign it to me ? |
…unction and fixed a failing doctest with the former.
@jratnani20 @joshuaonazi I'm really sorry I did not see your messages before, this week was really busy for me and I wasn't active here. Also, I just pushed the changes requested by the reviewer :-( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look perfect 👌
Thank you for your contribution! 😄
…oefficients" (TheAlgorithms#3513) * Added a solution for Project Euler Problem 203 (https://projecteuler.net/problem=203) * Simplified loop that calculates the coefficients of the Pascal's Triangle. Changes based on review suggestion. * Moved get_squared_primes_to_use function outside the get_squarefree function and fixed a failing doctest with the former.
…oefficients" (TheAlgorithms#3513) * Added a solution for Project Euler Problem 203 (https://projecteuler.net/problem=203) * Simplified loop that calculates the coefficients of the Pascal's Triangle. Changes based on review suggestion. * Moved get_squared_primes_to_use function outside the get_squarefree function and fixed a failing doctest with the former.
…oefficients" (TheAlgorithms#3513) * Added a solution for Project Euler Problem 203 (https://projecteuler.net/problem=203) * Simplified loop that calculates the coefficients of the Pascal's Triangle. Changes based on review suggestion. * Moved get_squared_primes_to_use function outside the get_squarefree function and fixed a failing doctest with the former.
…oefficients" (TheAlgorithms#3513) * Added a solution for Project Euler Problem 203 (https://projecteuler.net/problem=203) * Simplified loop that calculates the coefficients of the Pascal's Triangle. Changes based on review suggestion. * Moved get_squared_primes_to_use function outside the get_squarefree function and fixed a failing doctest with the former.
Describe your change:
Added a solution to Project Euler Problem 203 "Squarefree Binomial Coefficients" Link.
The solution is based on three main pilars.
d
.2
and the maximum coefficientCmax
using a variant of the Sieve of Eratosthenes Link and considering that the square of each prime must be less or equal than thatCmax
. The calculation returns the square of those primes.n
inton = p * p * r
wherep
is a prime number calculated before andr
is a positive integer. If nor
can be found for all squared primes, then the number is squarefree, else, the number is non-squarefree.After all unique squarefree numbers are calculated, they're summed-up to provide the final answer.
Checklist:
Fixes: #{$ISSUE_NO}
.