
from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
__lowerCAmelCase      :					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 a__   (	A_ ):






  '''simple docstring'''





  return [int(_lowerCAmelCase ) for c in f'''{ruleset:08}'''[:8]]

def a__   (	A_,					A_,					A_ ):






  '''simple docstring'''





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

def a__   (	A_ ):






  '''simple docstring'''





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


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



def a__   (	A_ ):






  '''simple docstring'''





  __magic_name__    					=	str(A_ ).strip()
  if not bin_string:
    raise ValueError("""Empty string was passed to the function""" )
  __magic_name__    					=	bin_string[0] == """-"""
  if is_negative:
    __magic_name__    					=	bin_string[1:]
  if not all(char in """01""" for char in bin_string ):
    raise ValueError("""Non-binary value was passed to the function""" )
  __magic_name__    					=	0
  for char in bin_string:
    __magic_name__    					=	2 * decimal_number + int(A_ )
  return -decimal_number if is_negative else decimal_number


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

    testmod()

