Heronian triangles: Difference between revisions

(New draft task and Python solution.)
 
Line 31:
=={{header|Python}}==
<lang python>from math import sqrt
from pprint import pprint as pp
 
 
Line 42 ⟶ 41:
def is_heronian(a, b, c):
a = hero(a, b, c)
return a ==> int(a)0 ifand a else False.is_integer()
 
Line 53 ⟶ 52:
h = [(a, b, c) for a,b,c in product(range(1, maxside + 1), repeat=3)
if a <= b <= c and a + b > c and gcd3(a, b, c) == 1 and is_heronian(a, b, c)]
#h.sort(key = lambda x: x[::-1]) # By longest side
#h.sort(key = lambda x: sum(x)) # By increasing perimeter
#h.sort(key = lambda x: hero(*x)) # By increasing area
#h.sort(key = lambda x: (hero(*x), sum(x))) # By increasing area then perimeter
h.sort(key = lambda x: (hero(*x), sum(x), x[::-1])) # By increasing area, perimeter, then sides
print('Primitive Heronian triangles with sides up to %i:' % maxside, len(h))
Anonymous user