dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
n = 5
def FindMaxProduct ( arr , n ) :
    max = 0
    for i in range ( n ) :
        for j in range ( n ) :
            if ( ( j - 3 ) >= 0 ) :
                result = ( arr [ i ] [ j ] * arr [ i ] [ j - 1 ] * arr [ i ] [ j - 2 ] * arr [ i ] [ j - 3 ] )
                if ( max < result ) :
                    max = result
            if ( ( i - 3 ) >= 0 ) :
                result = ( arr [ i ] [ j ] * arr [ i - 1 ] [ j ] * arr [ i - 2 ] [ j ] * arr [ i - 3 ] [ j ] )
                if ( max < result ) :
                    max = result
            if ( ( i - 3 ) >= 0 and ( j - 3 ) >= 0 ) :
                result = ( arr [ i ] [ j ] * arr [ i - 1 ] [ j - 1 ] * arr [ i - 2 ] [ j - 2 ] * arr [ i - 3 ] [ j - 3 ] )
                if ( max < result ) :
                    max = result
            if ( ( i - 3 ) >= 0 and ( j - 1 ) <= 0 ) :
                result = ( arr [ i ] [ j ] * arr [ i - 1 ] [ j + 1 ] * arr [ i - 2 ] [ j + 2 ] * arr [ i - 3 ] [ j + 3 ] )
                if ( max < result ) :
                    max = result
    return max
