-
-
Notifications
You must be signed in to change notification settings - Fork 43.8k
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
Project Euler problem148 #8662
Project Euler problem148 #8662
Conversation
for more information, see https://pre-commit.ci
project_euler/problem_148/sol1.py
Outdated
""" | ||
|
||
|
||
def solution(pascal_row_count: int = 10**4) -> int: |
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.
It has a hardcoded value of pascal_row_count which is only 10^4. As a result, the function returns the result for the first 10^4 rows of Pascal's triangle instead of the first billion rows, try this:
def solution(pascal_row_count: int = 10**9) -> int:
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.
Hey,
I've tried with 10**9 but one of the tests failed due to timeout as it was taking more than 6 hours to run.
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.
It's not uncommon for brute force solutions to take a long time or run into timeout issues when dealing with very large inputs. In this case, the input value of 10**9 is extremely large, and the current implementation of the "solution" function does not have an efficient algorithm to handle such large inputs.
|
||
|
||
def solution(pascal_row_count: int = 10**9) -> int: | ||
""" |
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.
use below codes for better efficiency which will solve the timeout issue:-
def solution(pascal_row_count: int = 10**9) -> int:
"""
To evaluate the solution, use solution()
>>> solution(3)
6
>>> solution(10)
40
>>> solution(100)
2361
"""
# Helper function to compute the number of odd binomial coefficients in a row
def odd_binomials(n: int) -> int:
res = 0
while n > 0:
res += n % 2
n //= 2
return res
# Compute the sum of odd binomial coefficients modulo 7 for each row up to pascal_row_count
result = 0
for k in range(pascal_row_count):
result += odd_binomials(k) % 7
return result
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.
also add docs in odd_binomials
, you can put above comment of that function inside as a doc.
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
""" | ||
|
||
|
||
def get_num_binomials(row_num: int) -> int: |
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.
As there is no test file in this pull request nor any test function or class in the file project_euler/problem_148/sol1.py
, please provide doctest for the function get_num_binomials
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.
@saitejamanchi add doctests.
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.
@rohan472000 Sure, will add.
Thanks a lot for the help!!
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
""" | ||
|
||
|
||
def get_num_binomials(row_num: int) -> int: |
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.
As there is no test file in this pull request nor any test function or class in the file project_euler/problem_148/sol1.py
, please provide doctest for the function get_num_binomials
…manchi/TheAlgorithms-Python into project-euler-problem148
for more information, see https://pre-commit.ci
kindly fix ruff issue before committing...by |
Hi @dhruvmanila , Could you please look into this pull request? |
Describe your change:
Added solution for Problem 148 in Project Euler.
Checklist:
Fixes: #{$ISSUE_NO}
.