Heronian triangles: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
(added Arturo)
Line 801: Line 801:
(7, 65, 68) 140 210
(7, 65, 68) 140 210
(3, 148, 149) 300 210</pre>
(3, 148, 149) 300 210</pre>

=={{header|Arturo}}==
<syntaxhighlight lang="arturo">printTable: function [title, rows][
print title ++ ":"
print repeat "=" 60

prints pad.center "A" 10
prints pad.center "B" 10
prints pad.center "C" 10
prints pad.center "Perimeter" 15
print pad.center "Area" 15
print repeat "-" 60

loop rows 'row [
prints pad.center to :string row\0 10
prints pad.center to :string row\1 10
prints pad.center to :string row\2 10
prints pad.center to :string row\3 15
print pad.center to :string row\4 15
]
print ""
]

hero: function [a,b,c][
s: (a + b + c) // 2
return sqrt(s * (s-a) * (s-b) * (s-c))
]

heronian?: function [x]->
and? -> x > 0
-> x = ceil x

lst: []
mx: 200

loop 1..mx 'c ->
loop 1..c 'b ->
loop 1..b 'a [
area: hero a b c
if and? [heronian? area] [one? gcd @[a b c]]->
'lst ++ @[
@[a, b, c, a + b + c, to :integer area]
]
]

print ["Number of Heronian triangles:" size lst]
print ""

lst: arrange lst 'item ->
(item\4 * 10000) + (item\3 * 100) + max first.n:3 item

printTable "Ordered list of first ten Heronian triangles" first.n: 10 lst
printTable "Ordered list of Heronian triangles with area 210" select lst 'x -> x\4 = 210</syntaxhighlight>

{{out}}

<pre>Number of Heronian triangles: 517

Ordered list of first ten Heronian triangles:
============================================================
A B C Perimeter Area
------------------------------------------------------------
3 4 5 12 6
5 5 6 16 12
5 5 8 18 12
4 13 15 32 24
5 12 13 30 30
9 10 17 36 36
3 25 26 54 36
7 15 20 42 42
10 13 13 36 60
8 15 17 40 60

Ordered list of Heronian triangles with area 210:
============================================================
A B C Perimeter Area
------------------------------------------------------------
17 25 28 70 210
20 21 29 70 210
12 35 37 84 210
17 28 39 84 210
7 65 68 140 210
3 148 149 300 210</pre>


=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==