human
Write me a code to number of ways such that only K bars are visible from the left and the other steps required given the following:
Number of ways such that only K bars are visible from the left | Function to calculate the number of permutations of N , where only K bars are visible from the left ..
Only ascending order is possible.
N is placed at the first position The nest N - 1 are arranged in ( N - 1 ) ! ways.
Recursing.
Driver code.
Input.
Function call"
How can the above be solved in Python?
assistant
#Here is code to number of ways such that only K bars are visible from the left and the other steps required.
 def KvisibleFromLeft ( N , K ) :
	if ( N == K ) :
		return 1
	if ( K == 1 ) :
		ans = 1
		for i in range ( 1 , N , 1 ) :
			ans *= i
		return ans
	return KvisibleFromLeft ( N - 1 , K - 1 ) + ( N - 1 ) * KvisibleFromLeft ( N - 1 , K )
if __name__ == ' _ _ main _ _ ' :
	N = 5
	K = 2
	print ( KvisibleFromLeft ( N , K ) )