Anonymous user
Heronian triangles: Difference between revisions
Better D entry
(Promote from draft to full task status.) |
(Better D entry) |
||
Line 51:
enum uint maxSide = 200;
//auto h = cartesianProduct!3(iota(1, maxSide + 1))
auto r = iota(1, maxSide + 1);
//.filter!({a, b, c} => ...
.filter!(t => t[0] <= t[1] && t[1] <= t[2] &&
t[0] + t[1] > t[2] &&
t[].gcd3 == 1 && t[].isHeronian)
.array
.release;
static void showTriangles(R)(R ts) @safe {
▲ // By increasing area, perimeter, then sides.
"Area Perimeter Sides".writeln;▼
▲ h.schwartzSort!(t => tuple(t[].hero, t[].only.sum, t.reverse));
}
writefln("Primitive Heronian triangles with sides up to %d: %d", maxSide, h.length);
"\nFirst ten when ordered by increasing area, then perimeter,then maximum sides:".writeln;
showTriangles(h.take(10));
▲ "Area Perimeter Sides".writeln;
▲ foreach (immutable t; h.take(10))
▲ writefln(fmt, t[].hero, t[].only.sum, t[]);
"\nAll with area 210 subject to the previous ordering:".writeln;
▲ foreach (immutable t; h.filter!(t => t[].hero == 210))
}</lang>
{{out}}
|