Skip to content

Commit

Permalink
triangle project: using a hash to avoid ifs. finished implementing tr…
Browse files Browse the repository at this point in the history
…iangle exceptions
  • Loading branch information
dlbock committed Sep 27, 2011
1 parent e5bb3d8 commit d6a572e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .path_progress
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0,1,2,3,4,5,6,6,6,6,7,7,7,7,8,8,9,9,9,11,12,13,14,14,14,14,16,17,18,18,19,19,19,19,20,20,20,20,21,21,22,22,23,23,24,12,24,25,26,26,28,28,29,30,32,32,34,33,35,36,36,36,36,37,38,39,39,40,42,43,43,44,45,45,45,46,47,48,49,51,52,53,54,55,56,56,57,57,57,57,58,59,59,60,60,60,61,61,61,62,62,63,64,65,66,67,68,69,70,71,71,71,71,71,71,71,71,71,71,72,72,72,72,73,74,75,75,76,77,78,79,79,80,81,81,83,84,85,85,85,86,86,87,88,88,89,90,91,91,91,92,92,93,94,95,95,96,96,97,97,99,101,102,102,103,103,104,104,105,106,107,110,110,110,110,110,111,111,112,113,115,116,117,118,119,121,121,121,123,124,126,127,128,130,131,132,133,134,134,135,135,136,136,137,138,139,140,140,144,144,145,144,144,144,147,147,147,147,147,147,148,148,148,149,150,151,152,152
0,1,2,3,4,5,6,6,6,6,7,7,7,7,8,8,9,9,9,11,12,13,14,14,14,14,16,17,18,18,19,19,19,19,20,20,20,20,21,21,22,22,23,23,24,12,24,25,26,26,28,28,29,30,32,32,34,33,35,36,36,36,36,37,38,39,39,40,42,43,43,44,45,45,45,46,47,48,49,51,52,53,54,55,56,56,57,57,57,57,58,59,59,60,60,60,61,61,61,62,62,63,64,65,66,67,68,69,70,71,71,71,71,71,71,71,71,71,71,72,72,72,72,73,74,75,75,76,77,78,79,79,80,81,81,83,84,85,85,85,86,86,87,88,88,89,90,91,91,91,92,92,93,94,95,95,96,96,97,97,99,101,102,102,103,103,104,104,105,106,107,110,110,110,110,110,111,111,112,113,115,116,117,118,119,121,121,121,123,124,126,127,128,130,131,132,133,134,134,135,135,136,136,137,138,139,140,140,144,144,145,144,144,144,147,147,147,147,147,147,148,148,148,149,150,151,152,152,152,152,152,144,152,154
10 changes: 7 additions & 3 deletions triangle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@

def triangle(a, b, c)
sides = Set.new [a, b, c]
return :equilateral if sides.length == 1
return :isosceles if sides.length == 2
return :scalene if sides.length == 3

raise TriangleError if sides.any? { |s| s == 0 or s < 0 }
fake_triangle = [[a + b, c], [a + c, b], [b + c, a]].any? { |x| x.first <= x.last }
raise TriangleError if fake_triangle

triangles = {1 => :equilateral, 2 => :isosceles, 3 => :scalene }
return triangles[sides.length]
end

# Error class used in part 2. No need to change this code.
Expand Down

0 comments on commit d6a572e

Please sign in to comment.