Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.5 kB
1
Indexable
Never
import numpy as np

row1 = np.array(list(map(int, input().split())))
row2 = np.array(list(map(int, input().split())))
row3 = np.array(list(map(int, input().split())))
row4 = np.array(list(map(int, input().split())))
direction = int(input())

matrix = np.vstack((row1, row2, row3, row4))

def left(matrix):
    for i in range(3): 
        for j in range(1, 3):
            matrix[i][j - 1] += matrix[i][j]
            matrix[i][j] = 0
        matrix[i][3] += matrix[i][0]
        matrix[i][0] = 0

    return matrix

def up(matrix):
    for j in range(3):
        for i in range(1, 3):
            matrix[i - 1][j] += matrix[i][j]
            matrix[i][j] = 0
        matrix[3][j] += matrix[0][j]
        matrix[0][j] = 0

    return matrix

def right(matrix):
    for i in range(3):
        for j in range(1, 3):  
            matrix[i][j + 1] += matrix[i][j]
            matrix[i][j] = 0
        matrix[i][0] += matrix[i][3]
        matrix[i][3] = 0

    return matrix

def down(matrix):
    for j in range(3):
        for i in range(1, 3): 
            matrix[i + 1][j] += matrix[i][j]
            matrix[i][j] = 0
        matrix[0][j] += matrix[3][j]
        matrix[3][j] = 0

    return matrix

if direction == 0:
    result = left(matrix)
elif direction == 1:
    result = up(matrix)
elif direction == 2:
    result = right(matrix)
elif direction == 3:
    result = down(matrix)

print(result)
Leave a Comment