
"""simple docstring"""







from __future__ import annotations

import matplotlib.pyplot as plt  # type: ignore
import numpy

# initial triangle of Koch snowflake
lowercase_         =       numpy.array([0, 0])
lowercase_         =       numpy.array([0.5, 0.866_0254])
lowercase_         =       numpy.array([1, 0])
lowercase_         =       [VECTOR_1, VECTOR_2, VECTOR_3, VECTOR_1]




def       A_      (       lowercase    ,			lowercase   )  ->				list[numpy.ndarray]:


     """simple docstring"""







     UpperCAmelCase_    :     int            =	initial_vectors
     for _ in range(lowercase   ):
          UpperCAmelCase_    :     List[Any]            =	iteration_step(lowercase   )
     return vectors




def       A_      (       lowercase   )  ->				list[numpy.ndarray]:


     """simple docstring"""







     UpperCAmelCase_    :     int            =	[]
     for i, start_vector in enumerate(vectors[:-1]   ):
          UpperCAmelCase_    :     Any            =	vectors[i + 1]
          new_vectors.append(lowercase   )
          UpperCAmelCase_    :     Any            =	end_vector - start_vector
          new_vectors.append(start_vector + difference_vector / 3   )
          new_vectors.append(
              start_vector + difference_vector / 3 + rotate(difference_vector / 3    ,			60   )   )
          new_vectors.append(start_vector + difference_vector * 2 / 3   )
     new_vectors.append(vectors[-1]   )
     return new_vectors




def       A_      (       lowercase    ,			lowercase   )  ->				numpy.ndarray:


     """simple docstring"""







     UpperCAmelCase_    :     Optional[int]            =	numpy.radians(lowercase   )
     UpperCAmelCase_       ,UpperCAmelCase_    :     Tuple            =	numpy.cos(lowercase   ), numpy.sin(lowercase   )
     UpperCAmelCase_    :     Any            =	numpy.array(((c, -s), (s, c))   )
     return numpy.dot(lowercase    ,			lowercase   )




def       A_      (       lowercase   )  ->				None:


     """simple docstring"""







     UpperCAmelCase_    :     Dict            =	plt.gca()
     axes.set_aspect("""equal"""   )

     # matplotlib.pyplot.plot takes a list of all x-coordinates and a list of all
     # y-coordinates as inputs, which are constructed from the vector-list using
     # zip()
     UpperCAmelCase_       ,UpperCAmelCase_    :     Tuple            =	zip(*lowercase   )
     plt.plot(lowercase    ,			lowercase   )
     plt.show()


if __name__ == "__main__":
       import doctest

       doctest.testmod()

       lowercase_         =       iterate(INITIAL_VECTORS, 5)
       plot(processed_vectors)



"""simple docstring"""







def       A_      (       lowercase   )  ->				None:


     """simple docstring"""







     UpperCAmelCase_    :     Union[str, Any]            =	generate_pascal_triangle(lowercase   )
     for row_idx in range(lowercase   ):
          # Print left spaces
          for _ in range(num_rows - row_idx - 1   ):
               print(end=""" """   )
          # Print row values
          for col_idx in range(row_idx + 1   ):
               if col_idx != row_idx:
                    print(triangle[row_idx][col_idx]    ,			end=""" """   )
               else:
                    print(triangle[row_idx][col_idx]    ,			end=""""""   )
          print()




def       A_      (       lowercase   )  ->				list[list[int]]:


     """simple docstring"""







     if not isinstance(lowercase    ,			lowercase   ):
          raise TypeError("""The input value of 'num_rows' should be 'int'"""   )

     if num_rows == 0:
          return []
     elif num_rows < 0:
          raise ValueError(
              """The input value of 'num_rows' should be greater than or equal to 0"""   )

     UpperCAmelCase_    :     list[list[int]]            =	[]
     for current_row_idx in range(lowercase   ):
          UpperCAmelCase_    :     Optional[Any]            =	populate_current_row(lowercase    ,			lowercase   )
          triangle.append(lowercase   )
     return triangle




def       A_      (       lowercase    ,			lowercase   )  ->				list[int]:


     """simple docstring"""







     UpperCAmelCase_    :     List[Any]            =	[-1] * (current_row_idx + 1)
     # first and last elements of current row are equal to 1
     UpperCAmelCase_       ,UpperCAmelCase_    :     List[Any]            =	1, 1
     for current_col_idx in range(1    ,			lowercase   ):
          calculate_current_element(
              lowercase    ,			lowercase    ,			lowercase    ,			lowercase   )
     return current_row




def       A_      (       lowercase    ,			lowercase    ,			lowercase    ,			lowercase    ,			)  ->				None:


     """simple docstring"""







     UpperCAmelCase_    :     str            =	triangle[current_row_idx - 1][current_col_idx - 1]
     UpperCAmelCase_    :     int            =	triangle[current_row_idx - 1][current_col_idx]
     UpperCAmelCase_    :     Any            =	above_to_left_elt + above_to_right_elt




def       A_      (       lowercase   )  ->				list[list[int]]:


     """simple docstring"""







     if not isinstance(lowercase    ,			lowercase   ):
          raise TypeError("""The input value of 'num_rows' should be 'int'"""   )

     if num_rows == 0:
          return []
     elif num_rows < 0:
          raise ValueError(
              """The input value of 'num_rows' should be greater than or equal to 0"""   )

     UpperCAmelCase_    :     list[list[int]]            =	[[1]]

     for row_index in range(1    ,			lowercase   ):
          UpperCAmelCase_    :     Any            =	[0] + result[-1] + [0]
          UpperCAmelCase_    :     Union[str, Any]            =	row_index + 1
          # Calculate the number of distinct elements in a row
          UpperCAmelCase_    :     Dict            =	sum(divmod(lowercase    ,			2   )   )
          UpperCAmelCase_    :     List[str]            =	[
              temp_row[i - 1] + temp_row[i] for i in range(1    ,			distinct_elements + 1   )
          ]
          UpperCAmelCase_    :     Union[str, Any]            =	row_first_half[: (row_index + 1) // 2]
          row_second_half.reverse()
          UpperCAmelCase_    :     int            =	row_first_half + row_second_half
          result.append(lowercase   )

     return result




def       A_      (       )  ->				None:


     """simple docstring"""







     from collections.abc import Callable
     from timeit import timeit

     def benchmark_a_function(lowercase    ,			lowercase   ) -> None:
          UpperCAmelCase_    :     int            =	f'''{func.__name__}({value})'''
          UpperCAmelCase_    :     int            =	timeit(f'''__main__.{call}'''    ,			setup="""import __main__"""   )
          # print(f"{call:38} = {func(value)} -- {timing:.4f} seconds")
          print(f'''{call:38} -- {timing:.4f} seconds'''   )

     for value in range(15   ):  # (1, 7, 14):
          for func in (generate_pascal_triangle, generate_pascal_triangle_optimized):
               benchmark_a_function(lowercase    ,			lowercase   )
          print()


if __name__ == "__main__":
       import doctest

       doctest.testmod()
       benchmark()

