Skip to content

adding a max_sectors_of_circle algorithm #8778

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

Closed
wants to merge 8 commits into from
Closed
1 change: 1 addition & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
@@ -605,6 +605,7 @@
* [Maclaurin Series](maths/maclaurin_series.py)
* [Manhattan Distance](maths/manhattan_distance.py)
* [Matrix Exponentiation](maths/matrix_exponentiation.py)
* [Max Sectors Of Circle](maths/max_sectors_of_circle.py)
* [Max Sum Sliding Window](maths/max_sum_sliding_window.py)
* [Median Of Two Arrays](maths/median_of_two_arrays.py)
* [Miller Rabin](maths/miller_rabin.py)
28 changes: 28 additions & 0 deletions maths/max_sectors_of_circle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def max_sectors_of_circle(num_cuts: float) -> float:
"""
returns the maximum amount of
sectors a circle can be divided
by if cut 'num_cuts' times
>>> max_sectors_of_circle(54)
1486.0
>>> max_sectors_of_circle(7)
29.0
>>> max_sectors_of_circle(22.5)
265.375
>>> max_sectors_of_circle(-222)
-1
>>> max_sectors_of_circle("-222")
Traceback (most recent call last):
TypeError: num_cuts must be a numeric value.
"""

if not isinstance(num_cuts, (int, float)):
raise TypeError("num_cuts must be a numeric value.")
return ((num_cuts + 2 + num_cuts**2) * 0.5) if num_cuts >= 0 else -1


if __name__ == "__main__":
import doctest

doctest.testmod()