Last active
December 11, 2015 06:19
-
-
Save mfpiccolo/4558663 to your computer and use it in GitHub Desktop.
This program will take three numbers and tell you if it can be represented as a triangle and if so what kind of triangle.
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 triangle(number1, number2, number3) | |
if number1 > number2 + number3 || number2 > number1 + number3 || number3 > number1 + number2 | |
"This is not a triangle" | |
else | |
if number1 == number2 && number2 == number3 | |
"You have got yourself an equalateral triangle. You should try and be more creative." | |
elsif number1 == number2 || number1 == number3 || number2 == number3 | |
'This is an isosceles triangle. So you got that there going for you.' | |
elsif number1 != number2 && number2 != number3 && number3 != number1 | |
'Oh snap! That is a scalene' | |
end | |
end | |
end | |
puts "'#{triangle(2, 2, 10)}' should be 'That is not a triangle'" | |
puts "'#{triangle(10, 10, 10)}' should be 'You have got yourself an equalateral triangle. You should try and be more creative.'" | |
puts "'#{triangle(2, 10, 10)}' should be 'This is an isosceles triangle. So you got that there going for you.'" | |
puts "'#{triangle(12, 7, 10)}' should be 'Oh snap! That is a scalene'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment