





import re
import tempfile
import unittest
from pathlib import Path

from datasets.utils.metadata import DatasetMetadata






def 				_lowerCAmelCase			(	_a :       str      )						->      str:
     lowerCAmelCase_       :							List[str]			 =		min(re.search("""^ +"""       , _a      ).end() if t.startswith(""" """      ) else 0 for t in string.splitlines()      )
     return "\n".join([line[indent_level:] for line in string.splitlines() if indent_level < len(_a      )]      )


UpperCAmelCase_       : List[Any]							=    """\
---
language:
- zh
- en
task_ids:
- sentiment-classification
---
# Begin of markdown

Some cool dataset card
"""

UpperCAmelCase_       : Dict							=    """\
---
---
# Begin of markdown

Some cool dataset card
"""


UpperCAmelCase_       : Dict							=    """\
# Begin of markdown

Some cool dataset card
"""







class   lowercase__     (				unittest.TestCase	):







  def 						UpperCAmelCase__		(						self    ):







       with tempfile.TemporaryDirectory() as tmp_dir:
            lowerCAmelCase_       :							Tuple			 =		Path(_lowercase    ) / '''README.md'''
            with open(_lowercase     ,    """w+"""    ) as readme_file:
                 readme_file.write(_lowercase    )
            lowerCAmelCase_       :							List[Any]			 =		DatasetMetadata.from_readme(_lowercase    )
            self.assertDictEqual(_lowercase     ,    {"""language""": ["""zh""", """en"""], """task_ids""": ["""sentiment-classification"""]}    )

            with open(_lowercase     ,    """w+"""    ) as readme_file:
                 readme_file.write(_lowercase    )
            lowerCAmelCase_       :							List[str]			 =		DatasetMetadata.from_readme(_lowercase    )
            self.assertDictEqual(_lowercase     ,    {}    )

            with open(_lowercase     ,    """w+"""    ) as readme_file:
                 readme_file.write(_lowercase    )
            lowerCAmelCase_       :							Optional[int]			 =		DatasetMetadata.from_readme(_lowercase    )
            self.assertEqual(_lowercase     ,    {}    )







  def 						UpperCAmelCase__		(						self    ):
       lowerCAmelCase_       :							Tuple			 =		_dedent(
           """\
            annotations_creators:
            - found
            language_creators:
            - found
            language:
            - en
            license:
            - unknown
            multilinguality:
            - monolingual
            pretty_name: Test Dataset
            size_categories:
            - 10K<n<100K
            source_datasets:
            - extended|other-yahoo-webscope-l6
            task_categories:
            - question-answering
            task_ids:
            - open-domain-qa
            """    )
       assert DatasetMetadata.from_yaml_string(_lowercase    )

       lowerCAmelCase_       :							str			 =		_dedent(
           """\
            annotations_creators:
            - found
            language:
            - en
            license:
            - unknown
            multilinguality:
            - monolingual
            pretty_name: Test Dataset
            size_categories:
            - 10K<n<100K
            source_datasets:
            - extended|other-yahoo-webscope-l6
            task_categories:
            - question-answering
            task_ids:
            - open-domain-qa
            task_ids:
            - open-domain-qa
            """    )
       with self.assertRaises(_lowercase    ):
            DatasetMetadata.from_yaml_string(_lowercase    )

       lowerCAmelCase_       :							Optional[int]			 =		_dedent(
           """\
            annotations_creators:
            - found
            language_creators:
            - found
            language:
            - en
            license:
            - unknown
            multilinguality:
            - monolingual
            pretty_name: Test Dataset
            size_categories:
            - 10K<n<100K
            source_datasets:
            - extended|other-yahoo-webscope-l6
            task_categories:
            - text-classification
            task_ids:
            - multi-class-classification
            paperswithcode_id:
            - squad
            configs:
            - en
            train-eval-index:
            - config: en
              task: text-classification
              task_id: multi_class_classification
              splits:
                train_split: train
                eval_split: test
              col_mapping:
                text: text
                label: target
              metrics:
                - type: accuracy
                  name: Accuracy
            extra_gated_prompt: |
              By clicking on “Access repository” below, you also agree to ImageNet Terms of Access:
              [RESEARCHER_FULLNAME] (the \"Researcher\") has requested permission to use the ImageNet database (the \"Database\") at Princeton University and Stanford University. In exchange for such permission, Researcher hereby agrees to the following terms and conditions:
              1. Researcher shall use the Database only for non-commercial research and educational purposes.
            extra_gated_fields:
              Company: text
              Country: text
              I agree to use this model for non-commerical use ONLY: checkbox
            """    )
       assert DatasetMetadata.from_yaml_string(_lowercase    )








"""simple docstring"""





from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
UpperCamelCase_						:					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      __lowercase       (     a			:					int			)       ->       list[int]:
      return [int(a			) for c in f'''{ruleset:08}'''[:8]]



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



def      __lowercase       (     a			:					list[list[int]]			)       ->       Image.Image:
      __snake_case   :     int	      =Image.new('''RGB'''							,		(len(cells[0]			), len(a			))			)
      __snake_case   :     List[Any]	      =img.load()
      # Generates image
      for w in range(img.width			):
            for h in range(img.height			):
                  __snake_case   :     int	      =255 - int(255 * cells[h][w]			)
                  __snake_case   :     List[str]	      =(color, color, color)
      return img


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


