user
Hero's formula for the area of a triangle given the length of its three sides    *a*,   *b*,   and   *c*   is given by:

:   :   :   :   A
                =


                s
                (
                s
                −
                a
                )
                (
                s
                −
                b
                )
                (
                s
                −
                c
                )
                ,
                {\displaystyle {\displaystyle A={\sqrt {s(s-a)(s-b)(s-c)}},}}

where   *s*   is half the perimeter of the triangle; that is,

:   :   :   :   s
                =

                a
                +
                b
                +
                c
                2
                .
                {\displaystyle {\displaystyle s={\frac {a+b+c}{2}}.}}

**Heronian triangles**
are triangles whose sides *and area* are all integers.

:   An example is the triangle with sides   **3, 4, 5**   whose area is   **6**   (and whose perimeter is   **12**).

Note that any triangle whose sides are all an integer multiple of   **3, 4, 5**;   such as   **6, 8, 10,**   will also be a Heronian triangle.

Define a **Primitive Heronian triangle** as a Heronian triangle where the greatest common divisor
of all three sides is   **1**   (unity).

This will exclude, for example, triangle   **6, 8, 10.**

Task

1. Create a named function/method/procedure/... that implements Hero's formula.
2. Use the function to generate all the *primitive* Heronian triangles with sides <= 200.
3. Show the count of how many triangles are found.
4. Order the triangles by first increasing area, then by increasing perimeter, then by increasing maximum side lengths
5. Show the first ten ordered triangles in a table of sides, perimeter, and area.
6. Show a similar ordered table for those triangles with area = 210

Show all output here.

**Note**: when generating triangles it may help to restrict 

a
<=
b
<=
c
{\displaystyle {\displaystyle a<=b<=c}}
assistant
(formerly Perl 6)

**Works with**: Rakudo version 2018.09

```
sub hero($a, $b, $c) {
    my $s = ($a + $b + $c) / 2;
    ($s * ($s - $a) * ($s - $b) * ($s - $c)).sqrt;
}
 
sub heronian-area($a, $b, $c) {
    $_ when Int given hero($a, $b, $c).narrow;
} 

sub primitive-heronian-area($a, $b, $c) {
    heronian-area $a, $b, $c
        if 1 == [gcd] $a, $b, $c;
}

sub show(@measures) {
    say "   Area Perimeter   Sides";
    for @measures -> [$area, $perim, $c, $b, $a] {
	printf "%6d %6d %12s\n", $area, $perim, "$a×$b×$c";
    }
}
 
sub MAIN ($maxside = 200, $first = 10, $witharea = 210) {
    my @hh[1000];
    my atomicint $i;
    (1 .. $maxside).race(:12batch).map: -> $c {
        for 1 .. $c -> $b {
            for $c - $b + 1 .. $b -> $a {
                if primitive-heronian-area($a,$b,$c) -> $area {
                    @hh[$i⚛++] = [$area, $a+$b+$c, $c, $b, $a];
                }
            }
        }
    }

    my @h = (@hh.grep: so *).sort;
    say "Primitive Heronian triangles with sides up to $maxside: ", +@h;

    say "\nFirst $first:";
    show @h[^$first];

    say "\nArea $witharea:";
    show @h.grep: *[0] == $witharea;
}

```

Output:

```
Primitive Heronian triangles with sides up to 200: 517

First 10:
   Area Perimeter   Sides
     6     12        3×4×5
    12     16        5×5×6
    12     18        5×5×8
    24     32      4×13×15
    30     30      5×12×13
    36     36      9×10×17
    36     54      3×25×26
    42     42      7×15×20
    60     36     10×13×13
    60     40      8×15×17

Area 210:
   Area Perimeter   Sides
   210     70     17×25×28
   210     70     20×21×29
   210     84     12×35×37
   210     84     17×28×39
   210    140      7×65×68
   210    300    3×148×149
```