Count of ordered triplets ( R , G , B ) in a given original string | function to count the ordered triplets ( R , G , B ) ; count the B ( blue ) colour ; Driver Code
def countTriplets ( color ) : NEW_LINE INDENT result = 0 ; Blue_Count = 0 ; NEW_LINE Red_Count = 0 ; NEW_LINE for c in color : NEW_LINE INDENT if ( c == ' B ' ) : NEW_LINE INDENT Blue_Count += 1 ; NEW_LINE DEDENT DEDENT for c in color : NEW_LINE INDENT if ( c == ' B ' ) : NEW_LINE INDENT Blue_Count -= 1 ; NEW_LINE DEDENT if ( c == ' R ' ) : NEW_LINE INDENT Red_Count += 1 ; NEW_LINE DEDENT if ( c == ' G ' ) : NEW_LINE INDENT result += Red_Count * Blue_Count ; NEW_LINE DEDENT DEDENT return result ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT color = " RRGGBBRGGBB " ; NEW_LINE print ( countTriplets ( color ) ) ; NEW_LINE DEDENT