mirror of
https://github.com/correl/elm.git
synced 2024-12-24 11:50:50 +00:00
4999d42ab5
Use a type to express triangles instead of strings
32 lines
589 B
Text
32 lines
589 B
Text
module Triangle exposing (..)
|
|
|
|
import Set
|
|
|
|
|
|
type Triangle
|
|
= Equilateral
|
|
| Isosceles
|
|
| Scalene
|
|
|
|
|
|
version : Int
|
|
version =
|
|
2
|
|
|
|
|
|
triangleKind : number -> number -> number -> Result String Triangle
|
|
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
|