Now I'm really challenging myself - can I get a solution to a problem without the fan kicking on? This one took a few tries, but I finally found a good algorithm.
We're asked to find the pythagorean triplet (a, b, c) that sums to 1000. I made an educated guess as to a good range for c, to limit the search space.
function euler9
% a < b < c
for cc = 500:-1:300
aa_bb = 1000-cc;
for bb = aa_bb-1:-1:1
aa = aa_bb - bb;
if (aa*aa + bb*bb) == cc*cc
disp([num2str(aa), ", ", num2str(bb), ", ", num2str(cc)]);
aa*bb*cc
return;
end
end
end
This problem reminded me of Professor Rida Farouki, who teaches his students the value of conserving computations in CAD systems, and who has written several papers on Pythagorean hodograph curves.