





'''simple docstring'''




from __future__ import annotations

from PIL import Image

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




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




def 						snake_case__    ( lowerCamelCase__				:   list[list[int]]			)   ->   Image.Image:
					A_ :     Dict =							Image.new('''RGB'''			,		(len(cells[0]			), len(lowerCamelCase__			))			)
					A_ :     Tuple =							img.load()
					# Generates image
					for w in range(img.width			):
										for h in range(img.height			):
															A_ :     List[Any] =							2_5_5 - int(2_5_5 * cells[h][w]			)
															A_ :     Optional[Any] =							(color, color, color)
					return img


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









'''simple docstring'''




def 						snake_case__    ( lowerCamelCase__				:   int			)   ->   bool:
					if not isinstance(lowerCamelCase__			,		lowerCamelCase__			):
										A_ :     int =							f'Input value of [number={number}] must be an integer'
										raise TypeError(lowerCamelCase__			)
					if number < 0 or number % 2 == 1:
										return False
					A_ :     Dict =							int(number**0.5			)
					return number == number_sqrt * (number_sqrt + 1)


if __name__ == "__main__":
							import doctest

							doctest.testmod()



