Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for The Angles of a Triangle by Rounin
import math
def checkio(a, b, c):
lengths = sorted([a, b, c])
try:
radius = a*b*c/math.sqrt((a+b+c)*(a-b+c)*(a+b-c)*(-a+b+c))
angles = sorted(map(lambda x : math.asin(x/(2.0*radius)), lengths))
# Sometimes we have an angle greater than 90 degrees
if lengths[2] > math.sqrt(lengths[0]*lengths[0]+lengths[1]*lengths[1]):
angles[2] = math.pi - angles[2]
return list(map(lambda x: round((180*x)/sum(angles)), angles))
except:
return [0, 0, 0]
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio(4, 4, 4) == [60, 60, 60], "All sides are equal"
assert checkio(3, 4, 5) == [37, 53, 90], "Egyptian triangle"
assert checkio(2, 2, 5) == [0, 0, 0], "It's can not be a triangle"
July 21, 2017