Form coils in a matrix | Prcoils in a matrix of size 4 n x 4 n ; Number of elements in each coil ; Let us fill elements in coil 1. ; First element of coil1 4 * n * 2 * n + 2 * n ; Fill remaining m - 1 elements in coil1 [ ] ; Fill elements of current step from down to up ; Next element from current element ; Fill elements of current step from up to down . ; get coil2 from coil1 ; Prboth coils ; Driver code
def printCoils ( n ) : NEW_LINE INDENT m = 8 * n * n NEW_LINE coil1 = [ 0 ] * m NEW_LINE coil1 [ 0 ] = 8 * n * n + 2 * n NEW_LINE curr = coil1 [ 0 ] NEW_LINE nflg = 1 NEW_LINE step = 2 NEW_LINE index = 1 NEW_LINE while ( index < m ) : NEW_LINE INDENT for i in range ( step ) : NEW_LINE INDENT curr = coil1 [ index ] = ( curr - 4 * n * nflg ) NEW_LINE index += 1 NEW_LINE if ( index >= m ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT if ( index >= m ) : NEW_LINE INDENT break NEW_LINE DEDENT for i in range ( step ) : NEW_LINE INDENT curr = coil1 [ index ] = curr + nflg NEW_LINE index += 1 NEW_LINE if ( index >= m ) : NEW_LINE INDENT break NEW_LINE DEDENT DEDENT nflg = nflg * ( - 1 ) NEW_LINE step += 2 NEW_LINE DEDENT coil2 = [ 0 ] * m NEW_LINE i = 0 NEW_LINE while ( i < 8 * n * n ) : NEW_LINE INDENT coil2 [ i ] = 16 * n * n + 1 - coil1 [ i ] NEW_LINE i += 1 NEW_LINE DEDENT print ( " Coil ▁ 1 ▁ : " , end = " ▁ " ) NEW_LINE i = 0 NEW_LINE while ( i < 8 * n * n ) : NEW_LINE INDENT print ( coil1 [ i ] , end = " ▁ " ) NEW_LINE i += 1 NEW_LINE DEDENT print ( " Coil 2 : " , ▁ end ▁ = ▁ "   " ) NEW_LINE i = 0 NEW_LINE while ( i < 8 * n * n ) : NEW_LINE INDENT print ( coil2 [ i ] , end = " ▁ " ) NEW_LINE i += 1 NEW_LINE DEDENT DEDENT n = 1 NEW_LINE printCoils ( n ) NEW_LINE