diff --git a/main.py b/main.py new file mode 100644 index 0000000..bd6dc2d --- /dev/null +++ b/main.py @@ -0,0 +1,35 @@ +from tabulate import tabulate + +from numeric.compute import matmul, transpose, rot_2D +from util.tools import substring + +if __name__ == '__main__': + # Substring + original = "GEEKSFORGEEKS" + # print(substring(original, 0, 5)) # Output: GEEKS + # print(substring(original, 5)) # Output: FORGEEKS + + # Matrix multiplication + matrix_a = [[3, 4, -1, 4], + [-2, 2, 5, 1] + ] + matrix_b = [[1, 3, -2], + [2, 5, 1], + [-1, 4, -4], + [2, 3, 6] + ] + matrix_c = matmul(matrix_a, matrix_b) + # print("Ergebnis C = A * B:") + + # for row in matrix_c: + # print(row) + + # Transposition + matrix = [ + [1, 2, 3], + [4, 5, 6] + ] + # print(tabulate(transpose(matrix))) + + # Rotation + print(tabulate(rot_2D(90))) diff --git a/numeric/__init__.py b/numeric/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..470d877 Binary files /dev/null and b/requirements.txt differ diff --git a/util/__init__.py b/util/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/util/tools.py b/util/tools.py new file mode 100644 index 0000000..4e67e39 --- /dev/null +++ b/util/tools.py @@ -0,0 +1,21 @@ +def substring(string: str, start: int, end: int = 0) -> str: + """ + A substring function + :param string: The string + :param start: The starting index + :param end: The ending index. If None, this is set to the length of the substring :return: + """ + if not isinstance(string, str): + raise ValueError("No string provided") + if not isinstance(start, int): + raise ValueError("No starting index provided") + + if end is None: + end = len(str) + + result = "" + + for i in range(start, end): + result += string[i] + + return result