MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_345/sol1.py:95–113  ·  view source on GitHub ↗

Takes list of strings `matrix_str` to parse the matrix and calculates the max sum. >>> solution(["1 2", "3 4"]) 5 >>> solution(MATRIX_1) 3315

(matrix_str: list[str] = MATRIX_2)

Source from the content-addressed store, hash-verified

93
94
95def solution(matrix_str: list[str] = MATRIX_2) -> int:
96 """
97 Takes list of strings `matrix_str` to parse the matrix and calculates the max sum.
98
99 >>> solution(["1 2", "3 4"])
100 5
101 >>> solution(MATRIX_1)
102 3315
103 """
104
105 n = len(matrix_str)
106 arr = np.empty(shape=(n, n), dtype=int)
107 for row, matrix_row_str in enumerate(matrix_str):
108 matrix_row_list_str = matrix_row_str.split()
109 for col, elem_str in enumerate(matrix_row_list_str):
110 arr[row, col] = int(elem_str)
111
112 cache: dict[str, int] = {}
113 return solve(arr=arr, row=0, cols=set(range(n)), cache=cache)
114
115
116if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 3

splitMethod · 0.80
solveFunction · 0.70
emptyMethod · 0.45

Tested by

no test coverage detected