Largest product in a grid: Difference between revisions
m
→{{header|Julia}}: sp
SqrtNegInf (talk | contribs) (→{{header|Perl}}: Added alternate version) |
m (→{{header|Julia}}: sp) |
||
Line 198:
<pre>The maximum product of 4 adjacent horizontal or vertical in the matrix is: 51267216</pre>
Alternatively, to get the position of the maximum product:
<lang julia>
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 - len + 2
pro = prod(mat[row:row+
if pro > maxprod
maxprod, maxrow, maxcol, arr = pro, row:row+
end
end
if col < ncol - len + 2
pro = prod(mat[row, col:col+
if pro > maxprod
maxprod, maxrow, maxcol, arr = pro, row:row, col:col+
end
end
end
println("The
end
maxprod(mat, 4)
</lang>{{out}}
<pre>The
=={{header|Perl}}==
|