if __name__ == " _ _ main _ _ " :
    arr = [ [ 1 , 2 , 3 , 4 , 5 ] , [ 6 , 7 , 8 , 9 , 1 ] , [ 2 , 3 , 4 , 5 , 6 ] , [ 7 , 8 , 9 , 1 , 0 ] , [ 9 , 6 , 4 , 2 , 3 ] ]
    print ( FindMaxProduct ( arr , n ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
class Node :
    def __init__ ( self , x ) :
        self . data = x
        self . left = None
        self . right = None
def buildUtil ( inn , post , innStrt , innEnd ) :
    global mp , index
    if ( innStrt > innEnd ) :
        return None
    curr = post [ index ]
    node = Node ( curr )
    index -= 1
    if ( innStrt == innEnd ) :
        return node
    iIndex = mp [ curr ]
    node . right = buildUtil ( inn , post , iIndex + 1 , innEnd )
    node . left = buildUtil ( inn , post , innStrt , iIndex - 1 )
    return node
def buildTree ( inn , post , lenn ) :
    global index
    for i in range ( lenn ) :
        mp [ inn [ i ] ] = i
    index = lenn - 1
    return buildUtil ( inn , post , 0 , lenn - 1 )
def preOrder ( node ) :
    if ( node == None ) :
        return
    print ( node . data , end = " ▁ " )
    preOrder ( node . left )
    preOrder ( node . right )
if __name__ == ' _ _ main _ _ ' :
    inn = [ 4 , 8 , 2 , 5 , 1 , 6 , 3 , 7 ]
    post = [ 8 , 4 , 5 , 2 , 6 , 7 , 3 , 1 ]
    n = len ( inn )
    mp , index = { } , 0
    root = buildTree ( inn , post , n )
    print ( " Preorder ▁ of ▁ the ▁ constructed ▁ tree ▁ : " )
    preOrder ( root )

Index/key variables: curr, i, index
Iterator variables: i
Class/struct names: Node
Python program:
N = 3
def minimumflip ( mat , n ) :
    transpose = [ [ 0 ] * n ] * n
    for i in range ( n ) :
        for j in range ( n ) :
            transpose [ i ] [ j ] = mat [ j ] [ i ]
    flip = 0
    for i in range ( n ) :
        for j in range ( n ) :
            if transpose [ i ] [ j ] != mat [ i ] [ j ] :
                flip += 1
    return int ( flip / 2 )
n = 3
mat = [ [ 0 , 0 , 1 ] , [ 1 , 1 , 1 ] , [ 1 , 0 , 0 ] ]
print ( minimumflip ( mat , n ) )

Index/key variables: i, j
Accumulator variables: flip
Iterator variables: i, j
Python program:
N = 3
def minimumflip ( mat , n ) :
    flip = 0
    for i in range ( n ) :
        for j in range ( i ) :
            if mat [ i ] [ j ] != mat [ j ] [ i ] :
                flip += 1
    return flip
n = 3
mat = [ [ 0 , 0 , 1 ] , [ 1 , 1 , 1 ] , [ 1 , 0 , 0 ] ]
print ( minimumflip ( mat , n ) )

Index/key variables: i, j
Accumulator variables: flip
Iterator variables: i, j
Python program:
MAX = 100
def freq ( ar , m , n ) :
    even = 0
    odd = 0
    for i in range ( m ) :
        for j in range ( n ) :
            if ( ( ar [ i ] [ j ] % 2 ) == 0 ) :
                even += 1
            else :
                odd += 1
    print ( " ▁ Frequency ▁ of ▁ odd ▁ number ▁ = " , odd )
    print ( " ▁ Frequency ▁ of ▁ even ▁ number ▁ = " , even )
m = 3
n = 3
array = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ]
freq ( array , m , n )

Index/key variables: i, j
Accumulator variables: even, odd
Iterator variables: i, j
Python program:
MAX = 100
def HalfDiagonalSums ( mat , n ) :
    diag1_left = 0
    diag1_right = 0
    diag2_left = 0
    diag2_right = 0
    i = 0
    j = n - 1
    while i < n :
        if ( i < n // 2 ) :
            diag1_left += mat [ i ] [ i ]
            diag2_left += mat [ j ] [ i ]
        elif ( i > n // 2 ) :
            diag1_right += mat [ i ] [ i ]
            diag2_right += mat [ j ] [ i ]
        i += 1
        j -= 1
    return ( diag1_left == diag2_right and diag2_right == diag2_left and diag1_right == diag2_left and diag2_right == mat [ n // 2 ] [ n // 2 ] )
if __name__ == " _ _ main _ _ " :
    a = [ [ 2 , 9 , 1 , 4 , - 2 ] , [ 6 , 7 , 2 , 11 , 4 ] , [ 4 , 2 , 9 , 2 , 4 ] , [ 1 , 9 , 2 , 4 , 4 ] , [ 0 , 2 , 4 , 2 , 5 ] ]
    print ( " Yes " ) if ( HalfDiagonalSums ( a , 5 ) ) else print ( " No " )

Index/key variables: i, j
Accumulator variables: diag1_left, diag1_right, diag2_left, diag2_right
Python program:
def Identity ( size ) :
    for row in range ( 0 , size ) :
        for col in range ( 0 , size ) :
            if ( row == col ) :
                print ( "1 ▁ " , end = " ▁ " )
            else :
                print ( "0 ▁ " , end = " ▁ " )
        print ( )
size = 5
Identity ( size )

Iterator variables: col, row
Python program:
MAX = 100 ;
def isIdentity ( mat , N ) :
    for row in range ( N ) :
        for col in range ( N ) :
            if ( row == col and mat [ row ] [ col ] != 1 ) :
                return False ;
            elif ( row != col and mat [ row ] [ col ] != 0 ) :
                return False ;
    return True ;
N = 4 ;
mat = [ [ 1 , 0 , 0 , 0 ] , [ 0 , 1 , 0 , 0 ] , [ 0 , 0 , 1 , 0 ] , [ 0 , 0 , 0 , 1 ] ] ;
if ( isIdentity ( mat , N ) ) :
    print ( " Yes ▁ " ) ;
else :
    print ( " No ▁ " ) ;

Index/key variables: col, row
Iterator variables: col, row
Python program:
def modPower ( a , t ) :
    now = a ;
    ret = 1 ;
    mod = 100000007 ;
    while ( t ) :
        if ( t & 1 ) :
            ret = now * ( ret % mod ) ;
        now = now * ( now % mod ) ;
        t >>= 1 ;
    return ret ;
def countWays ( n , m , k ) :
    mod = 100000007 ;
    if ( k == - 1 and ( ( n + m ) % 2 == 1 ) ) :
        return 0 ;
    if ( n == 1 or m == 1 ) :
        return 1 ;
    return ( modPower ( modPower ( 2 , n - 1 ) , m - 1 ) % mod ) ;
n = 2 ;
m = 7 ;
k = 1 ;
print ( countWays ( n , m , k ) ) ;

Accumulator variables: t
Python program:
MAX = 100
def imageSwap ( mat , n ) :
    row = 0
    for j in range ( n ) :
        s = [ ]
        i = row
        k = j
        while ( i < n and k >= 0 ) :
            s . append ( mat [ i ] [ k ] )
            i += 1
            k -= 1
        i = row
        k = j
        while ( i < n and k >= 0 ) :
            mat [ i ] [ k ] = s [ - 1 ]
            k -= 1
            i += 1
            s . pop ( )
    column = n - 1
    for j in range ( 1 , n ) :
        s = [ ]
        i = j
        k = column
        while ( i < n and k >= 0 ) :
            s . append ( mat [ i ] [ k ] )
            i += 1
            k -= 1
        i = j
        k = column
        while ( i < n and k >= 0 ) :
            mat [ i ] [ k ] = s [ - 1 ]
            i += 1
            k -= 1
            s . pop ( )
def printMatrix ( mat , n ) :
    for i in range ( n ) :
        for j in range ( n ) :
            print ( mat [ i ] [ j ] , end = " ▁ " )
        print ( )
mat = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 ] ]
n = 4
imageSwap ( mat , n )
printMatrix ( mat , n )

Index/key variables: i, j, k
Accumulator variables: s
Iterator variables: i, j
Python program:
from builtins import range
MAX = 100 ;
def imageSwap ( mat , n ) :
    for i in range ( n ) :
        for j in range ( i + 1 ) :
            t = mat [ i ] [ j ] ;
            mat [ i ] [ j ] = mat [ j ] [ i ]
            mat [ j ] [ i ] = t
def printMatrix ( mat , n ) :
    for i in range ( n ) :
        for j in range ( n ) :
            print ( mat [ i ] [ j ] , end = " ▁ " ) ;
        print ( ) ;
if __name__ == ' _ _ main _ _ ' :
    mat = [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 ] ;
    n = 4 ;
    imageSwap ( mat , n ) ;
    printMatrix ( mat , n ) ;

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findend ( i , j , a , output , index ) :
    x = len ( a )
    y = len ( a [ 0 ] )
    flagc = 0
    flagr = 0
    for m in range ( i , x ) :
        if a [ m ] [ j ] == 1 :
            flagr = 1
            break
        if a [ m ] [ j ] == 5 :
            pass
        for n in range ( j , y ) :
            if a [ m ] [ n ] == 1 :
                flagc = 1
                break
            a [ m ] [ n ] = 5
    if flagr == 1 :
        output [ index ] . append ( m - 1 )
    else :
        output [ index ] . append ( m )
    if flagc == 1 :
        output [ index ] . append ( n - 1 )
    else :
        output [ index ] . append ( n )
def get_rectangle_coordinates ( a ) :
    size_of_array = len ( a )
    output = [ ]
    index = - 1
    for i in range ( 0 , size_of_array ) :
        for j in range ( 0 , len ( a [ 0 ] ) ) :
            if a [ i ] [ j ] == 0 :
                output . append ( [ i , j ] )
                index = index + 1
                findend ( i , j , a , output , index )
    print ( output )
tests = [ [ 1 , 1 , 1 , 1 , 1 , 1 , 1 ] , [ 1 , 1 , 1 , 1 , 1 , 1 , 1 ] , [ 1 , 1 , 1 , 0 , 0 , 0 , 1 ] , [ 1 , 0 , 1 , 0 , 0 , 0 , 1 ] , [ 1 , 0 , 1 , 1 , 1 , 1 , 1 ] , [ 1 , 0 , 1 , 0 , 0 , 0 , 0 ] , [ 1 , 1 , 1 , 0 , 0 , 0 , 1 ] , [ 1 , 1 , 1 , 1 , 1 , 1 , 1 ] ]
get_rectangle_coordinates ( tests )

Index/key variables: i, index, j, m, n
Accumulator variables: output
Iterator variables: i, j, m, n
Python program:
def search ( mat , n , x ) :
    if ( n == 0 ) :
        return - 1
    for i in range ( n ) :
        for j in range ( n ) :
            if ( mat [ i ] [ j ] == x ) :
                print ( " Element ▁ found ▁ at ▁ ( " , i , " , " , j , " ) " )
                return 1
    print ( " ▁ Element ▁ not ▁ found " )
    return 0
mat = [ [ 10 , 20 , 30 , 40 ] , [ 15 , 25 , 35 , 45 ] , [ 27 , 29 , 37 , 48 ] , [ 32 , 33 , 39 , 50 ] ]
search ( mat , 4 , 29 )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def search ( mat , n , x ) :
    i = 0
    j = n - 1
    while ( i < n and j >= 0 ) :
        if ( mat [ i ] [ j ] == x ) :
            print ( " n ▁ Found ▁ at ▁ " , i , " , ▁ " , j )
            return 1
        if ( mat [ i ] [ j ] > x ) :
            j -= 1
        else :
            i += 1
    print ( " Element ▁ not ▁ found " )
    return 0
mat = [ [ 10 , 20 , 30 , 40 ] , [ 15 , 25 , 35 , 45 ] , [ 27 , 29 , 37 , 48 ] , [ 32 , 33 , 39 , 50 ] ]
search ( mat , 4 , 29 )

Index/key variables: i, j
Python program:
def fill0X ( m , n ) :
    i , k , l = 0 , 0 , 0
    r = m
    c = n
    a = [ [ None ] * n for i in range ( m ) ]
    x = ' X '
    while k < m and l < n :
        for i in range ( l , n ) :
            a [ k ] [ i ] = x
        k += 1
        for i in range ( k , m ) :
            a [ i ] [ n - 1 ] = x
        n -= 1
        if k < m :
            for i in range ( n - 1 , l - 1 , - 1 ) :
                a [ m - 1 ] [ i ] = x
            m -= 1
        if l < n :
            for i in range ( m - 1 , k - 1 , - 1 ) :
                a [ i ] [ l ] = x
            l += 1
        x = ' X ' if x == '0' else '0'
    for i in range ( r ) :
        for j in range ( c ) :
            print ( a [ i ] [ j ] , end = " ▁ " )
        print ( )
if __name__ == ' _ _ main _ _ ' :
    print ( " Output ▁ for ▁ m ▁ = ▁ 5 , ▁ n ▁ = ▁ 6" )
    fill0X ( 5 , 6 )
    print ( " Output ▁ for ▁ m ▁ = ▁ 4 , ▁ n ▁ = ▁ 4" )
    fill0X ( 4 , 4 )
    print ( " Output ▁ for ▁ m ▁ = ▁ 3 , ▁ n ▁ = ▁ 4" )
    fill0X ( 3 , 4 )

Index/key variables: i, j, k, l
Accumulator variables: m, n
Iterator variables: i, j
Python program:
R = 5
C = 5
def diagonalOrder ( arr , n , m ) :
    ans = [ [ ] for i in range ( n + m - 1 ) ]
    for i in range ( m ) :
        for j in range ( n ) :
            ans [ i + j ] . append ( arr [ j ] [ i ] )
    for i in range ( len ( ans ) ) :
        for j in range ( len ( ans [ i ] ) ) :
            print ( ans [ i ] [ j ] , end = " ▁ " )
        print ( )
n = 5
m = 4
arr = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 ] , [ 17 , 18 , 19 , 20 ] ]
diagonalOrder ( arr , n , m )

Index/key variables: i, j
Iterator variables: i, j
Python program:
n = 4
def calculateEnergy ( mat , n ) :
    tot_energy = 0
    for i in range ( n ) :
        for j in range ( n ) :
            q = mat [ i ] [ j ] // n
            i_des = q
            j_des = mat [ i ] [ j ] - ( n * q )
            tot_energy += ( abs ( i_des - i ) + abs ( j_des - j ) )
    return tot_energy
mat = [ [ 4 , 7 , 0 , 3 ] , [ 8 , 5 , 6 , 1 ] , [ 9 , 11 , 10 , 2 ] , [ 15 , 13 , 14 , 12 ] ]
print ( " Total ▁ energy ▁ required ▁ = ▁ " , calculateEnergy ( mat , n ) , " units " )

Index/key variables: i, j
Accumulator variables: tot_energy
Iterator variables: i, j
Python program:
MAX = 100
def isUnique ( mat , i , j , n , m ) :
    sumrow = 0
    for k in range ( m ) :
        sumrow += mat [ i ] [ k ]
        if ( sumrow > 1 ) :
            return False
    sumcol = 0
    for k in range ( n ) :
        sumcol += mat [ k ] [ j ]
        if ( sumcol > 1 ) :
            return False
    return True
def countUnique ( mat , n , m ) :
    uniquecount = 0
    for i in range ( n ) :
        for j in range ( m ) :
            if ( mat [ i ] [ j ] and isUnique ( mat , i , j , n , m ) ) :
                uniquecount += 1
    return uniquecount
mat = [ [ 0 , 1 , 0 , 0 ] , [ 0 , 0 , 1 , 0 ] , [ 1 , 0 , 0 , 1 ] ]
print ( countUnique ( mat , 3 , 4 ) )

Index/key variables: i, j, k
Accumulator variables: sumcol, sumrow, uniquecount
Iterator variables: i, j, k
Python program:
MAX = 100 ;
def countUnique ( mat , n , m ) :
    rowsum = [ 0 ] * n ;
    colsum = [ 0 ] * m ;
    for i in range ( n ) :
        for j in range ( m ) :
            if ( mat [ i ] [ j ] != 0 ) :
                rowsum [ i ] += 1 ;
                colsum [ j ] += 1 ;
    uniquecount = 0 ;
    for i in range ( n ) :
        for j in range ( m ) :
            if ( mat [ i ] [ j ] != 0 and rowsum [ i ] == 1 and colsum [ j ] == 1 ) :
                uniquecount += 1 ;
    return uniquecount ;
if __name__ == ' _ _ main _ _ ' :
    mat = [ [ 0 , 1 , 0 , 0 ] , [ 0 , 0 , 1 , 0 ] , [ 1 , 0 , 0 , 1 ] ] ;
    print ( countUnique ( mat , 3 , 4 ) ) ;

Index/key variables: i, j
Accumulator variables: uniquecount
Iterator variables: i, j
Python program:
Max = 100
def countCommon ( mat , n ) :
    res = 0
    for i in range ( n ) :
        if mat [ i ] [ i ] == mat [ i ] [ n - i - 1 ] :
            res = res + 1
    return res
mat = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ]
print ( countCommon ( mat , 3 ) )

