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
function factorial ( n ) { let fact = 1 ; for ( let i = 2 ; i <= n ; i ++ ) fact = fact * i ; return fact ; } function npr ( n , r ) { let pnr = Math . floor ( factorial ( n ) / factorial ( n - r ) ) ; return pnr ; } function countPermutations ( n , r , k ) { return factorial ( k ) * ( r - k + 1 ) * npr ( n - k , r - k ) ; } let n = 8 ; let r = 5 ; let k = 2 ; document . write ( countPermutations ( n , r , k ) ) ;