




from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
snake_case_					:					Optional[int]       						=			[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]


def   A		(__A  :       int			)  -> list[int]:







     """simple docstring"""


     return [int(__A			) for c in F"""{ruleset:08}"""[:8]]


def   A		(__A  :       list[list[int]]  ,							__A  :       list[int]  ,							__A  :       int			)  -> list[int]:







     """simple docstring"""


     UpperCAmelCase_		=				len(cells[0]			)  # 31
     UpperCAmelCase_		=				[]
     for i in range(__A			):
          # Get the neighbors of each cell
          # Handle neighbours outside bounds by using 0 as their value
          UpperCAmelCase_		=				0 if i == 0 else cells[time][i - 1]
          UpperCAmelCase_		=				0 if i == population - 1 else cells[time][i + 1]
          # Define a new cell and add it to the new generation
          UpperCAmelCase_		=				7 - int(F"""{left_neighbor}{cells[time][i]}{right_neighbor}"""  ,							2			)
          next_generation.append(rule[situation]			)
     return next_generation


def   A		(__A  :       list[list[int]]			)  -> Image.Image:







     """simple docstring"""


     UpperCAmelCase_		=				Image.new('''RGB'''  ,							(len(cells[0]			), len(__A			))			)
     UpperCAmelCase_		=				img.load()
     # Generates image
     for w in range(img.width			):
          for h in range(img.height			):
               UpperCAmelCase_		=				255 - int(255 * cells[h][w]			)
               UpperCAmelCase_		=				(color, color, color)
     return img


if __name__ == "__main__":
    snake_case_					:					Optional[int]       						=			bin(int(input("Rule:\n").strip()))[2:]
    snake_case_					:					List[str]       						=			format_ruleset(int(rule_num))
    for time in range(16):
        CELLS.append(new_generation(CELLS, rule, time))
    snake_case_					:					List[str]       						=			generate_image(CELLS)
    # Uncomment to save the image
    # img.save(f"rule_{rule_num}.png")
    img.show()












def   A		(__A  :       int			)  -> int:







     """simple docstring"""


     if not isinstance(__A  ,							__A			):
          UpperCAmelCase_		=				F"""Input value of [number={number}] must be an integer"""
          raise TypeError(__A			)
     if number < 1:
          raise ValueError('''Input must be a positive integer'''			)
     return number * (2 * number - 1)


if __name__ == "__main__":
    import doctest

    doctest.testmod()






