Archaic wrote:

> The problem to solve is 3 inputs from the user. The output has to be
> nothing more than equilateral, isosceles, scalene, or not a triangle. My
> algorithm feels a bit clunky and I would like to streamline it if
> possible. The input will be sanitized to allow only int and float (both
> positive and negative) to get this far, so my only concern is just with
> this algorithm.
> 
> Any suggestions?
> 
> <pseudo-code>
> 
> if a + b + c = 360
>   if a = b
>     if b = c
>       equilateral
>     else
>       isosceles
>   else
>     if a = c || b = c
>       isosceles
>     else
>       scalene
> else
>   not a triangle
> 
> </pseudo-code>
> 

How about:

return ( a+b+c == 180 ) * (a>0) * (b>0) * (c>0) * 
       ( 1 + (a==b) + (a==c) + (b==c) );

0 : not a triangle
1 : scalene
2 : isosceles
4 : equilateral

:)
-- 
http://linuxfromscratch.org/mailman/listinfo/lfs-chat
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page

Reply via email to