

def       a__					(		UpperCAmelCase							:      int      )  ->						None:
  UpperCAmelCase	:							Optional[Any]						=			generate_pascal_triangle(UpperCAmelCase      )
  for row_idx in range(UpperCAmelCase      ):
    # 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__					(		UpperCAmelCase							:      int      )  ->						list[list[int]]:

  if not isinstance(UpperCAmelCase    ,			UpperCAmelCase      ):
    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(UpperCAmelCase      ):
    UpperCAmelCase	:							List[str]						=			populate_current_row(UpperCAmelCase    ,			UpperCAmelCase      )
    triangle.append(UpperCAmelCase      )
  return triangle

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

def       a__					(		UpperCAmelCase							:      list[list[int]]    ,			UpperCAmelCase							:      list[int]    ,			UpperCAmelCase							:      int    ,			UpperCAmelCase							:      int    ,			)  ->						None:
  UpperCAmelCase	:							List[str]						=			triangle[current_row_idx - 1][current_col_idx - 1]
  UpperCAmelCase	:							Union[str, Any]						=			triangle[current_row_idx - 1][current_col_idx]
  UpperCAmelCase	:							Tuple						=			above_to_left_elt + above_to_right_elt

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

  if not isinstance(UpperCAmelCase    ,			UpperCAmelCase      ):
    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    ,			UpperCAmelCase      ):
    UpperCAmelCase	:							List[Any]						=			[0] + result[-1] + [0]
    UpperCAmelCase	:							Optional[int]						=			row_index + 1
    # Calculate the number of distinct elements in a row
    UpperCAmelCase	:							List[Any]						=			sum(divmod(UpperCAmelCase    ,			2      )      )
    UpperCAmelCase	:							Dict						=			[
        temp_row[i - 1] + temp_row[i] for i in range(1    ,			distinct_elements + 1      )
    ]
    UpperCAmelCase	:							int						=			row_first_half[: (row_index + 1) // 2]
    row_second_half.reverse()
    UpperCAmelCase	:							str						=			row_first_half + row_second_half
    result.append(UpperCAmelCase      )

  return result

def       a__					(		)  ->						None:
  from collections.abc import Callable
  from timeit import timeit

  def benchmark_a_function(UpperCAmelCase							:      Callable    ,			UpperCAmelCase							:      int      ) -> None:
    UpperCAmelCase	:							Optional[int]						=			f'''{func.__name__}({value})'''
    UpperCAmelCase	:							Tuple						=			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(UpperCAmelCase    ,			UpperCAmelCase      )
    print()


if __name__ == "__main__":
     import doctest

     doctest.testmod()
     benchmark()








from collections.abc import Callable
from math import pi, sqrt
from random import uniform
from statistics import mean

def       a__					(		UpperCAmelCase							:      int      )  ->						Dict:

  # A local function to see if a dot lands in the circle.
  def is_in_circle(UpperCAmelCase							:      float    ,			UpperCAmelCase							:      float      ) -> bool:
    UpperCAmelCase	:							Dict						=			sqrt((x**2) + (y**2)      )
    # Our circle has a radius of 1, so a distance
    # greater than 1 would land outside the circle.
    return distance_from_centre <= 1

  # The proportion of guesses that landed in the circle
  UpperCAmelCase	:							List[str]						=			mean(
      int(is_in_circle(uniform(-1.0    ,			1.0      )    ,			uniform(-1.0    ,			1.0      )      )      )
      for _ in range(UpperCAmelCase      )      )
  # The ratio of the area for circle to square is pi/4.
  UpperCAmelCase	:							int						=			proportion * 4
  print(f'''The estimated value of pi is {pi_estimate}'''      )
  print(f'''The numpy value of pi is {pi}'''      )
  print(f'''The total error is {abs(pi - pi_estimate      )}'''      )

def       a__					(		UpperCAmelCase							:      int    ,			UpperCAmelCase							:      Callable[[float], float]    ,			UpperCAmelCase							:      float = 0.0    ,			UpperCAmelCase							:      float = 1.0    ,			)  ->						float:
  return mean(
      function_to_integrate(uniform(UpperCAmelCase    ,			UpperCAmelCase      )      ) for _ in range(UpperCAmelCase      )      ) * (max_value - min_value)

def       a__					(		UpperCAmelCase							:      int    ,			UpperCAmelCase							:      float = 0.0    ,			UpperCAmelCase							:      float = 1.0      )  ->						None:

  def identity_function(UpperCAmelCase							:      float      ) -> float:
    return x

  UpperCAmelCase	:							int						=			area_under_curve_estimator(
      UpperCAmelCase    ,			UpperCAmelCase    ,			UpperCAmelCase    ,			UpperCAmelCase      )
  UpperCAmelCase	:							Tuple						=			(max_value * max_value - min_value * min_value) / 2

  print('''******************'''      )
  print(f'''Estimating area under y=x where x varies from {min_value} to {max_value}'''      )
  print(f'''Estimated value is {estimated_value}'''      )
  print(f'''Expected value is {expected_value}'''      )
  print(f'''Total error is {abs(estimated_value - expected_value      )}'''      )
  print('''******************'''      )

def       a__					(		UpperCAmelCase							:      int      )  ->						None:

  def function_to_integrate(UpperCAmelCase							:      float      ) -> float:
    return sqrt(4.0 - x * x      )

  UpperCAmelCase	:							Optional[int]						=			area_under_curve_estimator(
      UpperCAmelCase    ,			UpperCAmelCase    ,			0.0    ,			2.0      )

  print('''******************'''      )
  print('''Estimating pi using area_under_curve_estimator'''      )
  print(f'''Estimated value is {estimated_value}'''      )
  print(f'''Expected value is {pi}'''      )
  print(f'''Total error is {abs(estimated_value - pi      )}'''      )
  print('''******************'''      )


if __name__ == "__main__":
     import doctest

     doctest.testmod()





