Created
September 7, 2011 21:09
-
-
Save nbogie/1201738 to your computer and use it in GitHub Desktop.
poor soln h99 problems p28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List (elemIndex, sortBy, group, sort) | |
import Data.Ord (comparing) | |
import Data.Maybe (fromJust) | |
main = print demo | |
demo = lsort ["", "ab3","r3","fg3","d3","ijk1","mn","1", "abcdef1"] | |
lsort :: (Ord a) => [[a]] -> [[a]] | |
lsort xs = sortBy (comparing lfreq) xs | |
where | |
lfreq ls = fromJust $ (length ls) `elemIndex` allLengths | |
allLengths = map head $ sortBy (comparing length) $ group $ sort $ map length xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment