Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
As in a book solution in Clear category for The Angles of a Triangle by freeman_lex
from math import degrees, acos
def checkio(a, b, c):
if (a < b + c and b < a + c and c < a + b):
if a == b == c: return [60]*3
else:
f = lambda x, y, z : int(round(degrees(acos((x*x + y*y - z*z)/(2.0*x*y)))))
return sorted([f(a, b, c), f(a, c, b), 180 - f(a, b, c) - f(a, c, b)])
else: return [0]*3
#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"
June 17, 2014