elm/exercises/triangle/Triangle.example

22 lines
497 B
Text
Raw Normal View History

module Triangle exposing (..)
2016-03-14 00:09:05 +00:00
import Set
triangleKind : number -> number -> number -> Result String String
triangleKind x y z =
if x <= 0 || y <= 0 || z <= 0 then
Err "Invalid lengths"
else if x + y <= z || x + z <= y || y + z <= x then
Err "Violates inequality"
else
case Set.size (Set.fromList [ x, y, z ]) of
1 ->
Ok "equilateral"
2016-03-14 00:09:05 +00:00
2 ->
Ok "isosceles"
2016-03-14 00:09:05 +00:00
_ ->
Ok "scalene"