Created
March 20, 2013 15:39
-
-
Save jcasimir/5205706 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def triangle(a, b, c) | |
validate_triangle!(a, b, c) | |
identify_triangle_type(a, b, c) | |
end | |
def validate_triangle!(a, b, c) | |
raise TriangleError if !possible_triangle?(a, b, c) | |
end | |
def identify_triangle_type(a, b, c) | |
if a == b && b == c | |
:equilateral | |
elsif a != b && b != c && a != c | |
:scalene | |
else | |
:isosceles | |
end | |
end | |
def possible_triangle?(a, b, c) | |
side_1, side_2, hypotenuse = [a, b, c].sort | |
(side_1 + side_2) > hypotenuse | |
end | |
class TriangleError < Exception; end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment