Permutations of n things taken r at a time with k things together | def to find factorial of a number ; def to calculate p ( n , r ) ; def to find the number of permutations of n different things taken r at a time with k things grouped together ; Driver code
def factorial ( n ) : NEW_LINE INDENT fact = 1 ; NEW_LINE for i in range ( 2 , n + 1 ) : NEW_LINE INDENT fact = fact * i ; NEW_LINE DEDENT return fact ; NEW_LINE DEDENT def npr ( n , r ) : NEW_LINE INDENT pnr = factorial ( n ) / factorial ( n - r ) ; NEW_LINE return pnr ; NEW_LINE DEDENT def countPermutations ( n , r , k ) : NEW_LINE INDENT return int ( factorial ( k ) * ( r - k + 1 ) * npr ( n - k , r - k ) ) ; NEW_LINE DEDENT n = 8 ; NEW_LINE r = 5 ; NEW_LINE k = 2 ; NEW_LINE print ( countPermutations ( n , r , k ) ) ; NEW_LINE