Created
August 9, 2014 22:47
-
-
Save jedp/b2a6d3e39eae27303017 to your computer and use it in GitHub Desktop.
Heroku koans: syntax error in triangle project 2?
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
# http://koans.heroku.com/en/about_triangle_project_2 | |
# | |
# XXX why does the second TriangleError.new cause a syntax error | |
# in the heroku web app, but not in my irb repl!? | |
class TriangleError < Exception | |
end | |
def triangle(a, b, c) | |
sides = [a, b, c] | |
# illegal side(s)? | |
if sides.min <= 0 | |
raise TriangleError.new("a leg or two is of 0 or negative length") | |
else | |
_a, _b, h = sides.sort.map { |x| x*x } | |
lw = _a + _b | |
if lw < h || lw > h | |
raise TriangleError.new("one or more legs is the wrong length") | |
end | |
end | |
# OK, compute shape | |
[:equilateral, :isosceles, :scalene].fetch(sides.uniq.size - 1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment