Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 51k
Project Euler problem148#8662
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
Uh oh!
There was an error while loading. Please reload this page.
Project Euler problem148 #8662
Changes from all commits
5c8d0da7a58574449f3ccc0c3e3aa5b0ca6922bc8aba60c2304f30b38c1f2c641c6d419d98bb1e4e89ca237b6c94270291ba29c52249a5071a2229931b1831cf0c3b19f529c53854de83c13d940b706b9bc06932File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| """ | ||
| Project Euler Problem 148 : https://projecteuler.net/problem=148 | ||
| Author: Sai Teja Manchi | ||
| Problem Statement: | ||
| We can easily verify that none of the entries in the | ||
| first seven rows of Pascal's triangle are divisible by 7: | ||
| 1 | ||
| 1 1 | ||
| 1 2 1 | ||
| 1 3 3 1 | ||
| 1 4 6 4 1 | ||
| 1 5 10 10 5 1 | ||
| 1 6 15 20 15 6 1 | ||
| However, if we check the first one hundred rows, we will find that | ||
| only 2361 of the 5050 entries are not divisible by 7. | ||
| Find the number of entries which are not divisible by 7 | ||
| in the first one billion (109) rows of Pascal's triangle. | ||
| """ | ||
| def get_num_binomials(row_num: int) -> int: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| """ | ||
| To compute the number of entries in the nth row of | ||
| pascal triangle that are not divisble by 7. | ||
| To compute the number of entries in the nth row of | ||
| pascal triangle that are not divisble by 7. | ||
| Based on Lucas Theroem it is the product of (each digit in the base 7 n + 1) | ||
| Reference: https://brilliant.org/wiki/lucas-theorem/ | ||
| >>> get_num_binomials(3) | ||
| 4 | ||
| >>> get_num_binomials(6) | ||
| 7 | ||
| >>> get_num_binomials(10) | ||
| 8 | ||
| """ | ||
| cnt = 1 | ||
| while row_num > 0: | ||
| cnt *= (row_num % 7) + 1 | ||
| row_num //= 7 | ||
| return cnt | ||
| def solution(pascal_row_count: int = 10**9) -> int: | ||
| """ | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use below codes for better efficiency which will solve the timeout issue:- Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also add docs in | ||
| To evaluate the solution, use solution() | ||
| >>> solution(3) | ||
| 6 | ||
| >>> solution(10) | ||
| 40 | ||
| >>> solution(100) | ||
| 2361 | ||
| """ | ||
| result = 0 | ||
| for i in range(pascal_row_count): | ||
| result += get_num_binomials(i) | ||
| 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.
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 functionget_num_binomialsThere 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!!