Permutations of n things taken r at a time with k things together | Function to find factorial of a number ; Function to calculate p ( n , r ) ; Function to find the number of permutations of n different things taken r at a time with k things grouped together ; Driver code
< ? php function factorial ( $ n ) { $ fact = 1 ; for ( $ i = 2 ; $ i <= $ n ; $ i ++ ) $ fact = $ fact * $ i ; return $ fact ; } function npr ( $ n , $ r ) { $ pnr = factorial ( $ n ) / factorial ( $ n - $ r ) ; return $ pnr ; } function countPermutations ( $ n , $ r , $ k ) { return factorial ( $ k ) * ( $ r - $ k + 1 ) * npr ( $ n - $ k , $ r - $ k ) ; } $ n = 8 ; $ r = 5 ; $ k = 2 ; echo countPermutations ( $ n , $ r , $ k ) ; ? >