human
What is a code to generate a permutation of first N natural numbers having count of unique adjacent differences equal to K and the other steps required given the following:
Generate a permutation of first N natural numbers having count of unique adjacent differences equal to K | Function to construct the lst with exactly K unique adjacent element differences.
Stores the resultant array.
Stores the left and the right most element of the range.
Traverse the array.
If k is even , the add left to array and increment the left.
If k is odd , the add right to array and decrement the right.
Repeat the steps for k - 1 times.
Print the resultant lst.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to generate a permutation of first N natural numbers having count of unique adjacent differences equal to K and the other steps required.
 def makelst ( N , K ) :
	lst = [ 0 for i in range ( N ) ]
	left = 1
	right = N
	for i in range ( N ) :
		if ( K % 2 == 0 ) :
			lst [ i ] = left
			left = left + 1
		else :
			lst [ i ] = right
			right = right - 1
		if ( K > 1 ) :
			K -= 1
	for i in range ( N ) :
		print ( lst [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
	N = 6
	K = 3
	makelst ( N , K )