Skip to content

Instantly share code, notes, and snippets.

@fgalassi
Created August 19, 2012 07:15
Show Gist options
  • Select an option

  • Save fgalassi/3393132 to your computer and use it in GitHub Desktop.

Select an option

Save fgalassi/3393132 to your computer and use it in GitHub Desktop.
Ruby Koan triangle_2 project
def triangle(*sides)
raise TriangleError if [
sides.count != 3,
sides.any? {|side| side < 1},
sides.max >= sides.reduce(:+) - sides.max
].any?
case sides.uniq.count
when 1 then :equilateral
when 2 then :isosceles
else :scalene
end
end
class TriangleError < Exception; end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment