Skip to content
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5f54615
Adding the function isProthNumber(n : int) which returns true if n is…
Nov 27, 2024
a1ba381
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 27, 2024
fa04fdf
Fixing the issues of the isprothnumber function
Nov 27, 2024
bd59a27
Merge branch 'Juan' of https://github.com/Miranda13/Python into Juan
Nov 27, 2024
49b4546
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 27, 2024
319b501
New fixes on isprothnumber()
Nov 27, 2024
941efc3
Merge branch 'Juan' of https://github.com/Miranda13/Python into Juan
Nov 27, 2024
dc2f2f0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 27, 2024
8776dd6
Fixes on isprothnumber()
Nov 27, 2024
2a86be1
Merge branch 'Juan' of https://github.com/Miranda13/Python into Juan
Nov 27, 2024
45b7461
Fixes on isprothnumber
Nov 27, 2024
48cd502
Fixes on isprothnumber()
Nov 27, 2024
d5bc730
Fixes on isprothnumber
Nov 27, 2024
e965f29
Merge branch 'master' into Juan
MaximSmolskiy Sep 7, 2025
44b36da
Update proth_number.py
MaximSmolskiy Sep 7, 2025
fd8d253
Update proth_number.py
MaximSmolskiy Sep 7, 2025
9b016fe
Update proth_number.py
MaximSmolskiy Sep 7, 2025
a80cda0
Update proth_number.py
MaximSmolskiy Sep 7, 2025
58b6288
Update proth_number.py
MaximSmolskiy Sep 7, 2025
f05abe4
Update proth_number.py
MaximSmolskiy Sep 7, 2025
2159b09
Update proth_number.py
MaximSmolskiy Sep 7, 2025
f707813
Update proth_number.py
MaximSmolskiy Sep 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions maths/special_numbers/proth_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,50 @@ def proth(number: int) -> int:
return proth_list[number - 1]


def is_proth_number(number: int) -> bool:
"""
:param number: positive integer number
:return: true if number is a Proth number, false otherwise
>>> is_proth_number(1)
False
>>> is_proth_number(2)
False
>>> is_proth_number(3)
True
>>> is_proth_number(4)
False
>>> is_proth_number(5)
True
>>> is_proth_number(34)
False
>>> is_proth_number(-1)
Traceback (most recent call last):
...
ValueError: Input value of [number=-1] must be > 0
>>> is_proth_number(6.0)
Traceback (most recent call last):
...
TypeError: Input value of [number=6.0] must be an integer
"""
if not isinstance(number, int):
message = f"Input value of [{number=}] must be an integer"
raise TypeError(message)

if number <= 0:
message = f"Input value of [{number=}] must be > 0"
raise ValueError(message)

if number == 1:
return False

number -= 1
n = 0
while number % 2 == 0:
n += 1
number //= 2
return number < 2**n


if __name__ == "__main__":
import doctest

Expand All @@ -73,3 +117,9 @@ def proth(number: int) -> int:
continue

print(f"The {number}th Proth number: {value}")

for number in [1, 2, 3, 4, 5, 9, 13, 49, 57, 193, 241, 163, 201]:
if is_proth_number(number):
print(f"{number} is a Proth number")
else:
print(f"{number} is not a Proth number")