% Pythag
N = 10000;
count = 0;
for a=1:N
for b=a+1:floor(sqrt(N*N-a*a))
x = sqrt(a*a+b*b);
if floor(x)==x
% The hypotenuse has integral length.
count=count+1;
end
end
end
clc
fprintf('The number of Pythagorean triangles with sides <= %4d is %5d\n',N,count)

% Comments on the "b"-loop...

% for b=1:N would result in a double counting. A 3-4-5 triangle is the same
% as a 4-3-5 triangle etc.

% for b=a+1:N is inefficient. Once a is "picked" by the outer loop there
% is no point checking b unless a^2+b^2<=N^2