-
-
Notifications
You must be signed in to change notification settings - Fork 46.7k
add : Project Euler 95 solution #9172
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
Closed
kosuri-indu
wants to merge
14
commits into
TheAlgorithms:master
from
kosuri-indu:add/project-euler-95
Closed
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
320f8f2
Project euler 95
kosuri-indu 9ab8052
adding doctests
kosuri-indu a363819
adding doctests
kosuri-indu 6d68812
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 51a626b
descriptive names
kosuri-indu 977446f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3ddfcdc
examples
kosuri-indu eb9f6c0
Merge branch 'add/project-euler-95' of https://github.com/kosuri-indu…
kosuri-indu 6f0f563
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c19bd99
ruff errors sorted
kosuri-indu 9d6cb8e
ruff errors sorted
kosuri-indu e652c28
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 18e2c7c
ruff errors sorted
kosuri-indu 484d88b
ruff errors sorted
kosuri-indu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
""" | ||
Problem 95 | ||
Url: https://projecteuler.net/problem=95 | ||
""" | ||
|
||
|
||
def solution(number : int = 10**6) -> int: | ||
""" | ||
Returns the smallest member when n = 1000000 | ||
>> 14316 | ||
""" | ||
|
||
sum_of_div = [0] * (number + 1) | ||
for i in range(1, number // 2 + 1): | ||
for j in range(i * 2, number + 1, i): | ||
sum_of_div[j] += i | ||
|
||
checked = [False] * (number + 1) | ||
max_len_of_chain = 0 | ||
result = 0 | ||
for i in range(2, number + 1): | ||
possible_chain = [] | ||
j = i | ||
while not checked[j]: | ||
checked[j] = True | ||
possible_chain.append(j) | ||
j = sum_of_div[j] | ||
if j > number: | ||
break | ||
if j in possible_chain: | ||
len_of_chain = len(possible_chain) - possible_chain.index(j) | ||
if len_of_chain > max_len_of_chain: | ||
max_len_of_chain = len_of_chain | ||
result = min(possible_chain[-len_of_chain:]) | ||
break | ||
return result | ||
|
||
|
||
if __name__ == "__main__": | ||
import doctest | ||
|
||
doctest.testmod() | ||
print(f"{solution() = }") |
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.
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_095/sol1.py
, please provide doctest for the functionsolution