danilobellini

Less lines of code: Haskell

Jun 20th, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Data.List (group, sort)
  2. import Text.Printf (printf,)
  3.  
  4. get_ext = reverse . takeWhile (/='.') . reverse
  5. get_groups = group . sort . map get_ext . lines
  6. get_all_pairs txt = [ (length g, head g) | g <- get_groups txt ]
  7.  
  8. printer = mapM_ $ uncurry $ printf "%3d %s\n"
  9. main = readFile "massa.txt" >>= printer . reverse . sort . get_all_pairs
  10.  
  11. -- Based on https://www.facebook.com/pythonbrasil/photos/a.582882565067606.1073741825.328258703863328/776054062417121/
Advertisement
Add Comment
Please, Sign In to add comment