We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

# Rotate String

# Rotate String

andraantariksa + 0 comments Haskell using cycle :)

solve :: String -> String solve xs = unwords [take len $ drop i $ cycle xs | i <- [1..len]] where len = length xs main = do _ <- getLine c <- lines <$> getContents mapM (putStrLn . solve) c

wizard2none + 0 comments Clojure

(defn rotations [s] (join " " (for [i (range 1 (inc (count s))) :let [k (mod i (count s))]] (str (subs s k) (subs s 0 k))))) (dotimes [_ (Integer. (read-line))] (let [s (trim (read-line))] (println (rotations s))))

nalleyer + 0 comments this is my straightforward haskell solution

main = do ls <- lines <$> (getLine >> getContents) mapM_ output (map rotate ls) where rotate str = r $ take (length str) $ iterate r str r [] = [] r (x:xs) = xs ++ [x] output strs = putStrLn $ unwords strs

backofhan + 0 comments Yet another concise Haskell solution

-- Enter your code here. Read input from STDIN. Print output to STDOUT import Data.List -- both are working --solve s = [let (s1, s2) = splitAt n s in s2 ++ s1 | n <- [1..length s]] solve s = tail $ zipWith (++) (tails s) (inits s) main = getContents >>= mapM_ (putStrLn . unwords . solve) . tail . lines

penman + 0 comments Here's my haskell solution

rotate n s = take (length s) $ drop n $ cycle s allRotations s = flip rotate s <$> [1..length s] main = interact $ unlines . map (unwords . allRotations) . tail . lines

Load more conversations

Sort 14 Discussions, By:

Please Login in order to post a comment