Heronian triangles: Difference between revisions
Content deleted Content added
m →{{header|Python}}: (Replaced deprecated fractions.gcd with math.gcd) |
→{{header|Python}}: Improved performance by restricting search space - dropped the import of 'product' |
||
Line 3,635:
<lang python>from __future__ import division, print_function
from math import gcd, sqrt
Line 3,654 ⟶ 3,653:
if __name__ == '__main__':
N = 1 + MAXSIDE
h = [(x, y, z)
h.sort(key = lambda x: (hero(*x), sum(x), x[::-1])) # By increasing area, perimeter, then sides▼
for x in range(1, N)
print('Primitive Heronian triangles with sides up to %i:' % maxside, len(h))▼
for y in range(x, N)
print('\nFirst ten when ordered by increasing area, then perimeter,then maximum sides:')▼
for z in range(y, N) if (x + y > z) and
1 == gcd3(x, y, z) and
is_heronian(x, y, z)]
# By increasing area, perimeter, then sides
print(
)
'then maximum sides:')
print('\n'.join(' %14r perim: %3i area: %i'
% (sides, sum(sides), hero(*sides)) for sides in h[:10]))
Line 3,665 ⟶ 3,676:
print('\n'.join(' %14r perim: %3i area: %i'
% (sides, sum(sides), hero(*sides)) for sides in h
if hero(*sides) == 210))
</lang>
{{out}}
<pre>Primitive Heronian triangles with sides up to 200: 517
|