Guest User

Untitled

a guest
Oct 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. {-# LANGUAGE OverloadedStrings #-}
  2. import Control.Arrow ((***), first, second)
  3. import Control.Monad (ap, forever, guard, join, liftM2)
  4. import Control.Monad.Fix (fix)
  5. import Data.HashSet (fromList, member)
  6. import Data.List (nub, sortBy)
  7. import Data.Maybe (fromJust)
  8. import Data.Ord (comparing)
  9. import Data.Text (lines, pack, unpack, unwords)
  10. import Data.Text.IO (readFile, putStrLn)
  11. import Prelude hiding (lines, readFile, putStrLn, unwords)
  12.  
  13. if' x y z = if x then y else z
  14.  
  15. main = forever . ((putStrLn "Enter a 4x4 grid:" >> ((>>=) `ap` liftM2 (.) (>>=) (ap ((.) . (.) . (>>=)) ((. ((((return .) .) .) . (. ((. ((. return) . (:))) . (.) . (:))) . (.) . (.) . (:))) . (.) . (.) . (>>=)))) (fix ((getLine >>=) . (`ap` (return . take 4)) . flip (if' . (< 4) . length) . (putStrLn "too short, try again" >>)))) >>=) . flip flip getChar . (((>>) . putStrLn . unwords . sortBy (flip (comparing (sum . map (fromJust . flip lookup [('a',1), ('b',4), ('c',3), ('d',2), ('e',1), ('f',2), ('g',3), ('h',3), ('i',1), ('j',6), ('k',5), ('l',2), ('m',4), ('n',2), ('o',1), ('p',4), ('q',8), ('r',1), ('s',1), ('t',1), ('u',3), ('v',4), ('w',4), ('x',8), ('y',2), ('z',8)]) . unpack))) . nub) .) . (. flip ((. (join . drop 2 . flip take (iterate (concatMap (ap ((>>=) . (filter (ap ((&&) . ap ((&&) . (>= 0) . fst) ((<= 3) . fst)) (ap ((&&) . (>= 0) . snd) ((<= 3) . snd))) . flip map [first succ, join (***) succ, second succ, pred *** succ, first pred, join (***) pred, second pred, succ *** pred] . flip id) . last) (ap (ap . (((>>) . guard . not) .) . flip elem) (flip flip [] . ((:) .) . (. return) . (++))) . fix . const)) (([0..3] >>=) . flip flip [] . ((:) .) . flip flip [] . ((:) .) . (,) =<< [0..3])))) . map . (pack .) . map . (`ap` fst) . ((!!) .) . (. snd) . (!!)) 8) . filter . flip member =<< fmap (fromList . lines) (readFile "/usr/share/dict/words")
Add Comment
Please, Sign In to add comment