[mypy] Fix type annotations for maths directory (#5782)

* [mypy] Fix annotations in `maths/series/p_series.py`

* Update p_series.py

* Update p_series.py

* Remove from excluded in mypy.ini

* Type annotation for series

* Annotate maths/proth_number.py (properly)

* Remove from excluded in mypy.ini

* Annotate average_mode.py

* Update average_mode.py

* Update average_mode.py

* Update average_mode.py

* Update average_mode.py

* Remove from excluded in mypy.ini

* Fix annotations in gamma_recursive.py

* Remove from excluded in mypy.ini

* Annotations for geometric_series.py

* Update geometric_series.py

* Update mypy.ini

* Update average_mode.py

* Update average_mode.py

* Update average_mode.py

* Update mypy.ini

* Update mypy.ini

* Update mypy.ini

* Update average_mode.py

* Update proth_number.py

* Update average_mode.py

* Update gamma_recursive.py

* Update proth_number.py

* Update mypy.ini

* Update geometric_series.py

* Update average_mode.py

* Update proth_number.py

* Update geometric_series.py

* Update geometric_series.py

* Update geometric_series.py

* Update p_series.py

* Update geometric_series.py

* Update p_series.py

* Update p_series.py

* Update geometric_series.py

* Update p_series.py

* Update p_series.py

* Remove data_structures/stacks/next_greater_element.py|

Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
Rohan R Bharadwaj
2021-11-07 20:43:58 +05:30
committed by GitHub
parent db5aa1d188
commit a98465230f
6 changed files with 66 additions and 61 deletions

View File

@ -1,6 +1,5 @@
"""
Calculate the nth Proth number
Source:
https://handwiki.org/wiki/Proth_number
"""
@ -12,22 +11,17 @@ def proth(number: int) -> int:
"""
:param number: nth number to calculate in the sequence
:return: the nth number in Proth number
Note: indexing starts at 1 i.e. proth(1) gives the first Proth number of 3
>>> proth(6)
25
>>> proth(0)
Traceback (most recent call last):
...
ValueError: Input value of [number=0] must be > 0
>>> proth(-1)
Traceback (most recent call last):
...
ValueError: Input value of [number=-1] must be > 0
>>> proth(6.0)
Traceback (most recent call last):
...
@ -44,14 +38,12 @@ def proth(number: int) -> int:
elif number == 2:
return 5
else:
block_index = number // 3
"""
+1 for binary starting at 0 i.e. 2^0, 2^1, etc.
+1 to start the sequence at the 3rd Proth number
Hence, we have a +2 in the below statement
"""
block_index = math.log(block_index, 2) + 2
block_index = int(block_index)
block_index = int(math.log(number // 3, 2)) + 2
proth_list = [3, 5]
proth_index = 2
@ -66,6 +58,10 @@ def proth(number: int) -> int:
if __name__ == "__main__":
import doctest
doctest.testmod()
for number in range(11):
value = 0
try: