2016-05-13 02:26:52 +00:00
|
|
|
module Triangle exposing (..)
|
2016-03-14 00:09:05 +00:00
|
|
|
|
|
|
|
import Set
|
|
|
|
|
|
|
|
|
2016-08-16 00:16:34 +00:00
|
|
|
type Triangle
|
|
|
|
= Equilateral
|
|
|
|
| Isosceles
|
|
|
|
| Scalene
|
|
|
|
|
|
|
|
|
|
|
|
version : Int
|
|
|
|
version =
|
|
|
|
2
|
|
|
|
|
|
|
|
|
2016-12-17 22:15:34 +00:00
|
|
|
triangleKind : comparable -> comparable -> comparable -> Result String Triangle
|
2016-03-14 00:09:05 +00:00
|
|
|
triangleKind x y z =
|
2016-06-19 21:46:13 +00:00
|
|
|
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 ->
|
2016-08-16 00:16:34 +00:00
|
|
|
Ok Equilateral
|
2016-03-14 00:09:05 +00:00
|
|
|
|
2016-06-19 21:46:13 +00:00
|
|
|
2 ->
|
2016-08-16 00:16:34 +00:00
|
|
|
Ok Isosceles
|
2016-03-14 00:09:05 +00:00
|
|
|
|
2016-06-19 21:46:13 +00:00
|
|
|
_ ->
|
2016-08-16 00:16:34 +00:00
|
|
|
Ok Scalene
|