Skip to content

Instantly share code, notes, and snippets.

@jedp
Created August 9, 2014 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jedp/b2a6d3e39eae27303017 to your computer and use it in GitHub Desktop.
Save jedp/b2a6d3e39eae27303017 to your computer and use it in GitHub Desktop.
Heroku koans: syntax error in triangle project 2?
# 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