Law of cosines - triples: Difference between revisions

no edit summary
(Added Quackery.)
No edit summary
Line 647:
60 degree triangles in range 1..10000 where not all sides are the same
18394 solutions</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
 
procedure FindTriples(Memo: TMemo; Max,Angle,Coeff: integer);
var Count,A,B,C: integer;
var S: string;
begin
Memo.Lines.Add(Format('Gamma=%d Degrees',[Angle]));
Count:=0;
S:='';
for A:=1 to Max do
for B:=1 to A do
for C:=1 to Max do
if A*A+B*B-Coeff*A*B=C*C then
begin
Inc(Count);
S:=S+Format('(%d,%d,%d) ',[A,B,C]);
if (Count mod 3)=0 then S:=S+CRLF;
end;
Memo.Lines.Add(S);
Memo.Lines.Add(Format('Number of triangles = %d',[Count]));
end;
 
 
 
procedure LawOfCosines(Memo: TMemo);
begin
FindTriples(Memo,13,90,0);
FindTriples(Memo,13,60,1);
FindTriples(Memo,13,120,-1);
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
Gamma= 90°
Number of triangles = 3
(4,3,5) (8,6,10) (12,5,13)
 
Gamma= 60°
Number of triangles = 15
(1,1,1) (2,2,2) (3,3,3)
(4,4,4) (5,5,5) (6,6,6)
(7,7,7) (8,3,7) (8,5,7)
(8,8,8) (9,9,9) (10,10,10)
(11,11,11) (12,12,12) (13,13,13)
 
Gamma= 120°
Number of triangles = 2
(5,3,7) (8,7,13)
 
Elapsed Time: 9.768 ms.
</pre>
 
 
=={{header|Factor}}==
465

edits