Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
39 lines (35 sloc) 879 Bytes
# Triangle Project Code.
# Triangle analyzes the lengths of the sides of a triangle
# (represented by a, b and c) and returns the type of triangle.
#
# It returns:
# :equilateral if all sides are equal
# :isosceles if exactly 2 sides are equal
# :scalene if no sides are equal
#
# The tests for this method can be found in
# about_triangle_project.rb
# and
# about_triangle_project_2.rb
#
def triangle(a, b, c)
# WRITE THIS CODE
#raise TriangleError if a <= 0 or b <= 0 or c <= 0
raise TriangleError unless valid?(a,b,c)
if a == b and b == c
return :equilateral
elsif a == b or a == c or b == c
return :isosceles
else
return :scalene
end
end
def valid?(*a)
a.sort!
max = a.pop
return false if a.pop + a.pop <= max
true
end
# Error class used in part 2. No need to change this code.
class TriangleError < StandardError
end