diff --git a/DIRECTORY.md b/DIRECTORY.md index 0c21b9537fc1..80e69074ba76 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -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) diff --git a/maths/max_sectors_of_circle.py b/maths/max_sectors_of_circle.py new file mode 100644 index 000000000000..ac8855259519 --- /dev/null +++ b/maths/max_sectors_of_circle.py @@ -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()