Skip to content

Instantly share code, notes, and snippets.

@parksilk
Last active December 10, 2015 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parksilk/4382844 to your computer and use it in GitHub Desktop.
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.
def valid_triangle?(a, b, c)
if a+b>c and a+c>b and b+c>a
true
else
false
end
end
@parksilk
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment