Skip to content

Commit 5f54615

Browse files
author
Juanitoupipou
committed
Adding the function isProthNumber(n : int) which returns true if n is a Proth number
1 parent 6e24935 commit 5f54615

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

maths/special_numbers/proth_number.py

+40
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,38 @@ def proth(number: int) -> int:
5959
return proth_list[number - 1]
6060

6161

62+
def isProthNumber(number: int) -> bool :
63+
"""
64+
:param number: nth number to calculate in the sequence
65+
:return: true if number is a Proth number, false etherwise
66+
>>> proth(5)
67+
true
68+
>>> proth(34)
69+
false
70+
>>> proth(-1)
71+
Traceback (most recent call last):
72+
...
73+
ValueError: Input value of [number=-1] must be > 0
74+
>>> proth(6.0)
75+
Traceback (most recent call last):
76+
...
77+
TypeError: Input value of [number=6.0] must be an integer
78+
"""
79+
if number < 1:
80+
msg = f"Input value of [number={number}] must be > 0"
81+
raise ValueError(msg)
82+
83+
N = number
84+
N -= 1
85+
n = 0
86+
while N%2 == 0 :
87+
N = N/2
88+
n += 1
89+
return N < (2**n)
90+
91+
92+
93+
6294
if __name__ == "__main__":
6395
import doctest
6496

@@ -73,3 +105,11 @@ def proth(number: int) -> int:
73105
continue
74106

75107
print(f"The {number}th Proth number: {value}")
108+
109+
list = [3, 5, 9, 13, 49, 57, 193, 241, 163, 201]
110+
111+
for number in list :
112+
if isProthNumber(number):
113+
print(f"{number} is a Proth number")
114+
else :
115+
print(f"{number} is not a Proth number")

0 commit comments

Comments
 (0)