Rob drew four right-angled triangles. The hypotenuse of his first triangle was also the shortest side of his second triangle; the hypotenuse of his second triangle was also the shortest side of his third triangle; the hypotenuse of his third triangle was also the shortest side of his fourth triangle. The length in millimetres of each side of each triangle was an integer less than 100.
What were the lengths of the shortest and the longest sides that Rob drew?
Note: Adapted from Enigma number 1779 which appeared in New Scientist on 2013.
The code still has some scars from its initial design and debugging statements, but it works:
clearvars,clc
global triangles
triangles=double.empty(0,3);
for st=2:70
addon(st);
end
function addon(st)
global triangles
for a=st
savetri=triangles;
if size(triangles,1)>=1 && a>st
break
end
save2=triangles;
for b=a:100
save2=triangles;
c=sqrt(a^2+b^2);
if c>100
break
end
if c~=round(c)
continue
end
if c==85
xx=99;
end
triangles(end+1,:)=[a,b,c];
if size(triangles,1)>=4
disp(triangles)
disp('-----')
else
addon(c);
end
triangles=save2;
end
triangles=savetri;
end
end
It finds two paths:
9 12 15
15 20 25
25 60 65
65 72 97
-----
9 12 15
15 36 39
39 52 65
65 72 97
-----
|
Posted by Charlie
on 2024-05-06 09:51:24 |