29 lines
657 B
Haskell
29 lines
657 B
Haskell
module Reducers (
|
|
leastMostOcc,
|
|
leastMost,
|
|
most,
|
|
least
|
|
) where
|
|
|
|
import Data.List (group, sortBy, sort)
|
|
import Data.Ord (comparing)
|
|
|
|
groupOccurrences :: (Ord a) => [a] -> [[a]]
|
|
groupOccurrences = sortBy (comparing length) . group . sort
|
|
|
|
leastMostOcc :: (Ord a) => [a] -> (Int, Int)
|
|
leastMostOcc list = ((length . last) occ, (length . head) occ)
|
|
where
|
|
occ = groupOccurrences list
|
|
|
|
leastMost :: (Ord a) => [a] -> (a, a)
|
|
leastMost list = ((head . last) occ, (head . head) occ)
|
|
where
|
|
occ = groupOccurrences list
|
|
|
|
least :: (Ord a) => [a] -> a
|
|
least = fst . leastMost
|
|
|
|
most :: (Ord a) => [a] -> a
|
|
most = snd . leastMost
|