



'''simple docstring'''




from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
UpperCamelCase__	:     Optional[int]				  =			[[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_       (     _lowerCamelCase:       int ):
		return [int(SCREAMING_SNAKE_CASE_ ) for c in F"{ruleset:08}"[:8]]


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


def     lowerCAmelCase_       (     _lowerCamelCase:       list[list[int]] ):
		__SCREAMING_SNAKE_CASE	:		Tuple   	=		Image.new("""RGB"""	,				(len(cells[0] ), len(SCREAMING_SNAKE_CASE_ )) )
		__SCREAMING_SNAKE_CASE	:		Optional[int]   	=		img.load()
		# Generates image
		for w in range(img.width ):
				for h in range(img.height ):
						__SCREAMING_SNAKE_CASE	:		List[Any]   	=		2_55 - int(2_55 * cells[h][w] )
						__SCREAMING_SNAKE_CASE	:		Optional[int]   	=		(color, color, color)
		return img


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




'''simple docstring'''




import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin






class 						_UpperCamelCase  (							lowerCamelCase__   ):


			'''simple docstring'''

			_A				:		int         =		['''image_processor''', '''tokenizer''']
			_A				:		Union[str, Any]         =		'''AutoImageProcessor'''
			_A				:		Optional[Any]         =		'''AutoTokenizer'''

			def __init__(							self					:			Tuple							,					lowerCAmelCase__					:			Tuple=None							,					lowerCAmelCase__					:			Union[str, Any]=None							,					**lowerCAmelCase__					:			Any						):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE	:		Tuple   	=		None
					if "feature_extractor" in kwargs:
							warnings.warn(
							    """The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"""
							    """ instead."""							,					lowerCAmelCase__							,					)
							__SCREAMING_SNAKE_CASE	:		str   	=		kwargs.pop("""feature_extractor"""						)

					__SCREAMING_SNAKE_CASE	:		Any   	=		image_processor if image_processor is not None else feature_extractor
					if image_processor is None:
							raise ValueError("""You need to specify an `image_processor`."""						)
					if tokenizer is None:
							raise ValueError("""You need to specify a `tokenizer`."""						)

					super().__init__(lowerCAmelCase__							,					lowerCAmelCase__						)
					__SCREAMING_SNAKE_CASE	:		List[str]   	=		self.image_processor
					__SCREAMING_SNAKE_CASE	:		Dict   	=		False

			def __call__(							self					:			List[str]							,					*lowerCAmelCase__					:			List[str]							,					**lowerCAmelCase__					:			Dict						):





					"""simple docstring"""






					if self._in_target_context_manager:
							return self.current_processor(*lowerCAmelCase__							,					**lowerCAmelCase__						)

					__SCREAMING_SNAKE_CASE	:		Optional[Any]   	=		kwargs.pop("""images"""							,					lowerCAmelCase__						)
					__SCREAMING_SNAKE_CASE	:		Union[str, Any]   	=		kwargs.pop("""text"""							,					lowerCAmelCase__						)
					if len(lowerCAmelCase__						) > 0:
							__SCREAMING_SNAKE_CASE	:		Tuple   	=		args[0]
							__SCREAMING_SNAKE_CASE	:		int   	=		args[1:]

					if images is None and text is None:
							raise ValueError("""You need to specify either an `images` or `text` input to process."""						)

					if images is not None:
							__SCREAMING_SNAKE_CASE	:		List[str]   	=		self.image_processor(lowerCAmelCase__							,					*lowerCAmelCase__							,					**lowerCAmelCase__						)
					if text is not None:
							__SCREAMING_SNAKE_CASE	:		Optional[int]   	=		self.tokenizer(lowerCAmelCase__							,					**lowerCAmelCase__						)

					if text is None:
							return inputs
					elif images is None:
							return encodings
					else:
							__SCREAMING_SNAKE_CASE	:		int   	=		encodings["""input_ids"""]
							return inputs

			def UpperCamelCase__ (							self					:			Any							,					*lowerCAmelCase__					:			Any							,					**lowerCAmelCase__					:			List[str]						):





					"""simple docstring"""






					return self.tokenizer.batch_decode(*lowerCAmelCase__							,					**lowerCAmelCase__						)

			def UpperCamelCase__ (							self					:			int							,					*lowerCAmelCase__					:			str							,					**lowerCAmelCase__					:			Dict						):





					"""simple docstring"""






					return self.tokenizer.decode(*lowerCAmelCase__							,					**lowerCAmelCase__						)

			@contextmanager
			def UpperCamelCase__ (							self					:			Union[str, Any]						):





					"""simple docstring"""






					warnings.warn(
					    """`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your """
					    """labels by using the argument `text` of the regular `__call__` method (either in the same call as """
					    """your images inputs, or in a separate call."""						)
					__SCREAMING_SNAKE_CASE	:		List[Any]   	=		True
					__SCREAMING_SNAKE_CASE	:		Optional[Any]   	=		self.tokenizer
					yield
					__SCREAMING_SNAKE_CASE	:		Union[str, Any]   	=		self.image_processor
					__SCREAMING_SNAKE_CASE	:		List[str]   	=		False

			@property
			def UpperCamelCase__ (							self					:			Optional[Any]						):





					"""simple docstring"""






					warnings.warn(
					    """`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."""							,					lowerCAmelCase__							,					)
					return self.image_processor_class



			@property
			def UpperCamelCase__ (							self					:			List[Any]						):





					"""simple docstring"""






					warnings.warn(
					    """`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."""							,					lowerCAmelCase__							,					)
					return self.image_processor