Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdded a solution for Project Euler Problem 203 "Squarefree Binomial Coefficients" #3513
+181
−0
Conversation
project_euler/problem_203/sol1.py
Outdated
coefficients = set() | ||
previous_coefficients = [] | ||
for step in range(1, depth + 1): | ||
if step == 1: | ||
coefficients.add(1) | ||
previous_coefficients = [1] | ||
else: | ||
coefficients_begins_one = previous_coefficients + [0] | ||
coefficients_ends_one = [0] + previous_coefficients | ||
previous_coefficients = [] |
Comment on lines
52
to
61
dhruvmanila
Oct 19, 2020
Member
Suggested change
coefficients = set()
previous_coefficients = []
for step in range(1, depth + 1):
if step == 1:
coefficients.add(1)
previous_coefficients = [1]
else:
coefficients_begins_one = previous_coefficients + [0]
coefficients_ends_one = [0] + previous_coefficients
previous_coefficients = []
coefficients = {1}
previous_coefficients = [1]
for step in range(2, depth + 1):
coefficients_begins_one = previous_coefficients + [0]
coefficients_ends_one = [0] + previous_coefficients
previous_coefficients = []
Please test whether this works or not.
Suggested change
coefficients = set() | |
previous_coefficients = [] | |
for step in range(1, depth + 1): | |
if step == 1: | |
coefficients.add(1) | |
previous_coefficients = [1] | |
else: | |
coefficients_begins_one = previous_coefficients + [0] | |
coefficients_ends_one = [0] + previous_coefficients | |
previous_coefficients = [] | |
coefficients = {1} | |
previous_coefficients = [1] | |
for step in range(2, depth + 1): | |
coefficients_begins_one = previous_coefficients + [0] | |
coefficients_ends_one = [0] + previous_coefficients | |
previous_coefficients = [] |
Please test whether this works or not.
fernandobperezm
Oct 19, 2020
•
Author
Tested locally and works. Also black, flake8 and doctests pass. Commit is already on the branch :-D
Tested locally and works. Also black, flake8 and doctests pass. Commit is already on the branch :-D
…ngle. Changes based on review suggestion.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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}
.