Index/key variables: i
Iterator variables: i
Python program:
MAX = 100 ;
def areSumSame ( a , n , m ) :
    sum1 = 0
    sum2 = 0
    for i in range ( 0 , n ) :
        sum1 = 0
        sum2 = 0
        for j in range ( 0 , m ) :
            sum1 += a [ i ] [ j ]
            sum2 += a [ j ] [ i ]
        if ( sum1 == sum2 ) :
            return 1
    return 0
n = 4 ;
m = 4 ;
M = [ [ 1 , 2 , 3 , 4 ] , [ 9 , 5 , 3 , 1 ] , [ 0 , 3 , 5 , 6 ] , [ 0 , 4 , 5 , 6 ] ]
print ( areSumSame ( M , n , m ) )

Index/key variables: i, j
Accumulator variables: sum1, sum2
Iterator variables: i, j
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . Next = self . child = None
        self . data = data
def addSibling ( n , data ) :
    if ( n == None ) :
        return None
    while ( n . Next ) :
        n = n . Next
    n . Next = newNode ( data )
    return n . Next
def addChild ( n , data ) :
    if ( n == None ) :
        return None
    if ( n . child ) :
        return addSibling ( n . child , data )
    else :
        n . child = newNode ( data )
        return n . child
def traverseTree ( root ) :
    if ( root == None ) :
        return
    while ( root ) :
        print ( root . data , end = " ▁ " )
        if ( root . child ) :
            traverseTree ( root . child )
        root = root . Next
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 10 )
    n1 = addChild ( root , 2 )
    n2 = addChild ( root , 3 )
    n3 = addChild ( root , 4 )
    n4 = addChild ( n3 , 6 )
    n5 = addChild ( root , 5 )
    n6 = addChild ( n5 , 7 )
    n7 = addChild ( n5 , 8 )
    n8 = addChild ( n5 , 9 )
    traverseTree ( root )

