re: Daily Challenge #84 - Third Angle of a Triangle VIEW POST

FULL DISCUSSION
 

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.

code of conduct - report abuse