giulio98/xlcost-single-prompt huggingface dataset:
# create a matrix with alternating rectangles of o and x | function to pralternating rectangles of 0 and x ; k - starting row index m - ending row index l - starting column index n - ending column index i - iterator ; store given number of rows and columns for later use ; a 2d array to store the output to be printed ; iniitialize the character to be stoed in a [ ] [ ] ; fill characters in a [ ] [ ] in spiral form . every iteration fills one rectangle of either xs or os ; fill the first row from the remaining rows ; fill the last column from the remaining columns ; fill the last row from the remaining rows ; print the first column from the remaining columns ; flip character for next iteration ; print the filled matrix ; 
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)

# Expected output:
Output for m = 5, n = 6
X X X X X X 
X 0 0 0 0 X 
X 0 X X 0 X 
X 0 0 0 0 X 
X X X X X X 
Output for m = 4, n = 4
X X X X 
X 0 0 X 
X 0 0 X 
X X X X 
Output for m = 3, n = 4
X X X X 
X 0 0 X 
X X X X
# zigzag ( or diagonal ) traversal of matrix |  ; we will use a 2d vector to store the diagonals of our array the 2d vector will have ( n + m - 1 ) rows that is equal to the number of diagnols ; 

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)

# Expected output:
1 
5 2 
9 6 3 
13 10 7 4 
17 14 11 8 
18 15 12 
19 16 
20
# minimum cost to sort a matrix of numbers from 0 to n ^ 2 | implementation to find the total energy required to rearrange the numbers ; function to find the total energy required to rearrange the numbers ; nested loops to access the elements of the given matrix ; store quotient ; final destination location ( i_des , j_des ) of the element mat [ i ] [ j ] is being calculated ; energy required for the movement of the element mat [ i ] [ j ] is calculated and then accumulated in the 'tot_energy   ; required total energy ; 

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")

# Expected output:
Total energy required =  22 units
# unique cells in a binary matrix | python3 program to count unique cells in a matrix ; returns true if mat [ i ] [ j ] is unique ; checking in row calculating sumrow will be moving column wise ; checking in column calculating sumcol will be moving row wise ; 

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))

# Expected output:
2
# unique cells in a binary matrix | efficient python3 program to count unique cells in a binary matrix ; count number of 1 s in each row and in each column ; using above count arrays , find cells ; 

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))

# Expected output:
2
# check if a given matrix is sparse or not | python 3 code to check if a matrix is sparse . ; count number of zeros in the matrix ; 

MAX = 100


def isSparse(array, m, n):
    counter = 0
    for i in range(0, m):
        for j in range(0, n):
            if (array[i][j] == 0):
                counter = counter + 1
    return (counter > ((m * n) // 2))


array = [[1, 0, 3], [0, 0, 4], [6, 0, 0]]
m = 3
n = 3
if (isSparse(array, m, n)):
    print("Yes")
else:
    print("No")

# Expected output:
Yes
# row | python3 program to find common elements in two diagonals . ; returns count of row wise same elements in two diagonals of mat [ n ] [ n ] ; 

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))

# Expected output:
1
# Check if sums of i | Python3 program to check the if sum of a row is same as corresponding column ; Function to check the if sum of a row is same as corresponding column ; number of rows ; number of columns

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))

# Expected output:
1
# find row number of a binary matrix having maximum number of 1 s | python program to find row with maximum 1 in row sorted binary matrix ; function for finding row with maximum 1 ; find left most position of 1 in a row find 1 st zero in a row ; 

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)

# Expected output:
Row number =  4 , MaxCount =  3
# program to print matrix in z form | python3 program to pra square matrix in z form ; 
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)

# Expected output:
4 5 6 8 2 9 1 8 7 5
# print all palindromic paths from top left to bottom right in a matrix | python 3 program to print all palindromic paths from top left to bottom right in a grid . ; i and j are row and column indexes of current cell ( initially these are 0 and 0 ) . ; if we have not reached bottom right corner , keep exlporing ; if we reach bottom right corner , we check if the path used is palindrome or not . ; 
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)

