Skip to content

Instantly share code, notes, and snippets.

@nbogie
Created September 7, 2011 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbogie/1201738 to your computer and use it in GitHub Desktop.
Save nbogie/1201738 to your computer and use it in GitHub Desktop.
poor soln h99 problems p28
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