-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Weird numbers #6871
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
Merged
Merged
Weird numbers #6871
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7eef761
Create weird_number.py
Variiiest d1a5ae9
check
Variiiest 782012b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 9a44b4e
resolved
Variiiest ba747df
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] f747cf9
removed
Variiiest 3d2efce
Update weird_number.py
cclauss 18e9dd7
Update weird_number.py
cclauss 6d0d8f4
Update weird_number.py
cclauss 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
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,69 @@ | ||
from math import sqrt | ||
from typing import List | ||
|
||
def factors(n : int) -> List[int]: | ||
|
||
v = [] | ||
v.append(1) | ||
|
||
for i in range(2, int(sqrt(n)) + 1, 1): | ||
|
||
if n % i == 0: | ||
v.append(i) | ||
if int(n / i) != i: | ||
v.append(int(n / i)) | ||
return v | ||
|
||
|
||
def abundant(n : int) -> bool: | ||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sum = 0 | ||
v = factors(n) | ||
for i in range(len(v)): | ||
sum += v[i] | ||
if (sum > n): | ||
return True | ||
else: | ||
return False | ||
|
||
def semi_perfect(n: int) -> bool: | ||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
v = factors(n) | ||
v.sort(reverse = False) | ||
r = len(v) | ||
subset = [[0 for i in range(n + 1)] | ||
for j in range(r + 1)] | ||
for i in range(r + 1): | ||
subset[i][0] = True | ||
|
||
for i in range(1, n + 1): | ||
subset[0][i] = False | ||
|
||
for i in range(1, r + 1): | ||
for j in range(1, n + 1): | ||
if j < v[i - 1]: | ||
subset[i][j] = subset[i - 1][j] | ||
else: | ||
subset[i][j] = subset[i - 1][j] or subset[i - 1][j - v[i - 1]] | ||
|
||
if (subset[r][n]) == 0: | ||
return False | ||
else: | ||
return True | ||
|
||
def weird(n : int) -> bool: | ||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (abundant(n) == True and semi_perfect(n) == False): | ||
return True | ||
else: | ||
return False | ||
|
||
def main() -> None: | ||
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
cclauss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
n = 70 | ||
if (weird(n)): | ||
print("Weird Number") | ||
else: | ||
print("Not Weird Number") | ||
|
||
if __name__ == "__main__": | ||
import doctest | ||
|
||
doctest.testmod(verbose=True) | ||
main() |
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.
Uh oh!
There was an error while loading. Please reload this page.