





from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


A__:  Tuple       					=					{
    '''configuration_musicgen''': [
        '''MUSICGEN_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''MusicgenConfig''',
        '''MusicgenDecoderConfig''',
    ],
    '''processing_musicgen''': ['''MusicgenProcessor'''],
}

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      A__:  Any       					=					[
          '''MUSICGEN_PRETRAINED_MODEL_ARCHIVE_LIST''',
          '''MusicgenForConditionalGeneration''',
          '''MusicgenForCausalLM''',
          '''MusicgenModel''',
          '''MusicgenPreTrainedModel''',
      ]

if TYPE_CHECKING:
      from .configuration_musicgen import (
          MUSICGEN_PRETRAINED_CONFIG_ARCHIVE_MAP,
          MusicgenConfig,
          MusicgenDecoderConfig,
      )
      from .processing_musicgen import MusicgenProcessor

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_musicgen import (
                MUSICGEN_PRETRAINED_MODEL_ARCHIVE_LIST,
                MusicgenForCausalLM,
                MusicgenForConditionalGeneration,
                MusicgenModel,
                MusicgenPreTrainedModel,
            )

else:
      import sys

      A__:  List[Any]       					=					_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)








from __future__ import annotations

from PIL import Image

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



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



def 							lowerCAmelCase_				(    A_):
    UpperCamelCase__:					int												=      Image.new("RGB"  ,(len(cells[0]), len(A_)))
    UpperCamelCase__:					Dict												=      img.load()
    # Generates image
    for w in range(img.width):
        for h in range(img.height):
            UpperCamelCase__:					List[str]												=      2_55 - int(2_55 * cells[h][w])
            UpperCamelCase__:					Union[str, Any]												=      (color, color, color)
    return img


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

