Largest product in a grid: Difference between revisions
m
→{{header|julia}}
(julia example) |
|||
Line 30:
=={{header|
<lang julia>mat = [
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
Line 63:
<lang julia>let
nrow, ncol = size(mat)
maxprod, maxrow, maxcol, arr = 0, 0:0, 0:0, [0]
for row in 1:nrow, col in 1:ncol
if row < nrow - 2
pro = prod(mat[row:row+3, col])
if pro > maxprod
maxprod, maxrow, maxcol, arr = pro, row:row+3, col:col, mat[row:row+3, col]
end
end
Line 74:
pro = prod(mat[row, col:col+3])
if pro > maxprod
maxprod, maxrow, maxcol, arr = pro, row:row, col:col+3, mat[row, col:col+3]
end
end
end
println("The maxiumum product is $maxprod, product of $arr at row $maxrow, col $maxcol")
end
</lang>{{out}}
<pre>The maxiumum product is 51267216, product of [66, 91, 88, 97] at row 7:10, col 16:16</pre>
=={{header|Ring}}==
|