mirror of
https://github.com/correl/elm.git
synced 2024-11-16 19:19:28 +00:00
22 lines
434 B
Text
22 lines
434 B
Text
|
module Triangle (..) where
|
||
|
|
||
|
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"
|
||
|
|
||
|
2 ->
|
||
|
Ok "isosceles"
|
||
|
|
||
|
_ ->
|
||
|
Ok "scalene"
|