






from __future__ import annotations

from collections.abc import Sequence
from typing import Literal


def        __lowercase    (  UpperCAmelCase__		,					UpperCAmelCase__      ):

					"""simple docstring"""






					__lowerCAmelCase					=							list(UpperCAmelCase__      )
					__lowerCAmelCase					=							list(UpperCAmelCase__      )
					__lowerCAmelCase					=							0
					for i in range(len(UpperCAmelCase__      )      ):
										if lista[i] != lista[i]:
															count += 1
															__lowerCAmelCase					=							'_'
					if count > 1:
										return False
					else:
										return "".join(UpperCAmelCase__      )


def        __lowercase    (  UpperCAmelCase__      ):

					"""simple docstring"""






					__lowerCAmelCase					=							[]
					while True:
										__lowerCAmelCase					=							['$'] * len(UpperCAmelCase__      )
										__lowerCAmelCase					=							[]
										for i in range(len(UpperCAmelCase__      )      ):
															for j in range(i + 1		,					len(UpperCAmelCase__      )      ):
																				__lowerCAmelCase					=							compare_string(binary[i]		,					binary[j]      )
																				if k is False:
																									__lowerCAmelCase					=							'*'
																									__lowerCAmelCase					=							'*'
																									temp.append('X'      )
										for i in range(len(UpperCAmelCase__      )      ):
															if checka[i] == "$":
																				pi.append(binary[i]      )
										if len(UpperCAmelCase__      ) == 0:
															return pi
										__lowerCAmelCase					=							list(set(UpperCAmelCase__      )      )


def        __lowercase    (  UpperCAmelCase__		,					UpperCAmelCase__      ):

					"""simple docstring"""






					__lowerCAmelCase					=							[]
					for minterm in minterms:
										__lowerCAmelCase					=							''
										for _ in range(UpperCAmelCase__      ):
															__lowerCAmelCase					=							str(minterm % 2      ) + string
															minterm //= 2
										temp.append(UpperCAmelCase__      )
					return temp


def        __lowercase    (  UpperCAmelCase__		,					UpperCAmelCase__		,					UpperCAmelCase__      ):

					"""simple docstring"""






					__lowerCAmelCase					=							list(UpperCAmelCase__      )
					__lowerCAmelCase					=							list(UpperCAmelCase__      )
					__lowerCAmelCase					=							0
					for i in range(len(UpperCAmelCase__      )      ):
										if lista[i] != lista[i]:
															count_n += 1
					return count_n == count


def        __lowercase    (  UpperCAmelCase__		,					UpperCAmelCase__      ):

					"""simple docstring"""






					__lowerCAmelCase					=							[]
					__lowerCAmelCase					=							[0] * len(UpperCAmelCase__      )
					for i in range(len(chart[0]      )      ):
										__lowerCAmelCase					=							0
										__lowerCAmelCase					=							-1
										for j in range(len(UpperCAmelCase__      )      ):
															if chart[j][i] == 1:
																				count += 1
																				__lowerCAmelCase					=							j
										if count == 1:
															__lowerCAmelCase					=							1
					for i in range(len(UpperCAmelCase__      )      ):
										if select[i] == 1:
															for j in range(len(chart[0]      )      ):
																				if chart[i][j] == 1:
																									for k in range(len(UpperCAmelCase__      )      ):
																														__lowerCAmelCase					=							0
															temp.append(prime_implicants[i]      )
					while True:
										__lowerCAmelCase					=							0
										__lowerCAmelCase					=							-1
										__lowerCAmelCase					=							0
										for i in range(len(UpperCAmelCase__      )      ):
															__lowerCAmelCase					=							chart[i].count(1      )
															if count_n > max_n:
																				__lowerCAmelCase					=							count_n
																				__lowerCAmelCase					=							i

										if max_n == 0:
															return temp

										temp.append(prime_implicants[rem]      )

										for i in range(len(chart[0]      )      ):
															if chart[rem][i] == 1:
																				for j in range(len(UpperCAmelCase__      )      ):
																									__lowerCAmelCase					=							0


def        __lowercase    (  UpperCAmelCase__		,					UpperCAmelCase__      ):

					"""simple docstring"""






					__lowerCAmelCase					=							[[0 for x in range(len(UpperCAmelCase__      )      )] for x in range(len(UpperCAmelCase__      )      )]
					for i in range(len(UpperCAmelCase__      )      ):
										__lowerCAmelCase					=							prime_implicants[i].count('_'      )
										for j in range(len(UpperCAmelCase__      )      ):
															if is_for_table(prime_implicants[i]		,					binary[j]		,					UpperCAmelCase__      ):
																				__lowerCAmelCase					=							1

					return chart


def        __lowercase    (  ):

					"""simple docstring"""






					__lowerCAmelCase					=							int(input('Enter the no. of variables\n'      )      )
					__lowerCAmelCase					=							[
					    float(UpperCAmelCase__      )
					    for x in input(
					        'Enter the decimal representation of Minterms \'Spaces Separated\'\n'      ).split()
					]
					__lowerCAmelCase					=							decimal_to_binary(UpperCAmelCase__		,					UpperCAmelCase__      )

					__lowerCAmelCase					=							check(UpperCAmelCase__      )
					print('Prime Implicants are:'      )
					print(UpperCAmelCase__      )
					__lowerCAmelCase					=							prime_implicant_chart(UpperCAmelCase__		,					UpperCAmelCase__      )

					__lowerCAmelCase					=							selection(UpperCAmelCase__		,					UpperCAmelCase__      )
					print('Essential Prime Implicants are:'      )
					print(UpperCAmelCase__      )


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		main()









from graphs.minimum_spanning_tree_kruskal import kruskal


def        __lowercase    (  ):

					"""simple docstring"""






					__lowerCAmelCase					=							9
					__lowerCAmelCase					=							[
					    [0, 1, 4],
					    [0, 7, 8],
					    [1, 2, 8],
					    [7, 8, 7],
					    [7, 6, 1],
					    [2, 8, 2],
					    [8, 6, 6],
					    [2, 3, 7],
					    [2, 5, 4],
					    [6, 5, 2],
					    [3, 5, 14],
					    [3, 4, 9],
					    [5, 4, 10],
					    [1, 7, 11],
					]

					__lowerCAmelCase					=							kruskal(UpperCAmelCase__		,					UpperCAmelCase__      )

					__lowerCAmelCase					=							[
					    [7, 6, 1],
					    [2, 8, 2],
					    [6, 5, 2],
					    [0, 1, 4],
					    [2, 5, 4],
					    [2, 3, 7],
					    [0, 7, 8],
					    [3, 4, 9],
					]

					assert sorted(UpperCAmelCase__      ) == sorted(UpperCAmelCase__      )






