I\'m going through the ruby koans, I\'m on 151 and I just hit a brick wall.
Here is the koan:
# You need to write the triangle method in the file \'trian
There are some absolutely brilliant people on StackOverflow...I'm reminded of that every time I visit :D Just to contribute to the conversation, here's the solution I came up with:
def triangle(a, b, c)
raise TriangleError if [a,b,c].min <= 0
x,y,z = [a,b,c].sort
raise TriangleError if x + y <= z
equal_sides = 0
equal_sides +=1 if a == b
equal_sides +=1 if a == c
equal_sides +=1 if b == c
# Note that equal_sides will never be 2. If it hits 2
# of the conditions, it will have to hit all 3 by the law
# of associativity
return [:scalene, :isosceles, nil, :equilateral][equal_sides]
end