Class/struct names: newNode
Python program:
N = 4
def findMax ( arr ) :
    row = 0
    j = N - 1
    for i in range ( 0 , N ) :
        while ( arr [ i ] [ j ] == 1 and j >= 0 ) :
            row = i
            j -= 1
    print ( " Row ▁ number ▁ = ▁ " , row + 1 , " , ▁ MaxCount ▁ = ▁ " , N - 1 - j )
arr = [ [ 0 , 0 , 0 , 1 ] , [ 0 , 0 , 0 , 1 ] , [ 0 , 0 , 0 , 0 ] , [ 0 , 1 , 1 , 1 ] ]
findMax ( arr )

Index/key variables: i, j
Iterator variables: i
Python program:
def diag ( arr , n ) :
    for i in range ( n ) :
        for j in range ( n ) :
            if ( i == 0 ) :
                print ( arr [ i ] [ j ] , end = " ▁ " )
            elif ( i == j ) :
                print ( arr [ i ] [ j ] , end = " ▁ " )
            elif ( i == n - 1 ) :
                print ( arr [ i ] [ j ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    a = [ [ 4 , 5 , 6 , 8 ] , [ 1 , 2 , 3 , 1 ] , [ 7 , 8 , 9 , 4 ] , [ 1 , 8 , 7 , 5 ] ]
    diag ( a , 4 )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def isPalin ( str ) :
    l = len ( str ) // 2
    for i in range ( l ) :
        if ( str [ i ] != str [ len ( str ) - i - 1 ] ) :
            return False
    return True
def palindromicPath ( str , a , i , j , m , n ) :
    if ( j < m - 1 or i < n - 1 ) :
        if ( i < n - 1 ) :
            palindromicPath ( str + a [ i ] [ j ] , a , i + 1 , j , m , n )
        if ( j < m - 1 ) :
            palindromicPath ( str + a [ i ] [ j ] , a , i , j + 1 , m , n )
    else :
        str = str + a [ n - 1 ] [ m - 1 ]
        if isPalin ( str ) :
            print ( str )
if __name__ == " _ _ main _ _ " :
    arr = [ [ ' a ' , ' a ' , ' a ' , ' b ' ] , [ ' b ' , ' a ' , ' a ' , ' a ' ] , [ ' a ' , ' b ' , ' b ' , ' a ' ] ]
    str = " "
    palindromicPath ( str , arr , 0 , 0 , 4 , 3 )

Index/key variables: i, j
Iterator variables: i
Python program:
n = 4 ;
m = 4 ;
def findPossibleMoves ( mat , p , q ) :
    global n , m ;
    X = [ 2 , 1 , - 1 , - 2 , - 2 , - 1 , 1 , 2 ] ;
    Y = [ 1 , 2 , 2 , 1 , - 1 , - 2 , - 2 , - 1 ] ;
    count = 0 ;
    for i in range ( 8 ) :
        x = p + X [ i ] ;
        y = q + Y [ i ] ;
        if ( x >= 0 and y >= 0 and x < n and y < m and mat [ x ] [ y ] == 0 ) :
            count += 1 ;
    return count ;
if __name__ == ' _ _ main _ _ ' :
    mat = [ [ 1 , 0 , 1 , 0 ] , [ 0 , 1 , 1 , 1 ] , [ 1 , 1 , 0 , 1 ] , [ 0 , 1 , 1 , 1 ] ] ;
    p , q = 2 , 2 ;
    print ( findPossibleMoves ( mat , p , q ) ) ;

Index/key variables: i, x, y
Accumulator variables: count
Iterator variables: i
Python program:
MAX = 100
def printDiagonalSums ( mat , n ) :
    principal = 0
    secondary = 0 ;
    for i in range ( 0 , n ) :
        for j in range ( 0 , n ) :
            if ( i == j ) :
                principal += mat [ i ] [ j ]
            if ( ( i + j ) == ( n - 1 ) ) :
                secondary += mat [ i ] [ j ]
    print ( " Principal ▁ Diagonal : " , principal )
    print ( " Secondary ▁ Diagonal : " , secondary )
a = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] ]
printDiagonalSums ( a , 4 )

