Created
December 28, 2012 04:28
-
-
Save kmandreza/4394496 to your computer and use it in GitHub Desktop.
Write a method valid_triangle? which takes as its input three non-negative numbers. It should return true if the three numbers could form the side lengths of a triangle and false otherwise. The arguments don't correspond to specific sides. Don't worry about handling negative inputs — garbage in, garbage out. For example, valid_triangle?(0,0,0) #…
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 valid_triangle?(a,b,c) | |
ab = a == b | |
bc = b == c | |
ac = a == c | |
if a >= b + c || b >= a + c || c >= a + b || a == 0 || b == 0 || c == 0 | |
return false | |
elsif ab && bc && ac | |
return true | |
elsif ab || bc || ac | |
return true | |
else | |
return true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment