



import qiskit
from qiskit.providers import Backend


def 	_UpperCAmelCase       (   snake_case			,		snake_case    ):





     """simple docstring"""

     _lowerCAmelCase			,			_lowerCAmelCase      			=					bin(snake_case    )[2:], bin(snake_case    )[2:]  # Remove leading '0b'

     # Ensure that both strings are of the same length
     if len(snake_case    ) > len(snake_case    ):
          _lowerCAmelCase      			=					y.zfill(len(snake_case    )    )
     else:
          _lowerCAmelCase      			=					x.zfill(len(snake_case    )    )

     # We need (3 * number of bits in the larger number)+1 qBits
     # The second parameter is the number of classical registers, to measure the result
     _lowerCAmelCase      			=					qiskit.QuantumCircuit((len(snake_case    ) * 3) + 1			,		len(snake_case    ) + 1    )

     # We are essentially "not-ing" the bits that are 1
     # Reversed because it's easier to perform ops on more significant bits
     for i in range(len(snake_case    )    ):
          if x[::-1][i] == "1":
               circuit.x(snake_case    )
     for j in range(len(snake_case    )    ):
          if y[::-1][j] == "1":
               circuit.x(len(snake_case    ) + j    )

     return circuit, x, y


def 	_UpperCAmelCase       (   snake_case			,		snake_case			,		snake_case			,		snake_case			,		snake_case			,		):





     """simple docstring"""

     circuit.ccx(snake_case			,		snake_case			,		snake_case    )
     circuit.cx(snake_case			,		snake_case    )
     circuit.ccx(snake_case			,		snake_case			,		snake_case    )
     circuit.cx(snake_case			,		snake_case    )
     circuit.cx(snake_case			,		snake_case    )


def 	_UpperCAmelCase       (   snake_case			,		snake_case			,		snake_case = qiskit.Aer.get_backend("""aer_simulator"""    )			,		):





     """simple docstring"""

     if vala < 0 or vala < 0:
          raise ValueError("""Both Integers must be positive!"""    )

     # Store the Integers
     _lowerCAmelCase			,			_lowerCAmelCase			,			_lowerCAmelCase      			=					store_two_classics(snake_case			,		snake_case    )
     for i in range(len(snake_case    )    ):
          full_adder(snake_case			,		snake_case			,		len(snake_case    ) + i			,		len(snake_case    ) + len(snake_case    ) + i			,		len(snake_case    ) + len(snake_case    ) + i + 1    )
          circuit.barrier()  # Optional, just for aesthetics

     # Measure the resultant qBits
     for i in range(len(snake_case    ) + 1    ):
          circuit.measure([(len(snake_case    ) * 2) + i]			,		[i]    )

     _lowerCAmelCase      			=					qiskit.execute(snake_case			,		snake_case			,		shots=1    ).result()

     # The result is in binary. Convert it back to int
     return int(list(res.get_counts()    )[0]			,		2    )


if __name__ == "__main__":
 import doctest

 doctest.testmod()








from __future__ import annotations

from PIL import Image

# Define the first generation of cells
# fmt: off
A__			   = [[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 	_UpperCAmelCase       (   snake_case    ):





					"""simple docstring"""

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


def 	_UpperCAmelCase       (   snake_case			,		snake_case			,		snake_case    ):





					"""simple docstring"""

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


def 	_UpperCAmelCase       (   snake_case    ):





					"""simple docstring"""

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


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



