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 slygoblin
import math
def checkio(a, b, c):
result = []
if (a + b <= c) or (a + c <= b) or (b + c <= a):
result.append(0)
result.append(0)
result.append(0)
elif (a == b) and (a == c) and (b == c):
result.append(60)
result.append(60)
result.append(60)
elif a*a == b*b + c*c or b*b == a*a + c*c or c*c == a*a + b*b:
if a > b and a > c:
result.append(90)
result.append(round(math.degrees(math.acos(b/a))))
result.append(round(math.degrees(math.acos(c/a))))
if b > a and b > c:
result.append(90)
result.append(round(math.degrees(math.acos(a/b))))
result.append(round(math.degrees(math.acos(c/b))))
if c > a and c > b:
result.append(90)
result.append(round(math.degrees(math.acos(a/c))))
result.append(round(math.degrees(math.acos(b/c))))
result.sort()
else:
result.append(round(math.degrees(math.acos(a/((2*a*a*b)/(a*a+b*b-c*c))))))
result.append(round(math.degrees(math.acos(b/((2*b*b*c)/(b*b+c*c-a*a))))))
result.append(round(math.degrees(math.acos(c/((2*c*c*a)/(c*c+a*a-b*b))))))
result.sort()
return result
#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"
Dec. 10, 2015