


'''simple docstring'''






from __future__ import annotations

from PIL import Image

# Define glider example
a_   :      Union[str, Any]				    =      [
    [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
a_   :      Dict				    =      [[0, 1, 0], [0, 1, 0], [0, 1, 0]]






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




     '''simple docstring'''



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






def 		_A			(lowerCAmelCase__					:list[list[int]]			,  lowerCAmelCase__					:int						)				->					list[Image.Image]:




     '''simple docstring'''



     _a      =							[]
     for _ in range(lowerCAmelCase__						):
          # Create output image
          _a      =							Image.new('RGB'			,  (len(cells[0]						), len(lowerCAmelCase__						))						)
          _a      =							img.load()

          # Save cells to image
          for x in range(len(lowerCAmelCase__						)						):
               for y in range(len(cells[0]						)						):
                    _a      =							2_55 - cells[y][x] * 2_55
                    _a      =							(colour, colour, colour)

        # Save image
          images.append(lowerCAmelCase__						)
          _a      =							new_generation(lowerCAmelCase__						)
     return images


if __name__ == "__main__":
 a_   :      List[Any]				    =      generate_images(GLIDER, 1_6)
 images[0].save("out.gif", save_all=True, append_images=images[1:])





'''simple docstring'''






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




     '''simple docstring'''



     _a      =							len(lowerCAmelCase__						)
     print('The following activities are selected:'						)

     # The first activity is always selected
     _a      =							0
     print(lowerCAmelCase__			,  end=','						)

     # Consider rest of the activities
     for j in range(lowerCAmelCase__						):
          # If this activity has start time greater than
          # or equal to the finish time of previously
          # selected activity, then select it
          if start[j] >= finish[i]:
               print(lowerCAmelCase__			,  end=','						)
               _a      =							j


if __name__ == "__main__":
 import doctest

 doctest.testmod()

 a_   :      List[str]				    =      [1, 3, 0, 5, 8, 5]
 a_   :      str				    =      [2, 4, 6, 7, 9, 9]
 print_max_activities(start, finish)