Index/key variables: i, j
Accumulator variables: principal, secondary
Iterator variables: i, j
Python program:
MAX = 100
def printDiagonalSums ( mat , n ) :
    principal = 0
    secondary = 0
    for i in range ( 0 , n ) :
        principal += mat [ i ] [ i ]
        secondary += mat [ i ] [ n - i - 1 ]
    print ( " Principal ▁ Diagonal : " , principal )
    print ( " Secondary ▁ Diagonal : " , secondary )
a = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] ]
printDiagonalSums ( a , 4 )

Index/key variables: i
Accumulator variables: principal, secondary
Iterator variables: i
Python program:
from collections import deque
class Node :
    def __init__ ( self , x ) :
        self . data = x
        self . next = None
        self . child = None
def addSibling ( n , data ) :
    if ( n == None ) :
        return None
    while ( n . next ) :
        n = n . next
    n . next = Node ( data )
    return n
def addChild ( n , data ) :
    if ( n == None ) :
        return None
    if ( n . child ) :
        return addSibling ( n . child , data )
    else :
        n . child = Node ( data )
        return n
def traverseTree ( root ) :
    if ( root == None ) :
        return
    print ( root . data , end = " ▁ " )
    if ( root . child == None ) :
        return
    q = deque ( )
    curr = root . child
    q . append ( curr )
    while ( len ( q ) > 0 ) :
        curr = q . popleft ( )
        while ( curr != None ) :
            print ( curr . data , end = " ▁ " )
            if ( curr . child != None ) :
                q . append ( curr . child )
            curr = curr . next
