Arrangement of words without changing the relative position of vowel and consonants | this function return n ! ; this will return total number of ways ; freq maintains frequency of each character in word ; check character is vowel or not ; the characters that are not vowel must be consonant ; number of ways to arrange vowel ; multiply both as these are independent ; string contains only capital letters ; this will contain ans
< ? php function factorial ( $ n ) { $ res = 1 ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) $ res = $ res * $ i ; return $ res ; } function count1 ( $ word ) { $ freq = array_fill ( 0 , 27 , 0 ) ; for ( $ i = 0 ; $ i < 27 ; $ i ++ ) $ freq [ $ i ] = 0 ; $ vowel = 0 ; $ consonant = 0 ; for ( $ i = 0 ; $ i < strlen ( $ word ) ; $ i ++ ) { $ freq [ ord ( $ word [ $ i ] ) - 65 ] ++ ; if ( $ word [ $ i ] == ' A ' $ word [ $ i ] == ' E ' $ word [ $ i ] == ' I ' $ word [ $ i ] == ' O ' $ word [ $ i ] == ' U ' ) { $ vowel ++ ; } else $ consonant ++ ; } $ vowelArrange = factorial ( $ vowel ) ; $ vowelArrange /= factorial ( $ freq [ 0 ] ) ; $ vowelArrange /= factorial ( $ freq [ 4 ] ) ; $ vowelArrange /= factorial ( $ freq [ 8 ] ) ; $ vowelArrange /= factorial ( $ freq [ 14 ] ) ; $ vowelArrange /= factorial ( $ freq [ 20 ] ) ; $ consonantArrange = factorial ( $ consonant ) ; for ( $ i = 0 ; $ i < 26 ; $ i ++ ) { if ( $ i != 0 && $ i != 4 && $ i != 8 && $ i != 14 && $ i != 20 ) $ consonantArrange /= factorial ( $ freq [ $ i ] ) ; } $ total = $ vowelArrange * $ consonantArrange ; return $ total ; } $ word = " COMPUTER " ; $ ans = count1 ( $ word ) ; echo ( $ ans ) ; ? >