Largest product in a grid: Difference between revisions

m
Line 323:
from math import prod
 
def maxproduct(mat, lengthnlen):
""" find the largest product of len length horizontal or vertical length in matrix """
length, nrow, ncol = nlen - 1, len(mat), len(mat[0])
maxprod, maxrow, maxcol, arr = 0, [0, 0], [0, 0], [0]
for row in range(nrow):
Line 340:
maxprod, maxrow, maxcol, arr = pro, row, [col, col2], mat[row][col:col2]
 
print(f"The max {lengthnlen}-product is {maxprod}, product of {arr} at row {maxrow}, col {maxcol}.")
 
MATRIX = [
Line 369:
</lang>{{out}}
<pre>
The maximummax 2-product is 7767769215, product of [91, 8895, 97] at row [7, 109], col 158.
The maximummax 3-product is 51267216776776, product of [66, 91, 88, 97] at row [67, 10], col 15.
The maximummax 4-product is 232682986851267216, product of [6266, 9991, 6988, 82, 6797] at row 17[6, 10], col [9, 14]15.
The maximummax 5-product is 1882105127102326829868, product of [62, 99, 69, 82, 67, 59, 85] at row 17, col [109, 1614].
</pre>
 
 
=={{header|Raku}}==
4,102

edits