Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Main where
- import Data.List (group, sort)
- main :: IO ()
- main = getLine >>= mapM_ putStrLn . palindromes
- palindromes :: String -> [String]
- palindromes [] = [""]
- palindromes [x] = [[x]]
- palindromes xs | head xs == last xs = (++)
- <$> ((++)<$> [[head xs]] <*> (palindromes . tail . init) xs)
- <*> [[last xs]]
- | otherwise = candidates $ branches xs
- where
- branches xs = map head . group . sort . concatMap (palindromes . ($xs)) $ [tail, init, tail . init]
- maxlen = maximum . map length
- candidates xs = filter (\x -> length x == maxlen xs) xs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement