remove Repeat values from a list in haskell -



remove Repeat values from a list in haskell -

i need accomplish few tasks in haskell:

find maximum of list, along number of times occurs:

maxcount [2,4,7,2,3] --> [7,1]

remove repeated values list

delrep [1,3,2,1,4] --> [3,2,4]

delete instances of element list:

delete [1,3,4,1] 1 --> [3,4]

question 1.

maxandreps l = allow m = maximum l reps = length $ filter (== m) l in [m,reps]

this solution has bad asymptotic performance because list traversed twice. ideally, solution find maximum , count repetitions in 1 pass. if write maximum, filter, , length in terms of fold, should see how combine them single pass.

also, more natural homecoming tuple instead of list.

question 2. @ using data.set.set. also, output list need in same order? if not, there's particularly easy solution.

question 3. above reply question 1 covers this. function removes non-maximum values list, problem. figure out how 1 works, , you'll have solved well.

haskell

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -