Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8f1a6b0

Browse files
JuanitoupipouJuanitoupipoupre-commit-ci[bot]MaximSmolskiy
authored
Adding the function is_proth_number (TheAlgorithms#12399)
* Adding the function isProthNumber(n : int) which returns true if n is a Proth number * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fixing the issues of the isprothnumber function * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * New fixes on isprothnumber() * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fixes on isprothnumber() * Fixes on isprothnumber * Fixes on isprothnumber() * Fixes on isprothnumber * Update proth_number.py * Update proth_number.py * Update proth_number.py * Update proth_number.py * Update proth_number.py * Update proth_number.py * Update proth_number.py * Update proth_number.py --------- Co-authored-by: Juanitoupipou <juan.dupierris@imt-atlantique.net> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
1 parent 4ce1185 commit 8f1a6b0

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

‎maths/special_numbers/proth_number.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,50 @@ def proth(number: int) -> int:
5959
return proth_list[number - 1]
6060

6161

62+
def is_proth_number(number: int) -> bool:
63+
"""
64+
:param number: positive integer number
65+
:return: true if number is a Proth number, false otherwise
66+
>>> is_proth_number(1)
67+
False
68+
>>> is_proth_number(2)
69+
False
70+
>>> is_proth_number(3)
71+
True
72+
>>> is_proth_number(4)
73+
False
74+
>>> is_proth_number(5)
75+
True
76+
>>> is_proth_number(34)
77+
False
78+
>>> is_proth_number(-1)
79+
Traceback (most recent call last):
80+
...
81+
ValueError: Input value of [number=-1] must be > 0
82+
>>> is_proth_number(6.0)
83+
Traceback (most recent call last):
84+
...
85+
TypeError: Input value of [number=6.0] must be an integer
86+
"""
87+
if not isinstance(number, int):
88+
message = f"Input value of [{number=}] must be an integer"
89+
raise TypeError(message)
90+
91+
if number <= 0:
92+
message = f"Input value of [{number=}] must be > 0"
93+
raise ValueError(message)
94+
95+
if number == 1:
96+
return False
97+
98+
number -= 1
99+
n = 0
100+
while number % 2 == 0:
101+
n += 1
102+
number //= 2
103+
return number < 2**n
104+
105+
62106
if __name__ == "__main__":
63107
import doctest
64108

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

75119
print(f"The {number}th Proth number: {value}")
120+
121+
for number in [1, 2, 3, 4, 5, 9, 13, 49, 57, 193, 241, 163, 201]:
122+
if is_proth_number(number):
123+
print(f"{number} is a Proth number")
124+
else:
125+
print(f"{number} is not a Proth number")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /