Project Euler: Problem 11
Mostrar comentarios más antiguos
%I have the solution for this problem : https://www.mathworks.com/matlabcentral/cody/groups/50/problems/42936-project-euler-problem-11-largest-product-in-a-grid/solutions/new
% the problem is inspired by Project Euler 11
%It pass 2 test but failed in test 3,i dont know why
%here is my code
function y = PE11(A,k)
[b c]=size(A)
m = 0;
dx = [1, 0, 1,-1];
dy = [0, 1, 1,-1];
%check product on horizontal
for y=1:b
for x=1:c-k
p=1;
for i=0:k-1
p=p*A(y+i*dy(1),x+i*dx(1));
end
m=max(p,m);
end
end
%check product on vertical
for y=1:b-k
for x=1:c
p=1;
for i=0:k-1
p=p*A(y+i*dy(2),x+i*dx(2));
end
m=max(p,m);
end
end
%check product on diagonal form right to left
for y=1:b-k
for x=1:c-k
p=1;
for i=0:k-1
p=p*A(y+i*dy(3),x+i*dx(3));
end
m=max(p,m);
end
end
%check product on diagonal form left to right
for y=b:-1:k
for x=c:-1:k
p=1;
for i=0:k-1
p=p*A(y+i*dy(4),x+i*dx(4));
end
m=max(p,m);
end
end
y=m;
end
1 comentario
John D'Errico
el 16 de Jul. de 2021
Don't add an answer pleading for help. That is not an answer. (I've deleted your non-answer.)
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!