Minimum number of basic logic gates required to realize given Boolean expression | Function to count the total number of gates required to realize the boolean expression S ; Length of the string ; Stores the count of total gates ; Traverse the string ; AND , OR and NOT Gate ; Print the count of gates required ; Driver Code ; Input ; Function call to count the total number of gates required
def numberOfGates ( s ) : NEW_LINE INDENT N = len ( s ) NEW_LINE ans = 0 NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if ( s [ i ] == ' . ' or s [ i ] == ' + ' or s [ i ] == '1' ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT print ( ans , end = " " ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT S = " ( 1 - A ) . B + C " NEW_LINE numberOfGates ( S ) NEW_LINE DEDENT