





import colorsys

from PIL import Image  # type: ignore

def 	lowerCAmelCase__			(      a__:		float      ,  a__:		float      ,  a__:		int	)  ->		float:


							'''simple docstring'''





							_UpperCAmelCase					=      x
							_UpperCAmelCase					=      y
							for step in range(lowerCAmelCase__	):  # noqa: B007
														_UpperCAmelCase					=      a * a - b * b + x
														_UpperCAmelCase					=      2 * a * b + y
														_UpperCAmelCase					=      a_new

														# divergence happens for all complex number with an absolute value
														# greater than 4
														if a * a + b * b > 4:
																					break
							return step / (max_step - 1)

def 	lowerCAmelCase__			(      a__:		float	)  ->		tuple:


							'''simple docstring'''





							if distance == 1:
														return (0, 0, 0)
							else:
														return (2_5_5, 2_5_5, 2_5_5)

def 	lowerCAmelCase__			(      a__:		float	)  ->		tuple:


							'''simple docstring'''





							if distance == 1:
														return (0, 0, 0)
							else:
														return tuple(round(i * 2_5_5	) for i in colorsys.hsv_to_rgb(lowerCAmelCase__      ,  1      ,  1	)	)

def 	lowerCAmelCase__			(      a__:		int = 8_0_0      ,  a__:		int = 6_0_0      ,  a__:		float = -0.6      ,  a__:		float = 0      ,  a__:		float = 3.2      ,  a__:		int = 5_0      ,  a__:		bool = True      ,  )  ->		Image.Image:


							'''simple docstring'''





							_UpperCAmelCase					=      Image.new('RGB'      ,  (image_width, image_height)	)
							_UpperCAmelCase					=      img.load()

							# loop through the image-coordinates
							for image_x in range(lowerCAmelCase__	):
														for image_y in range(lowerCAmelCase__	):
																					# determine the figure-coordinates based on the image-coordinates
																					_UpperCAmelCase					=      figure_width / image_width * image_height
																					_UpperCAmelCase					=      figure_center_x + (image_x / image_width - 0.5) * figure_width
																					_UpperCAmelCase					=      figure_center_y + (image_y / image_height - 0.5) * figure_height

																					_UpperCAmelCase					=      get_distance(lowerCAmelCase__      ,  lowerCAmelCase__      ,  lowerCAmelCase__	)

																					# color the corresponding pixel based on the selected coloring-function
																					if use_distance_color_coding:
																												_UpperCAmelCase					=      get_color_coded_rgb(lowerCAmelCase__	)
																					else:
																												_UpperCAmelCase					=      get_black_and_white_rgb(lowerCAmelCase__	)

							return img


if __name__ == "__main__":
		import doctest

		doctest.testmod()

		# colored version, full figure
		lowerCAmelCase__  :Optional[Any]             =							get_image()

		# uncomment for colored version, different section, zoomed in
		# img = get_image(figure_center_x = -0.6, figure_center_y = -0.4,
		# figure_width = 0.8)

		# uncomment for black and white version, full figure
		# img = get_image(use_distance_color_coding = False)

		# uncomment to save the image
		# img.save("mandelbrot.png")

		img.show()




def 	lowerCAmelCase__			(      a__:		int	)  ->		None:


							'''simple docstring'''





							_UpperCAmelCase					=      generate_pascal_triangle(a__	)
							for row_idx in range(a__	):
														# 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 	lowerCAmelCase__			(      a__:		int	)  ->		list[list[int]]:


							'''simple docstring'''





							if not isinstance(a__      ,  a__	):
														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					=      []
							for current_row_idx in range(a__	):
														_UpperCAmelCase					=      populate_current_row(a__      ,  a__	)
														triangle.append(a__	)
							return triangle

def 	lowerCAmelCase__			(      a__:		list[list[int]]      ,  a__:		int	)  ->		list[int]:


							'''simple docstring'''





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

def 	lowerCAmelCase__			(      a__:		list[list[int]]      ,  a__:		list[int]      ,  a__:		int      ,  a__:		int      ,  )  ->		None:


							'''simple docstring'''





							_UpperCAmelCase					=      triangle[current_row_idx - 1][current_col_idx - 1]
							_UpperCAmelCase					=      triangle[current_row_idx - 1][current_col_idx]
							_UpperCAmelCase					=      above_to_left_elt + above_to_right_elt

def 	lowerCAmelCase__			(      a__:		int	)  ->		list[list[int]]:


							'''simple docstring'''





							if not isinstance(a__      ,  a__	):
														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					=      [[1]]

							for row_index in range(1      ,  a__	):
														_UpperCAmelCase					=      [0] + result[-1] + [0]
														_UpperCAmelCase					=      row_index + 1
														# Calculate the number of distinct elements in a row
														_UpperCAmelCase					=      sum(divmod(a__      ,  2	)	)
														_UpperCAmelCase					=      [
														    temp_row[i - 1] + temp_row[i] for i in range(1      ,  distinct_elements + 1	)
														]
														_UpperCAmelCase					=      row_first_half[: (row_index + 1) // 2]
														row_second_half.reverse()
														_UpperCAmelCase					=      row_first_half + row_second_half
														result.append(a__	)

							return result

def 	lowerCAmelCase__			(      )  ->		None:


							'''simple docstring'''





							from collections.abc import Callable
							from timeit import timeit

							def benchmark_a_function(a__:		Callable      ,  a__:		int	) -> None:
														_UpperCAmelCase					=      F'''{func.__name__}({value})'''
														_UpperCAmelCase					=      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(1_5	):  # (1, 7, 14):
														for func in (generate_pascal_triangle, generate_pascal_triangle_optimized):
																					benchmark_a_function(a__      ,  a__	)
														print()


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		benchmark()
