
from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
_UpperCAmelCase   :					List[str]    =			[[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			(   lowercase					)  ->    list[int]:
		'''simple docstring'''

		return [int(lowercase					) for c in f'''{ruleset:08}'''[:8]]


def  A			(   lowercase       ,			lowercase       ,			lowercase					)  ->    list[int]:
		'''simple docstring'''

		UpperCamelCase            =	len(cells[0]					)  # 31
		UpperCamelCase            =	[]
		for i in range(lowercase					):
				# 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			(   lowercase					)  ->    Image.Image:
		'''simple docstring'''

		UpperCamelCase            =	Image.new('RGB'       ,			(len(cells[0]					), len(lowercase					))					)
		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__":
					_UpperCAmelCase   :					Dict    =			bin(int(input("Rule:\n").strip()))[2:]
					_UpperCAmelCase   :					Any    =			format_ruleset(int(rule_num))
					for time in range(16):
										CELLS.append(new_generation(CELLS, rule, time))
					_UpperCAmelCase   :					Dict    =			generate_image(CELLS)
					# Uncomment to save the image
					# img.save(f"rule_{rule_num}.png")
					img.show()


def  A			(   lowercase					)  ->    int:
		'''simple docstring'''

		return int(lowercase					) if x - int(lowercase					) >= 0 else int(lowercase					) - 1


if __name__ == "__main__":
					import doctest

					doctest.testmod()