if __name__ == ' _ _ main _ _ ' :
    root = Node ( 10 )
    n1 = addChild ( root , 2 )
    n2 = addChild ( root , 3 )
    n3 = addChild ( root , 4 )
    n4 = addChild ( n3 , 6 )
    n5 = addChild ( root , 5 )
    n6 = addChild ( n5 , 7 )
    n7 = addChild ( n5 , 8 )
    n8 = addChild ( n5 , 9 )
    traverseTree ( root )

Accumulator variables: q
Class/struct names: Node
Python program:
MAX = 100
def printSpiral ( mat , r , c ) :
    a = 0
    b = 2
    low_row = 0 if ( 0 > a ) else a
    low_column = 0 if ( 0 > b ) else b - 1
    high_row = r - 1 if ( ( a + 1 ) >= r ) else a + 1
    high_column = c - 1 if ( ( b + 1 ) >= c ) else b + 1
    while ( ( low_row > 0 - r and low_column > 0 - c ) ) :
        i = low_column + 1
        while ( i <= high_column and i < c and low_row >= 0 ) :
            print ( mat [ low_row ] [ i ] , end = " ▁ " )
            i += 1
        low_row -= 1
        i = low_row + 2
        while ( i <= high_row and i < r and high_column < c ) :
            print ( mat [ i ] [ high_column ] , end = " ▁ " )
            i += 1
        high_column += 1
        i = high_column - 2
        while ( i >= low_column and i >= 0 and high_row < r ) :
            print ( mat [ high_row ] [ i ] , end = " ▁ " )
            i -= 1
        high_row += 1
        i = high_row - 2
        while ( i > low_row and i >= 0 and low_column >= 0 ) :
            print ( mat [ i ] [ low_column ] , end = " ▁ " )
            i -= 1
        low_column -= 1
    print ( )
