human
Can you provide a code to count of permutations such that sum of K numbers from given range is even and the other steps required given the following:
Count of permutations such that sum of K numbers from given range is even | Function to return the number of all permutations such that sum of K numbers in range is even.
Find total count of even and odd number in given range.
Iterate loop k times and update even_sum & odd_sum using previous values.
Update the prev_even and odd_sum.
Even sum.
Odd sum.
Return even_sum.
Given ranges.
Length of permutation.
Function call"
Solution in Python:
assistant
#Here is code to count of permutations such that sum of K numbers from given range is even and the other steps required.
 def countEvenSum ( low , high , k ) :
	even_count = high / 2 - ( low - 1 ) / 2
	odd_count = ( high + 1 ) / 2 - low / 2
	even_sum = 1
	odd_sum = 0
	for i in range ( 0 , k ) :
		prev_even = even_sum
		prev_odd = odd_sum
		even_sum = ( ( prev_even * even_count ) + ( prev_odd * odd_count ) )
		odd_sum = ( ( prev_even * odd_count ) + ( prev_odd * even_count ) )
	print ( int ( even_sum ) )
low = 4 ;
high = 5 ;
K = 3 ;
countEvenSum ( low , high , K ) ;