# Expected output:
abaaba
aaaaaa
aaaaaa
# possible moves of knight | python3 program to find number of possible moves of knight ; to calculate possible moves ; all possible moves of a knight ; check if each possible move is valid or not ; position of knight after move ; count valid moves ; return number of possible moves ; 

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))

# Expected output:
4
# efficiently compute sums of diagonals of a matrix | a simple python program to find sum of diagonals ; condition for principal diagonal ; condition for secondary diagonal ; 

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)

# Expected output:
Principal Diagonal: 18
Secondary Diagonal: 18
# efficiently compute sums of diagonals of a matrix | a simple python3 program to find sum of diagonals ; 

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)

# Expected output:
Principal Diagonal: 18
Secondary Diagonal: 18
# boundary elements of a matrix | python program to print boundary element of the matrix . ; 

MAX = 100


def printBoundary(a, m, n):
    for i in range(m):
        for j in range(n):
            if (i == 0):
                print(a[i][j],)
            elif (i == m - 1):
                print(a[i][j],)
            elif (j == 0):
                print(a[i][j],)
            elif (j == n - 1):
                print(a[i][j],)
            else:
                print(" ",)
        print


a = [[1, 2, 3, 4], [5, 6, 7, 8], [1, 2, 3, 4], [5, 6, 7, 8]]
printBoundary(a, 4, 4)

# Expected output:
1
2
3
4
5
 
 
8
1
 
 
4
5
6
7
8
# boundary elements of a matrix | python program to print boundary element of the matrix . ; 

MAX = 100


def printBoundary(a, m, n):
    sum = 0
    for i in range(m):
        for j in range(n):
            if (i == 0):
                sum += a[i][j]
            elif (i == m - 1):
                sum += a[i][j]
            elif (j == 0):
                sum += a[i][j]
            elif (j == n - 1):
                sum += a[i][j]
    return sum


a = [[1, 2, 3, 4], [5, 6, 7, 8], [1, 2, 3, 4], [5, 6, 7, 8]]
sum = printBoundary(a, 4, 4)
print("Sum of boundary elements is", sum)

# Expected output:
Sum of boundary elements is 54
# print a matrix in a spiral form starting from a point | python3 program to print a matrix in spiral form . ; 

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)

# Expected output:
3 6 5 2 9 8 7 4 1
# program to interchange diagonals of matrix | python program to interchange the diagonals of matrix ; function to interchange diagonals ; swap elements of diagonal ; 

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)

# Expected output:
6 5 4 
1 2 3 
9 8 7
# find difference between sums of two diagonals | python3 program to find the difference between the sum of diagonal . ; initialize sums of diagonals ; finding sum of primary diagonal ; finding sum of secondary diagonal ; absolute difference of the sums across the diagonals ; 
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))

# Expected output:
15
# find difference between sums of two diagonals | python3 program to find the difference between the sum of diagonal . ; initialize sums of diagonals ; absolute difference of the sums across the diagonals ; 
def difference(arr, n):
    d1 = 0
    d2 = 0
    for i in range(0, n):
        d1 = d1 + arr[i][i]
        d2 = d2 + arr[i][n - i - 1]
    return abs(d1 - d2)


n = 3
arr = [[11, 2, 4], [4, 5, 6], [10, 8, -12]]
print(difference(arr, n))

# Expected output:
15
# circular matrix ( construct a matrix with numbers 1 to m * n in spiral way ) | fills a [ m ] [ n ] with values from 1 to m * n in spiral fashion . ; initialize value to be filled in matrix . ; k - starting row index m - ending row index l - starting column index n - ending column index ; print the first row from the remaining rows . ; print the last column from the remaining columns . ; print the last row from the remaining rows . ; print the first column from the remaining columns . ; 
def spiralFill(m, n, a):
    val = 1
    k, l = 0, 0
    while (k < m and l < n):
        for i in range(l, n):
            a[k][i] = val
            val += 1
        k += 1
        for i in range(k, m):
            a[i][n - 1] = val
            val += 1
        n -= 1
        if (k < m):
            for i in range(n - 1, l - 1, -1):
                a[m - 1][i] = val
                val += 1
            m -= 1
        if (l < n):
            for i in range(m - 1, k - 1, -1):
                a[i][l] = val
                val += 1
            l += 1