if __name__ == " _ _ main _ _ " :
    mat = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ]
    r = 3
    c = 3
    printSpiral ( mat , r , c )

Index/key variables: high_column, high_row, i, low_column, low_row
Python program:
N = 3 ;
def interchangeDiagonals ( array ) :
    for i in range ( N ) :
        if ( i != N / 2 ) :
            temp = array [ i ] [ i ] ;
            array [ i ] [ i ] = array [ i ] [ N - i - 1 ] ;
            array [ i ] [ N - i - 1 ] = temp ;
    for i in range ( N ) :
        for j in range ( N ) :
            print ( array [ i ] [ j ] , end = " ▁ " ) ;
        print ( ) ;
if __name__ == ' _ _ main _ _ ' :
    array = [ 4 , 5 , 6 ] , [ 1 , 2 , 3 ] , [ 7 , 8 , 9 ] ;
    interchangeDiagonals ( array ) ;

Index/key variables: i, j
Iterator variables: i, j
Python program:
def difference ( arr , n ) :
    d1 = 0
    d2 = 0
    for i in range ( 0 , n ) :
        for j in range ( 0 , n ) :
            if ( i == j ) :
                d1 += arr [ i ] [ j ]
            if ( i == n - j - 1 ) :
                d2 += arr [ i ] [ j ]
    return abs ( d1 - d2 ) ;
n = 3
arr = [ [ 11 , 2 , 4 ] , [ 4 , 5 , 6 ] , [ 10 , 8 , - 12 ] ]
print ( difference ( arr , n ) )

Index/key variables: i, j
Accumulator variables: d1, d2
Iterator variables: i, j