RosettaCodeData/Task/Pythagorean-triples/PL-I/pythagorean-triples-2.pli
2014-04-02 16:56:35 +00:00

32 lines
818 B
Text

pythagorean: procedure options (main, reorder); /* 23 January 2014 */
declare (a, b, c) fixed (3);
declare (asquared, bsquared) fixed;
declare (triples, primitives) fixed binary(31) initial (0);
do a = 1 to 100;
asquared = a*a;
do b = a+1 to 100;
bsquared = b*b;
do c = b+1 to 100;
if a+b+c <= 100 then
if asquared + bsquared = c*c then
do;
triples = triples + 1;
if GCD(a,b) = 1 then primitives = primitives + 1;
end;
end;
end;
end;
put skip data (triples, primitives);
GCD: procedure (a, b) returns (fixed binary (31)) recursive;
declare (a, b) fixed binary (31);
if b = 0 then return (a);
return (GCD (b, mod(a, b)) );
end GCD;
end pythagorean;