






from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
__snake_case     :     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 						_UpperCamelCase (     UpperCamelCase_							:       Union[str, Any]		)	-> Optional[int]:

						"""simple docstring"""



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







def 						_UpperCamelCase (     UpperCamelCase_							:       Dict     ,							UpperCamelCase_							:       List[Any]     ,							UpperCamelCase_							:       Any		)	-> str:

						"""simple docstring"""



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







def 						_UpperCamelCase (     UpperCamelCase_							:       Dict		)	-> Any:

						"""simple docstring"""



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


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







"""simple docstring"""

def 						UpperCAmelCase   (						a_     ):





		'''simple docstring'''


		if not isinstance(a_,		a_     ):
				raise TypeError('recursive_lucas_number accepts only integer arguments.'     )
		if n_th_number == 0:
				return 2
		if n_th_number == 1:
				return 1

		return recursive_lucas_number(n_th_number - 1     ) + recursive_lucas_number(
		    n_th_number - 2     )
def 						UpperCAmelCase   (						a_     ):





		'''simple docstring'''


		if not isinstance(a_,		a_     ):
				raise TypeError('dynamic_lucas_number accepts only integer arguments.'     )
		lowerCamelCase      ,       lowerCamelCase	:     Optional[int]            =       2, 1
		for _ in range(a_     ):
				lowerCamelCase      ,       lowerCamelCase	:     Optional[int]            =       b, a + b
		return a


if __name__ == "__main__":
					from doctest import testmod

					testmod()
					_A				=					int(input('Enter the number of terms in lucas series:\n').strip())
					print('Using recursive function to calculate lucas series:')
					print(' '.join(str(recursive_lucas_number(i)) for i in range(n)))
					print('\nUsing dynamic function to calculate lucas series:')
					print(' '.join(str(dynamic_lucas_number(i)) for i in range(n)))






