user622194
user622194

Reputation:

Find the lowest value of all the high values

I am trying to write haskell function that takes list of lists and find the lowest value of all the high values.

So the function takes the list [[1,1,3],[2,5],[1]] and return 1 because its the lowest of 3,5,1.

What haskell function can I use?

Upvotes: 1

Views: 1138

Answers (3)

Landei
Landei

Reputation: 54584

Think "step by step": First you need find all maximums of the individual lists, e.g.:

map maximum [[1,1,3],[2,5],[1]]
--[3,5,1]

Then you need the minimum of this list. So one solution would be:

minOfMax xs = minimum (map maximum xs)

Of course you can also write your own recursive solution, or use a fold:

minOfMax (x:xs) = foldl f (maximum x) xs where 
    f a bs = min a (maximum bs)

Upvotes: 2

Nomics
Nomics

Reputation: 716

Using list comprehension :

maxi xxs = minimum [ maximum a | a <- xxs] 

(I'm a beginner in Haskell ... and coding. It's the first time that I figure it out an answer arround here. So, Gratzz to me!! :P )

Upvotes: 4

Daniel Fischer
Daniel Fischer

Reputation: 183978

Data.List contains useful functions,

:browse Data.List

in ghci.

(Looks a lot like homework, so...)

Upvotes: 4

Related Questions