RosettaCodeData/Task/Pythagorean-triples/Seed7/pythagorean-triples.seed7
Ingy döt Net b83f433714 tasks a-s
2013-04-10 23:57:08 -07:00

31 lines
887 B
Text

$ include "seed7_05.s7i";
include "bigint.s7i";
var bigInteger: total is 0_;
var bigInteger: prim is 0_;
var bigInteger: max_peri is 10_;
const proc: new_tri (in bigInteger: a, in bigInteger: b, in bigInteger: c) is func
local
var bigInteger: p is 0_;
begin
p := a + b + c;
if p <= max_peri then
incr(prim);
total +:= max_peri div p;
new_tri( a - 2_*b + 2_*c, 2_*a - b + 2_*c, 2_*a - 2_*b + 3_*c);
new_tri( a + 2_*b + 2_*c, 2_*a + b + 2_*c, 2_*a + 2_*b + 3_*c);
new_tri(-a + 2_*b + 2_*c, -2_*a + b + 2_*c, -2_*a + 2_*b + 3_*c);
end if;
end func;
const proc: main is func
begin
while max_peri <= 100000000_ do
total := 0_;
prim := 0_;
new_tri(3_, 4_, 5_);
writeln("Up to " <& max_peri <& ": " <& total <& " triples, " <& prim <& " primitives.");
max_peri *:= 10_;
end while;
end func;