DEV Community

Discussion on: Daily Challenge #84 - Third Angle of a Triangle

Collapse
 
aminnairi profile image
Amin

Elm

import List exposing (all, sum)
import Maybe exposing (andThen, map)


isAngle : Int -> Bool
isAngle angle =
    angle > 0 && angle < 180


maybeAngles : List Int -> Maybe (List Int)
maybeAngles angles =
    if all isAngle angles && sum angles < 180 then
        Just angles

    else
        Nothing


third : Int -> Int -> Maybe Int
third first second =
    maybeAngles [ first, second ]
        |> map (sum >> (-) 180)

Test it online

Here.