



"""simple docstring"""






from __future__ import annotations

from PIL import Image

# Define glider example
__snake_case				:  Optional[int] =       [
    [0, 1, 0, 0, 0, 0, 0, 0],
    [0, 0, 1, 0, 0, 0, 0, 0],
    [1, 1, 1, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0],
]

# Define blinker example
__snake_case				:  Optional[int] =       [[0, 1, 0], [0, 1, 0], [0, 1, 0]]


def      _lowercase							(    __snake_case      )		->  list[list[int]]:
			__lowerCAmelCase :    List[Any]				=			[]
			for i in range(len(__snake_case      )      ):
						__lowerCAmelCase :    Dict				=			[]
						for j in range(len(cells[i]      )      ):
									# Get the number of live neighbours
									__lowerCAmelCase :    Dict				=			0
									if i > 0 and j > 0:
												neighbour_count += cells[i - 1][j - 1]
									if i > 0:
												neighbour_count += cells[i - 1][j]
									if i > 0 and j < len(cells[i]      ) - 1:
												neighbour_count += cells[i - 1][j + 1]
									if j > 0:
												neighbour_count += cells[i][j - 1]
									if j < len(cells[i]      ) - 1:
												neighbour_count += cells[i][j + 1]
									if i < len(__snake_case      ) - 1 and j > 0:
												neighbour_count += cells[i + 1][j - 1]
									if i < len(__snake_case      ) - 1:
												neighbour_count += cells[i + 1][j]
									if i < len(__snake_case      ) - 1 and j < len(cells[i]      ) - 1:
												neighbour_count += cells[i + 1][j + 1]

									# Rules of the game of life (excerpt from Wikipedia):
									# 1. Any live cell with two or three live neighbours survives.
									# 2. Any dead cell with three live neighbours becomes a live cell.
									# 3. All other live cells die in the next generation.
									#    Similarly, all other dead cells stay dead.
									__lowerCAmelCase :    str				=			cells[i][j] == 1
									if (
									    (alive and 2 <= neighbour_count <= 3)
									    or not alive
									    and neighbour_count == 3
									):
												next_generation_row.append(1      )
									else:
												next_generation_row.append(0      )

						next_generation.append(__snake_case      )
			return next_generation


def      _lowercase							(    __snake_case   ,__snake_case      )		->  list[Image.Image]:
			__lowerCAmelCase :    List[str]				=			[]
			for _ in range(__snake_case      ):
						# Create output image
						__lowerCAmelCase :    Any				=			Image.new("RGB"   ,(len(cells[0]      ), len(__snake_case      ))      )
						__lowerCAmelCase :    Optional[Any]				=			img.load()

						# Save cells to image
						for x in range(len(__snake_case      )      ):
									for y in range(len(cells[0]      )      ):
												__lowerCAmelCase :    Union[str, Any]				=			255 - cells[y][x] * 255
												__lowerCAmelCase :    Optional[Any]				=			(colour, colour, colour)

        # Save image
						images.append(__snake_case      )
						__lowerCAmelCase :    Any				=			new_generation(__snake_case      )
			return images


if __name__ == "__main__":
	__snake_case				:  Optional[Any] =       generate_images(GLIDER, 16)
	images[0].save('out.gif', save_all=True, append_images=images[1:])




"""simple docstring"""






def      _lowercase							(    __snake_case      )		->  float:
			return 10 - x * x


def      _lowercase							(    __snake_case   ,__snake_case      )		->  float:
			# Bolzano theory in order to find if there is a root between a and b
			if equation(__snake_case      ) * equation(__snake_case      ) >= 0:
						raise ValueError("Wrong space!"      )

			__lowerCAmelCase :    List[Any]				=			a
			while (b - a) >= 0.01:
						# Find middle point
						__lowerCAmelCase :    str				=			(a + b) / 2
						# Check if middle point is root
						if equation(__snake_case      ) == 0.0:
									break
						# Decide the side to repeat the steps
						if equation(__snake_case      ) * equation(__snake_case      ) < 0:
									__lowerCAmelCase :    List[Any]				=			c
						else:
									__lowerCAmelCase :    List[str]				=			c
			return c


if __name__ == "__main__":
	import doctest

	doctest.testmod()

	print(bisection(-2, 5))
	print(bisection(0, 6))