if __name__ == '__main__':
    m, n = 4, 4
    a = [[0 for j in range(m)]for i in range(n)]
    spiralFill(m, n, a)
    for i in range(m):
        for j in range(n):
            print(a[i][j], end=' ')
        print('')

# Expected output:
1 2 3 4 
12 13 14 5 
11 16 15 6 
10 9 8 7
# prufer code to tree creation | prints edges of tree represented by give prufer code ; initialize the array of vertices ; number of occurrences of vertex in code ; find the smallest label not present in prufer . ; if j + 1 is not present in prufer set ; remove from prufer set and print pair . ; for the last element ; 
def printTreeEdges(prufer, m):
    vertices = m + 2
    vertex_set = [0] * vertices
    for i in range(vertices - 2):
        vertex_set[prufer[i] - 1] += 1
    print("The edge set E(G) is :")
    j = 0
    for i in range(vertices - 2):
        for j in range(vertices):
            if (vertex_set[j] == 0):
                vertex_set[j] = -1
                print("(", (j + 1), ", ", prufer[i], ") ", sep="", end="")
                vertex_set[prufer[i] - 1] -= 1
                break
    j = 0
    for i in range(vertices):
        if (vertex_set[i] == 0 and j == 0):
            print("(", (i + 1), ", ", sep="", end="")
            j += 1
        elif (vertex_set[i] == 0 and j == 1):
            print((i + 1), ")")


prufer = [4, 1, 3, 4]
n = len(prufer)
printTreeEdges(prufer, n)

# Expected output:
The edge set E(G) is :
(2, 4) (5, 1) (1, 3) (3, 4) (4, 6 )
# maximum and minimum in a square matrix . | python3 program for finding maximum and minimum in a matrix . ; finds maximum and minimum in arr [ 0. . n - 1 ] [ 0. . n - 1 ] using pair wise comparisons ; traverses rows one by one ; compare elements from beginning and end of current row ; 

MAX = 100


