



'''simple docstring'''



from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
_lowercase       :						Dict						=[[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 							__UpperCAmelCase				(				UpperCamelCase__				:int			)		->						list[int]:
				return [int(UpperCamelCase__			) for c in F'''{ruleset:08}'''[:8]]


def 							__UpperCAmelCase				(				UpperCamelCase__				:list[list[int]]   ,				UpperCamelCase__				:list[int]   ,				UpperCamelCase__				:int			)		->						list[int]:
				snake_case__      :   Tuple      =    len(cells[0]			)  # 31
				snake_case__      :   Optional[Any]      =    []
				for i in range(UpperCamelCase__			):
								# Get the neighbors of each cell
								# Handle neighbours outside bounds by using 0 as their value
								snake_case__      :   Tuple      =    0 if i == 0 else cells[time][i - 1]
								snake_case__      :   Union[str, Any]      =    0 if i == population - 1 else cells[time][i + 1]
								# Define a new cell and add it to the new generation
								snake_case__      :   List[str]      =    7 - int(F'''{left_neighbor}{cells[time][i]}{right_neighbor}'''   ,				2			)
								next_generation.append(rule[situation]			)
				return next_generation


def 							__UpperCAmelCase				(				UpperCamelCase__				:list[list[int]]			)		->						Image.Image:
				snake_case__      :   List[str]      =    Image.new('''RGB'''   ,				(len(cells[0]			), len(UpperCamelCase__			))			)
				snake_case__      :   str      =    img.load()
				# Generates image
				for w in range(img.width			):
								for h in range(img.height			):
												snake_case__      :   Tuple      =    255 - int(255 * cells[h][w]			)
												snake_case__      :   Any      =    (color, color, color)
				return img


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











def   _lowercase       (    _UpperCAmelCase					)    ->	bool:
				if not isinstance(_UpperCAmelCase      ,   _UpperCAmelCase					):
								lowerCamelCase									=F"""Input value of [number={number}] must be an integer"""
								raise TypeError(_UpperCAmelCase					)
				if number < 0 or number % 2 == 1:
								return False
				lowerCamelCase									=int(number**0.5					)
				return number == number_sqrt * (number_sqrt + 1)


if __name__ == "__main__":
							import doctest

							doctest.testmod()





