from __future__ import annotations

from PIL import Image

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

def  lowerCAmelCase_      (_SCREAMING_SNAKE_CASE	:str		,			_SCREAMING_SNAKE_CASE	:List[Any]		,			_SCREAMING_SNAKE_CASE	:Optional[Any]  )				-> Tuple:
						a_							:			Tuple     		=					len(cells[0]  )  # 31
						a_							:			Optional[int]     		=					[]
						for i in range(UpperCamelCase__  ):
												# Get the neighbors of each cell
												# Handle neighbours outside bounds by using 0 as their value
												a_							:			Optional[Any]     		=					0 if i == 0 else cells[time][i - 1]
												a_							:			Optional[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  lowerCAmelCase_      (_SCREAMING_SNAKE_CASE	:Any  )				-> int:
						a_							:			List[str]     		=					Image.new("RGB"		,			(len(cells[0]  ), len(UpperCamelCase__  ))  )
						a_							:			str     		=					img.load()
						# Generates image
						for w in range(img.width  ):
												for h in range(img.height  ):
																		a_							:			int     		=					255 - int(255 * cells[h][w]  )
																		a_							:			Any     		=					(color, color, color)
						return img


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





"""simple docstring"""






def  lowerCAmelCase_      (_SCREAMING_SNAKE_CASE	:str  )				-> int:
						a_							:			Optional[int]     		=					0
						for letter in data:
												a_							:			Union[str, Any]     		=					(hash_ << 4) + ord(_SCREAMING_SNAKE_CASE  )
												a_							:			Optional[int]     		=					hash_ & 0xf000_0000
												if x != 0:
																		hash_ ^= x >> 24
												hash_ &= ~x
						return hash_


if __name__ == "__main__":
				import doctest

				doctest.testmod()




