A quite different way to solve it, popped into my twisted little mind:
[:equilateral, :isosceles, :scalene][[a,b,c].uniq.length - 1]
As I wrote to him, "Do NOT put something that "clever" in anything actually important, as the lack of clarity isn't worth the conciseness. But it makes a neat
little mind-exercise. ;-)"
Alternately, to split it up for a bit better readability:
types = [:equilateral, :isosceles, :scalene]
number_of_lengths = [a, b, c].uniq.length - 1
types[number_of_lengths]
Just thought y'all might find it amusing....
What about a = b = 3, c = 17?
ReplyDeleteComes back :isosceles, as is correct. Transcript from irb:
ReplyDelete1.9.3p194 :001 > a = b = 3
=> 3
1.9.3p194 :002 > c = 17
=> 17
1.9.3p194 :003 > [:equilateral, :isosceles, :scalene][[a,b,c].uniq.length - 1]
=> :isosceles
And furthermore:
1.9.3p194 :004 > c = 3
=> 3
1.9.3p194 :005 > [:equilateral, :isosceles, :scalene][[a,b,c].uniq.length - 1]
=> :equilateral
And lastly:
1.9.3p194 :006 > a = 1
=> 1
1.9.3p194 :007 > b = 2
=> 2
1.9.3p194 :008 > [:equilateral, :isosceles, :scalene][[a,b,c].uniq.length - 1]
=> :scalene