Skip to content

Instantly share code, notes, and snippets.

@kmandreza
Created December 28, 2012 04:28
Show Gist options
  • Save kmandreza/4394496 to your computer and use it in GitHub Desktop.
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) #…
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