



'''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 			snake_case_					( _lowerCAmelCase  :						int  )				->       list[int]:
							return [int(_lowerCAmelCase  ) for c in f"""{ruleset:08}"""[:8]]


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


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


if __name__ == "__main__":
						UpperCamelCase__:       Any							     =      bin(int(input("Rule:\n").strip()))[2:]
						UpperCamelCase__:       Any							     =      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()










'''simple docstring'''






UpperCamelCase__:       Any							     =      [[0, 1, 1], [0, 0, 1], [1, 0, 0]]

class     SCREAMING_SNAKE_CASE:







	"""simple docstring"""






	def __init__(						self      :					List[str]		,      __snake_case      :					int		)      ->		int:
								UpperCAmelCase			:	Any										=		name
								UpperCAmelCase			:	Optional[Any]										=		[]
								UpperCAmelCase			:	Any										=		[]







	def 					A     (						self      :					Dict		,      __snake_case      :					str		)      ->		Tuple:
								self.inbound.append(__snake_case		)







	def 					A     (						self      :					Union[str, Any]		,      __snake_case      :					str		)      ->		Optional[int]:
								self.outbound.append(__snake_case		)







	def __repr__(						self      :					Optional[int]		)      ->		Optional[int]:
								return F"""<node={self.name} inbound={self.inbound} outbound={self.outbound}>"""


def 			snake_case_					( _lowerCAmelCase  :						Tuple       ,				_lowerCAmelCase  :						Dict=3       ,				_lowerCAmelCase  :						Tuple=0.8_5  )				->       Optional[Any]:
							UpperCAmelCase			:	Tuple										=		{}
							for node in nodes:
														UpperCAmelCase			:	List[str]										=		1

							UpperCAmelCase			:	List[Any]										=		{}
							for node in nodes:
														UpperCAmelCase			:	str										=		len(node.outbound  )

							for i in range(_lowerCAmelCase  ):
														print(f"""======= Iteration {i + 1} ======="""  )
														for _, node in enumerate(_lowerCAmelCase  ):
																					UpperCAmelCase			:	str										=		(1 - d) + d * sum(
																					    ranks[ib] / outbounds[ib] for ib in node.inbound  )
														print(_lowerCAmelCase  )


def 			snake_case_					( )				->       List[str]:
							UpperCAmelCase			:	str										=		list(input('''Enter Names of the Nodes: '''  ).split()  )

							UpperCAmelCase			:	Dict										=		[Node(_lowerCAmelCase  ) for name in names]

							for ri, row in enumerate(_lowerCAmelCase  ):
														for ci, col in enumerate(_lowerCAmelCase  ):
																					if col == 1:
																												nodes[ci].add_inbound(names[ri]  )
																												nodes[ri].add_outbound(names[ci]  )

							print('''======= Nodes ======='''  )
							for node in nodes:
														print(_lowerCAmelCase  )

							page_rank(_lowerCAmelCase  )


if __name__ == "__main__":
						main()





