Skip to content

Instantly share code, notes, and snippets.

@ulysses4ever
Created August 29, 2015 08:48
Show Gist options
  • Save ulysses4ever/df6127493b141b0a1b77 to your computer and use it in GitHub Desktop.
Save ulysses4ever/df6127493b141b0a1b77 to your computer and use it in GitHub Desktop.
LinqBegin60 (from PT4) on Haskell
import Data.List
import Data.Ord (comparing)
import Data.Char (ord)
import Control.Applicative ((<$>))
equating f = \a b -> f a == f b
thenBy ord' = concat
. map (sortBy ord')
. groupBy (equating length)
myPrint s = (show $ length s) ++ "-" ++ [head s]
main = map myPrint
. thenBy (comparing (ord . head))
. sortBy (flip $ comparing length)
. map concat
. groupBy (equating head)
. sort
. lines
<$> test -- getContents -- for stdin
test :: IO String
test = return $
intercalate "\n"
["GRPWB", "LNKF", "CBF", "D",
"IABW", "IAJDY", "H", "PBGNI",
"F", "G", "CRXC", "OYVFW"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment