Created
August 19, 2012 07:15
-
-
Save fgalassi/3393132 to your computer and use it in GitHub Desktop.
Ruby Koan triangle_2 project
This file contains hidden or 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(*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