在haskell中旋转一个字符串,但有一些例外

时间:2017-05-02 18:16:53

标签: haskell

我想在haskell中旋转一个字符串,所以如果我给#34;现在我想尖叫"旋转[[想要现在尖叫我],[现在我想要尖叫]],如果字符串以&#34开头;我"或"到"然后必须消除它。直到现在我仍然有轮换问题。

reverseWords :: String -> String
reverseWords = unwords . reverse . words

shiftt :: [a] -> Int -> [a]
shiftt l n = drop n l  ++ take n l

rot::String->[String]
rot l = [ reverseWords l i | i <- [0 .. (length l) -1]]

1 个答案:

答案 0 :(得分:0)

创建所有旋转的列表,然后根据您的谓词过滤掉。例如,

rotations x = take (length x) $ iterate rot1 x
        where rot1 = drop 1 x ++ take 1 x


filteredRots = map unwords . filter (\x -> length (head x) > 2) . rotations . words

并用作

> filteredRots "Now I want to scream"

["Now I want to scream","want to scream Now I","scream Now I want to"]

前奏&GT;