human
Permutations of string such that no two vowels are adjacent | Factorial of a number.
Function to find c ( n , r ).
Function to count permutations of string such that no two vowels are adjacent.
Finding the frequencies of the characters.
finding the no . of vowels and consonants in given word.
finding places for the vowels.
ways to fill consonants 6 ! / 2 !.
ways to put vowels 7 C5 x 5 !.
Driver code"
How can the above be solved in Python?
 Give me a code to permutations of string such that no two vowels are adjacent and the other steps required?
assistant
#Here is code to permutations of string such that no two vowels are adjacent and the other steps required.
 def factorial ( n ) :
	fact = 1 ;
	for i in range ( 2 , n + 1 ) :
		fact = fact * i
	return fact
def ncr ( n , r ) :
	return factorial ( n ) // ( factorial ( r ) * factorial ( n - r ) )
def countWays ( string ) :
	freq = [ 0 ] * 26
	nvowels , nconsonants = 0 , 0
	for i in range ( len ( string ) ) :
		freq [ ord ( string [ i ] ) - ord ( ' a ' ) ] += 1
	for i in range ( 26 ) :
		if ( i == 0 or i == 4 or i == 8 or i == 14 or i == 20 ) :
			nvowels += freq [ i ]
		else :
			nconsonants += freq [ i ]
	vplaces = nconsonants + 1
	cways = factorial ( nconsonants )
	for i in range ( 26 ) :
		if ( i != 0 and i != 4 and i != 8 and i != 14 and i != 20 and freq [ i ] > 1 ) :
			cways = cways // factorial ( freq [ i ] )
	vways = ncr ( vplaces , nvowels ) * factorial ( nvowels )
	for i in range ( 26 ) :
		if ( i == 0 or i == 4 or i == 8 or i == 14 or i == 20 and freq [ i ] > 1 ) :
			vways = vways // factorial ( freq [ i ] )
	return cways * vways ;
if __name__ == " _ _ main _ _ " :
	string = " permutation "
	print ( countWays ( string ) )