Length of Smallest Non Prime Subsequence in given numeric String | Function to find the smallest length of resultant subsequence ; Check for a subsequence of size 1 ; Check for a subsequence of size 2 ; If none of the above check is successful then subsequence must be of size 3 ; Never executed ; Driver Code
def findMinimumSubsequence ( S ) : NEW_LINE INDENT flag = False NEW_LINE dummy = ' ' NEW_LINE for j in range ( len ( S ) ) : NEW_LINE INDENT if ( S [ j ] != '2' and S [ j ] != '3' and S [ j ] != '5' and S [ j ] != '7' ) : NEW_LINE INDENT print ( 1 ) NEW_LINE flag = True NEW_LINE break NEW_LINE DEDENT DEDENT if ( flag == False ) : NEW_LINE INDENT for j in range ( len ( S ) ) : NEW_LINE INDENT for j1 in range ( j + 1 , len ( S ) , 1 ) : NEW_LINE INDENT dummy = S [ j ] + S [ j1 ] NEW_LINE if ( dummy != "23" and dummy != "37" and dummy != "53" and dummy != "73" ) : NEW_LINE INDENT print ( 2 ) NEW_LINE DEDENT if ( flag == True ) : NEW_LINE INDENT break NEW_LINE DEDENT else : NEW_LINE INDENT flag = True NEW_LINE DEDENT DEDENT if ( flag == True ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT DEDENT if ( flag == False ) : NEW_LINE INDENT if ( len ( S ) >= 3 ) : NEW_LINE INDENT print ( 3 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( - 1 ) NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT S = "237" NEW_LINE findMinimumSubsequence ( S ) NEW_LINE DEDENT