# Predmet: Robotizovani sistemi u industriji
# Autor: Mladen Draganović
# Broj indeksa: IT68/2019
# Kontakt: draganovic.it68.2019@uns.ac.rs
# Datum: 05.05.2022.
# Projekat: Množenje matrica
# Verzija: 1.0

class Matrix:
    def __init__(self, rows, columns, initial_value=0):
        self.items = [[initial_value for _ in range(
            columns)] for _ in range(rows)]
        self.rows = rows
        self.columns = columns

    def set(self, row, column, value):
        self.items[row][column] = value

    def dot(self, other):
        if self.columns != other.rows:
            raise Exception("Matrices must be of the same size")

        result = Matrix(self.rows, other.columns)

        for row in range(self.rows):
            for column in range(other.columns):
                for i in range(self.columns):
                    result.items[row][column] += self.items[row][i] * \
                        other.items[i][column]

        return result

    def __str__(self) -> str:
        return '\n'.join(['\t'.join([str(val) for val in row]) for row in self.items])


M1 = Matrix(3, 3, 3)
M2 = Matrix(3, 3, 2)
M1.set(2, 2, 10)

print()
print('Matrix M1:')
print(M1)
print()
print('Matrix M2:')
print(M2)
print()
print('Result of M1 * M2:')
print(M1.dot(M2))
print()
