Last active
December 10, 2015 04:38
-
-
Save parksilk/4382844 to your computer and use it in GitHub Desktop.
Code for my answer to "Exercise: Triangle side lengths" in Dev Bootcamp's Socrates. See the revisions for my original code that was missing some elements and did not work.
This file contains 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) | |
if a+b>c and a+c>b and b+c>a | |
true | |
else | |
false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to help on facebook, I realized line 2 needed to be
if a+b>c and a+c>b and b+c>a
My code was only testing for a+b>c, when to test for a valid triangle the values for a, b, and c need to be interchangeable in that equation. So in my original code a triangle with sides a==50, b==100, c==1 would return 'true', when in fact no triangle exists with those side lengths.