def MAXMIN(arr, n):
    MIN = 10 ** 9
    MAX = -10 ** 9
    for i in range(n):
        for j in range(n // 2 + 1):
            if (arr[i][j] > arr[i][n - j - 1]):
                if (MIN > arr[i][n - j - 1]):
                    MIN = arr[i][n - j - 1]
                if (MAX < arr[i][j]):
                    MAX = arr[i][j]
            else:
                if (MIN > arr[i][j]):
                    MIN = arr[i][j]
                if (MAX < arr[i][n - j - 1]):
                    MAX = arr[i][n - j - 1]
    print("MAXimum =", MAX, ", MINimum =", MIN)


arr = [[5, 9, 11], [25, 0, 14], [21, 6, 4]]
MAXMIN(arr, 3)

# Expected output:
MAXimum = 25 , MINimum = 0
# print matrix in antispiral form | python 3 program to print matrix in anti - spiral form ; k - starting row index m - ending row index l - starting column index n - ending column index i - iterator ; print the first row from the remaining rows ; print the last column from the remaining columns ; print the last row from the remaining rows ; print the first column from the remaining columns ; 

R = 4
C = 5


def antiSpiralTraversal(m, n, a):
    k = 0
    l = 0
    stk = []
    while (k <= m and l <= n):
        for i in range(l, n + 1):
            stk .append(a[k][i])
        k += 1
        for i in range(k, m + 1):
            stk .append(a[i][n])
        n -= 1
        if (k <= m):
            for i in range(n, l - 1, -1):
                stk .append(a[m][i])
            m -= 1
        if (l <= n):
            for i in range(m, k - 1, -1):
                stk .append(a[i][l])
            l += 1
    while len(stk) != 0:
        print(str(stk[-1]), end=" ")
        stk .pop()


mat = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [
    11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]
antiSpiralTraversal(R - 1, C - 1, mat)

# Expected output:
12 13 14 9 8 7 6 11 16 17 18 19 20 15 10 5 4 3 2 1
# minimum operations required to set all elements of binary matrix | return minimum operation required to make all 1 s . ; check if this cell equals 0 ; increase the number of moves ; flip from this cell to the start point ; flip the cell ; 
def minOperation(arr):
    ans = 0
    for i in range(N - 1, -1, -1):
        for j in range(M - 1, -1, -1):
            if (arr[i][j] == 0):
                ans += 1
                for k in range(i + 1):
                    for h in range(j + 1):
                        if (arr[k][h] == 1):
                            arr[k][h] = 0
                        else:
                            arr[k][h] = 1
    return ans


mat = [[0, 0, 1, 1, 1], [0, 0, 0, 1, 1], [
    0, 0, 0, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]
M = 5
N = 5
print(minOperation(mat))

# Expected output:
3
# sum of matrix element where each elements is integer division of row and column | return sum of matrix element where each element is division of its corresponding row and column . ; for each column . ; count the number of elements of each column . initialize to i - 1 because number of zeroes are i - 1. ; for multiply ; 
def findSum(n):
    ans = 0
    temp = 0
    for i in range(1, n + 1):
        if temp < n:
            temp = i - 1
            num = 1
            while temp < n:
                if temp + i <= n:
                    ans += i * num
                else:
                    ans += (n - temp) * num
                temp += i
                num += 1
    return ans


N = 2
print(findSum(N))

# Expected output:
3
# find number of transformation to make two matrix equal | python3 program to find number of countopsation to make two matrix equals ; update matrix a [ ] [ ] so that only a [ ] [ ] has to be countopsed ; check necessary condition for condition for existence of full countopsation ; if countopsation is possible calculate total countopsation ; 
def countOps(A, B, m, n):
    for i in range(n):
        for j in range(m):
            A[i][j] -= B[i][j]
    for i in range(1, n):
        for j in range(1, n):
            if (A[i][j] - A[i][0] - A[0][j] + A[0][0] != 0):
                return -1
    result = 0
    for i in range(n):
        result += abs(A[i][0])
    for j in range(m):
        result += abs(A[0][j] - A[0][0])
    return (result)


if __name__ == '__main__':
    A = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]
    B = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
    print(countOps(A, B, 3, 3))

# Expected output:
12
# 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 ; 
def printCoils(n):
    m = 8 * n * n
    coil1 = [0] * m
    coil1[0] = 8 * n * n + 2 * n
    curr = coil1[0]
    nflg = 1
    step = 2
    index = 1
    while (index < m):
        for i in range(step):
            curr = coil1[index] = (curr - 4 * n * nflg)
            index += 1
            if (index >= m):
                break
        if (index >= m):
            break
        for i in range(step):
            curr = coil1[index] = curr + nflg
            index += 1
            if (index >= m):
                break
        nflg = nflg * (-1)
        step += 2
    coil2 = [0] * m
    i = 0
    while (i < 8 * n * n):
        coil2[i] = 16 * n * n + 1 - coil1[i]
        i += 1
    print("Coil 1 :", end=" ")
    i = 0
    while (i < 8 * n * n):
        print(coil1[i], end=" ")
        i += 1
    print("Coil2:",  end="")
    i = 0
    while (i < 8 * n * n):
        print(coil2[i], end=" ")
        i += 1


n = 1
printCoils(n)

# Expected output:
Coil 1 : 10 6 2 3 4 8 12 16 Coil2:7 11 15 14 13 9 5 1
# sum of matrix in which each element is absolute difference of its row and column numbers | return the sum of matrix in which each element is absolute difference of its corresponding row and column number row ; generate matrix ; compute sum ; 
def findSum(n):
    arr = [[0 for x in range(n)]for y in range(n)]
    for i in range(n):
        for j in range(n):
            arr[i][j] = abs(i - j)
    sum = 0
    for i in range(n):
        for j in range(n):
            sum += arr[i][j]
    return sum


if __name__ == "__main__":
    n = 3
    print(findSum(n))

# Expected output:
8