





from __future__ import annotations

from PIL import Image

# Define glider example
lowercase_					     =	[
    [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
lowercase_					     =	[[0, 1, 0], [0, 1, 0], [0, 1, 0]]




def     __UpperCamelCase						(_SCREAMING_SNAKE_CASE	)       ->     list[list[int]]:
  lowercase__			    =						[]
  for i in range(len(_SCREAMING_SNAKE_CASE	)	):
    lowercase__			    =						[]
    for j in range(len(cells[i]	)	):
      # Get the number of live neighbours
      lowercase__			    =						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(_SCREAMING_SNAKE_CASE	) - 1 and j > 0:
        neighbour_count += cells[i + 1][j - 1]
      if i < len(_SCREAMING_SNAKE_CASE	) - 1:
        neighbour_count += cells[i + 1][j]
      if i < len(_SCREAMING_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.
      lowercase__			    =						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(_SCREAMING_SNAKE_CASE	)
  return next_generation




def     __UpperCamelCase						(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	)       ->     list[Image.Image]:
  lowercase__			    =						[]
  for _ in range(_SCREAMING_SNAKE_CASE	):
    # Create output image
    lowercase__			    =						Image.new('RGB'	,		(len(cells[0]	), len(_SCREAMING_SNAKE_CASE	))	)
    lowercase__			    =						img.load()

    # Save cells to image
    for x in range(len(_SCREAMING_SNAKE_CASE	)	):
      for y in range(len(cells[0]	)	):
        lowercase__			    =						255 - cells[y][x] * 255
        lowercase__			    =						(colour, colour, colour)

        # Save image
    images.append(_SCREAMING_SNAKE_CASE	)
    lowercase__			    =						new_generation(_SCREAMING_SNAKE_CASE	)
  return images


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









from __future__ import annotations

import math
from collections.abc import Callable




def     __UpperCamelCase						(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE = 100	,		)       ->     float:
  lowercase__			    =						x_start
  lowercase__			    =						fnc(_SCREAMING_SNAKE_CASE	)
  lowercase__			    =						0.0

  for _ in range(_SCREAMING_SNAKE_CASE	):
    # Approximates curve as a sequence of linear lines and sums their length
    lowercase__			    =						(x_end - x_start) / steps + xa
    lowercase__			    =						fnc(_SCREAMING_SNAKE_CASE	)
    length += math.hypot(xa - xa	,		fxa - fxa	)

    # Increment step
    lowercase__			    =						xa
    lowercase__			    =						fxa

  return length


if __name__ == "__main__":




      def     __UpperCamelCase						(_SCREAMING_SNAKE_CASE	)       ->     str:
        return math.sin(10 * x	)

      print("""f(x) = sin(10 * x)""")
      print("""The length of the curve from x = -10 to x = 10 is:""")
      lowercase_					     =	10
      while i <= 100_000:
            print(f'''With {i} steps: {line_length(f, -10, 10, i)}''')
            i *= 10


