






"""simple docstring"""





import numpy as np
from numpy import floataa
from numpy.typing import NDArray



def      __lowercase       (     a			:					NDArray[floataa]							,		a			:					NDArray[floataa]			)       ->       NDArray[floataa]:
      __snake_case      ,					__snake_case   :     str	      =np.shape(a			)

      __snake_case   :     NDArray[floataa]	      =np.zeros((rows, 1)							,		dtype=a			)
      for row in reversed(range(a			)			):
            __snake_case   :     Optional[int]	      =0
            for col in range(row + 1							,		a			):
                  total += coefficients[row, col] * x[col]

            __snake_case   :     int	      =(vector[row] - total) / coefficients[row, row]

      return x



def      __lowercase       (     a			:					NDArray[floataa]							,		a			:					NDArray[floataa]			)       ->       NDArray[floataa]:
      __snake_case      ,					__snake_case   :     int	      =np.shape(a			)
      if rows != columns:
            return np.array(()							,		dtype=a			)

      # augmented matrix
      __snake_case   :     NDArray[floataa]	      =np.concatenate((coefficients, vector)							,		axis=1			)
      __snake_case   :     str	      =augmented_mat.astype('''float64'''			)

      # scale the matrix leaving it triangular
      for row in range(rows - 1			):
            __snake_case   :     Tuple	      =augmented_mat[row, row]
            for col in range(row + 1							,		a			):
                  __snake_case   :     Dict	      =augmented_mat[col, row] / pivot
                  augmented_mat[col, :] -= factor * augmented_mat[row, :]

      __snake_case   :     Optional[int]	      =retroactive_resolution(
          augmented_mat[:, 0:columns]							,		augmented_mat[:, columns : columns + 1]			)

      return x


if __name__ == "__main__":
    import doctest

    doctest.testmod()










"""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()


