Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Math formula solution in Speedy category for The Angles of a Triangle by odwl
from math import acos
from math import degrees
def checkio(a, b, c):
return list(sorted((compute_angle(a, b, c), compute_angle(c, a, b), compute_angle(b, c, a))))
def compute_angle(a, b, c):
val = (a * a + b * b - c * c)/(2 * a * b)
return round(degrees(acos(val))) if val > -1 and val < 1 else 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"
March 4, 2014
Comments: