
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 							UpperCAmelCase_		(							__SCREAMING_SNAKE_CASE							):
	return [int(__SCREAMING_SNAKE_CASE							) for c in F'''{ruleset:08}'''[:8]]






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






def 							UpperCAmelCase_		(							__SCREAMING_SNAKE_CASE							):
	lowercase					  =   Image.new('RGB'			,							(len(cells[0]							), len(__SCREAMING_SNAKE_CASE							))							)
	lowercase					  =   img.load()
	# Generates image
	for w in range(img.width							):
		for h in range(img.height							):
			lowercase					  =   255 - int(255 * cells[h][w]							)
			lowercase					  =   (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()



from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


UpperCAmelCase     				=			{
    '''configuration_dpr''': ['''DPR_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''DPRConfig'''],
    '''tokenization_dpr''': [
        '''DPRContextEncoderTokenizer''',
        '''DPRQuestionEncoderTokenizer''',
        '''DPRReaderOutput''',
        '''DPRReaderTokenizer''',
    ],
}


try:
	if not is_tokenizers_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	UpperCAmelCase     				=			[
	    '''DPRContextEncoderTokenizerFast''',
	    '''DPRQuestionEncoderTokenizerFast''',
	    '''DPRReaderTokenizerFast''',
	]

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	UpperCAmelCase     				=			[
	    '''DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''DPRContextEncoder''',
	    '''DPRPretrainedContextEncoder''',
	    '''DPRPreTrainedModel''',
	    '''DPRPretrainedQuestionEncoder''',
	    '''DPRPretrainedReader''',
	    '''DPRQuestionEncoder''',
	    '''DPRReader''',
	]

try:
	if not is_tf_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	UpperCAmelCase     				=			[
	    '''TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST''',
	    '''TFDPRContextEncoder''',
	    '''TFDPRPretrainedContextEncoder''',
	    '''TFDPRPretrainedQuestionEncoder''',
	    '''TFDPRPretrainedReader''',
	    '''TFDPRQuestionEncoder''',
	    '''TFDPRReader''',
	]


if TYPE_CHECKING:
	from .configuration_dpr import DPR_PRETRAINED_CONFIG_ARCHIVE_MAP, DPRConfig
	from .tokenization_dpr import (
	    DPRContextEncoderTokenizer,
	    DPRQuestionEncoderTokenizer,
	    DPRReaderOutput,
	    DPRReaderTokenizer,
	)

	try:
		if not is_tokenizers_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .tokenization_dpr_fast import (
		    DPRContextEncoderTokenizerFast,
		    DPRQuestionEncoderTokenizerFast,
		    DPRReaderTokenizerFast,
		)

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_dpr import (
		    DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
		    DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
		    DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
		    DPRContextEncoder,
		    DPRPretrainedContextEncoder,
		    DPRPreTrainedModel,
		    DPRPretrainedQuestionEncoder,
		    DPRPretrainedReader,
		    DPRQuestionEncoder,
		    DPRReader,
		)

	try:
		if not is_tf_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_tf_dpr import (
		    TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
		    TFDPRContextEncoder,
		    TFDPRPretrainedContextEncoder,
		    TFDPRPretrainedQuestionEncoder,
		    TFDPRPretrainedReader,
		    TFDPRQuestionEncoder,
		    TFDPRReader,
		)

else:
	import sys

	UpperCAmelCase     				=			_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)

