human
Give me a code to block swap algorithm for array rotation and the other steps required given the following:
Block swap algorithm for array rotation | Wrapper over the recursive function leftRotateRec ( ) It left rotates arr by d ..
* Return If number of elements to be rotated is zero or equal to array size.
* If number of elements to be rotated is exactly half of array size.
If A is shorter.
If B is shorter.
function to pran array.
* This function swaps d elements starting at * index fi with d elements starting at index si.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to block swap algorithm for array rotation and the other steps required.
 def leftRotate ( arr , d , n ) :
	leftRotateRec ( arr , 0 , d , n ) ;
def leftRotateRec ( arr , i , d , n ) :
	if ( d == 0 or d == n ) :
		return ;
	if ( n - d == d ) :
		swap ( arr , i , n - d + i , d ) ;
		return ;
	if ( d < n - d ) :
		swap ( arr , i , n - d + i , d ) ;
		leftRotateRec ( arr , i , d , n - d ) ;
	else :
		swap ( arr , i , d , n - d ) ;
		leftRotateRec ( arr , n - d + i , 2 * d - n , d ) ;
def printArray ( arr , size ) :
	for i in range ( size ) :
		print ( arr [ i ] , end = " ▁ " ) ;
	print ( ) ;
def swap ( arr , fi , si , d ) :
	for i in range ( d ) :
		temp = arr [ fi + i ] ;
		arr [ fi + i ] = arr [ si + i ] ;
		arr [ si + i ] = temp ;
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ;
	leftRotate ( arr , 2 , 7 ) ;
	printArray ( arr , 7 ) ;