DEV Community

Discussion on: Daily Challenge #117 - MinMinMax

Collapse
 
craigmc08 profile image
Craig McIlwrath

Haskell solution:

import Data.List ((\\))

minminmax :: (Ord a, Enum a) => [a] -> (a, a, a)
minminmax xs = let min = minimum xs
                   max = maximum xs
                   range = [min..max] \\ xs
               in  (min, head range, max)

The \\ operator is the list difference, and the .. can be used on any enum type to build a list. This means this works for a large number of types, like:

minminmax "sonicthehedgehog" = ('c', 'f', 't')