Heronian triangles: Difference between revisions

(→‎{{header|Ada}}: New solved task)
Line 4,497:
(3, 148, 149) perimiter = 300; area = 210
</pre>
=={{header|VBA}}==
{{trans|Phix}}<lang vb>Function heroArea(a As Integer, b As Integer, c As Integer) As Double
s = (a + b + c) / 2
On Error GoTo Err
heroArea = Sqr(s * (s - a) * (s - b) * (s - c))
Exit Function
Err:
heroArea = -1
End Function
Function hero(h As Double) As Boolean
hero = (h - Int(h) = 0) And h > 0
End Function
Public Sub main()
Dim list() As Variant, items As Integer
Dim a As Integer, b As Integer, c As Integer
Dim hArea As Double
Dim tries As Long
For a = 1 To 200
For b = 1 To a
For c = 1 To b
tries = tries + 1
If gcd(gcd(a, b), c) = 1 Then
hArea = heroArea(a, b, c)
If hero(hArea) Then
ReDim Preserve list(items)
list(items) = Array(CStr(hArea), CStr(a + b + c), CStr(a), CStr(b), CStr(c))
items = items + 1
End If
End If
Next c
Next b
Next a
list = sort(list)
Debug.Print "Primitive Heronian triangles with sides up to 200:"; UBound(list) + 1; "(of"; tries; "tested)"
Debug.Print
Debug.Print "First 10 ordered by area/perimeter/sides:"
Debug.Print "area perimeter sides"
For i = 0 To 9
Debug.Print Format(list(i)(0), "@@@"), Format(list(i)(1), "@@@"),
Debug.Print list(i)(2); "x"; list(i)(3); "x"; list(i)(4)
Next i
Debug.Print
Debug.Print "area = 210:"
Debug.Print "area perimeter sides"
For i = 0 To UBound(list)
If Val(list(i)(0)) = 210 Then
Debug.Print Format(list(i)(0), "@@@"), Format(list(i)(1), "@@@"),
Debug.Print list(i)(2); "x"; list(i)(3); "x"; list(i)(4)
End If
Next i
End Sub</lang>{{out}}
<pre>Primitive Heronian triangles with sides up to 200: 517 (of 1353400 tested)
 
First 10 ordered by area/perimeter/sides:
area perimeter sides
6 12 5x4x3
12 16 6x5x5
12 18 8x5x5
24 32 15x13x4
30 30 13x12x5
36 36 17x10x9
36 54 26x25x3
42 42 20x15x7
60 36 13x13x10
60 40 17x15x8
 
area = 210:
area perimeter sides
210 70 28x25x17
210 70 29x21x20
210 84 37x35x12
210 84 39x28x17
210 140 68x65x7
210 300 149x148x3</pre>
=={{header|zkl}}==
{{trans|Python}}
255

edits