





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 string import ascii_uppercase

lowercase_					     =	{str(ord(c) - 55): c for c in ascii_uppercase}




def     __UpperCamelCase						(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	)       ->     str:
  if isinstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	):
    raise TypeError('int() can\'t convert non-string with explicit base'	)
  if num < 0:
    raise ValueError('parameter must be positive int'	)
  if isinstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	):
    raise TypeError('\'str\' object cannot be interpreted as an integer'	)
  if isinstance(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	):
    raise TypeError('\'float\' object cannot be interpreted as an integer'	)
  if base in (0, 1):
    raise ValueError('base must be >= 2'	)
  if base > 36:
    raise ValueError('base must be <= 36'	)
  lowercase__			    =						''
  lowercase__			    =						0
  lowercase__			    =						0
  while div != 1:
    lowercase__    ,					lowercase__			    =						divmod(_SCREAMING_SNAKE_CASE	,		_SCREAMING_SNAKE_CASE	)
    if base >= 11 and 9 < mod < 36:
      lowercase__			    =						ALPHABET_VALUES[str(_SCREAMING_SNAKE_CASE	)]
    else:
      lowercase__			    =						str(_SCREAMING_SNAKE_CASE	)
    new_value += actual_value
    lowercase__			    =						num // base
    lowercase__			    =						div
    if div == 0:
      return str(new_value[::-1]	)
    elif div == 1:
      new_value += str(_SCREAMING_SNAKE_CASE	)
      return str(new_value[::-1]	)

  return new_value[::-1]


if __name__ == "__main__":
      import doctest

      doctest.testmod()

      for base in range(2, 37):
            for num in range(1_000):
                  assert int(decimal_to_any(num, base), base) == num, (
                      num,
                      base,
                      decimal_to_any(num, base),
                      int(decimal_to_any(num, base), base),
                  )


