
"""simple docstring"""



from __future__ import annotations

from collections.abc import Sequence
from typing import Literal


def 			_UpperCamelCase						(    _A       ,   _A   )     ->	str | Literal[False]:





    """simple docstring"""

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


def 			_UpperCamelCase						(    _A   )     ->	list[str]:





    """simple docstring"""

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


def 			_UpperCamelCase						(    _A       ,   _A   )     ->	list[str]:





    """simple docstring"""

    _UpperCAmelCase        = []
    for minterm in minterms:
        _UpperCAmelCase        = """"""
        for _ in range(_A   ):
            _UpperCAmelCase        = str(minterm % 2   ) + string
            minterm //= 2
        temp.append(_A   )
    return temp


def 			_UpperCamelCase						(    _A       ,   _A       ,   _A   )     ->	bool:





    """simple docstring"""

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


def 			_UpperCamelCase						(    _A       ,   _A   )     ->	list[str]:





    """simple docstring"""

    _UpperCAmelCase        = []
    _UpperCAmelCase        = [0] * len(_A   )
    for i in range(len(chart[0]   )   ):
        _UpperCAmelCase        = 0
        _UpperCAmelCase        = -1
        for j in range(len(_A   )   ):
            if chart[j][i] == 1:
                count += 1
                _UpperCAmelCase        = j
        if count == 1:
            _UpperCAmelCase        = 1
    for i in range(len(_A   )   ):
        if select[i] == 1:
            for j in range(len(chart[0]   )   ):
                if chart[i][j] == 1:
                    for k in range(len(_A   )   ):
                        _UpperCAmelCase        = 0
            temp.append(prime_implicants[i]   )
    while True:
        _UpperCAmelCase        = 0
        _UpperCAmelCase        = -1
        _UpperCAmelCase        = 0
        for i in range(len(_A   )   ):
            _UpperCAmelCase        = chart[i].count(1   )
            if count_n > max_n:
                _UpperCAmelCase        = count_n
                _UpperCAmelCase        = 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(_A   )   ):
                    _UpperCAmelCase        = 0


def 			_UpperCamelCase						(    _A       ,   _A   )     ->	list[list[int]]:





    """simple docstring"""

    _UpperCAmelCase        = [[0 for x in range(len(_A   )   )] for x in range(len(_A   )   )]
    for i in range(len(_A   )   ):
        _UpperCAmelCase        = prime_implicants[i].count("""_"""   )
        for j in range(len(_A   )   ):
            if is_for_table(prime_implicants[i]       ,   binary[j]       ,   _A   ):
                _UpperCAmelCase        = 1

    return chart


def 			_UpperCamelCase						(    )     ->	None:





    """simple docstring"""

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

    _UpperCAmelCase        = check(_A   )
    print("""Prime Implicants are:"""   )
    print(_A   )
    _UpperCAmelCase        = prime_implicant_chart(_A       ,   _A   )

    _UpperCAmelCase        = selection(_A       ,   _A   )
    print("""Essential Prime Implicants are:"""   )
    print(_A   )


if __name__ == "__main__":
 import doctest

 doctest.testmod()
 main()

"""simple docstring"""



import math




class 		a_    :







    def   _snake_case       (      self      :							List[Any]  ,       __UpperCamelCase      :							list[list[float]]  ,       __UpperCamelCase      :							list[int]  )		->int:






        '''simple docstring'''






        _UpperCAmelCase        = 0.0
        _UpperCAmelCase        = 0.0
        for i in range(len(__UpperCamelCase  )  ):
            da += math.pow((sample[i] - weights[0][i])  ,       2  )
            da += math.pow((sample[i] - weights[1][i])  ,       2  )
            return 0 if da > da else 1
        return 0







    def   _snake_case       (      self      :							Dict  ,       __UpperCamelCase      :							list[list[int | float]]  ,       __UpperCamelCase      :							list[int]  ,       __UpperCamelCase      :							int  ,       __UpperCamelCase      :							float  )		->list[list[int | float]]:






        '''simple docstring'''






        for i in range(len(__UpperCamelCase  )  ):
            weights[j][i] += alpha * (sample[i] - weights[j][i])
        return weights







def 			_UpperCamelCase						(    )     ->	None:





    """simple docstring"""

    _UpperCAmelCase        = [[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

    # weight initialization ( n, C )
    _UpperCAmelCase        = [[0.2, 0.6, 0.5, 0.9], [0.8, 0.4, 0.7, 0.3]]

    # training
    _UpperCAmelCase        = SelfOrganizingMap()
    _UpperCAmelCase        = 3
    _UpperCAmelCase        = 0.5

    for _ in range(_A   ):
        for j in range(len(_A   )   ):
            # training sample
            _UpperCAmelCase        = training_samples[j]

            # Compute the winning vector
            _UpperCAmelCase        = self_organizing_map.get_winner(_A       ,   _A   )

            # Update the winning vector
            _UpperCAmelCase        = self_organizing_map.update(_A       ,   _A       ,   _A       ,   _A   )

    # classify test sample
    _UpperCAmelCase        = [0, 0, 0, 1]
    _UpperCAmelCase        = self_organizing_map.get_winner(_A       ,   _A   )

    # results
    print(F"""Clusters that the test sample belongs to : {winner}"""   )
    print(F"""Weights that have been trained : {weights}"""   )


# running the main() function
if __name__ == "__main__":
 main()