Last active
July 21, 2016 05:39
-
-
Save rhaseven7h/67bef96d84f2eeec81bc69dc92ff0130 to your computer and use it in GitHub Desktop.
HackerRank.com - Functional Programming - Haskell - Return all rotations of a string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Rotate Strings | |
import Data.List | |
rotate s r = drop r s ++ take r s | |
solve s = intercalate " " (tail rss ++ [ head rss ]) | |
where rss = [ rs | r <- [ 0 .. (length s - 1) ], let rs = rotate s r ] | |
main = do | |
getContents >>= mapM_ putStrLn . map solve . tail . lines |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 | |
abc | |
abcde | |
abab | |
aaa | |
z |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bca cab abc | |
bcdea cdeab deabc eabcd abcde | |
baba abab baba abab | |
aaa aaa aaa | |
z |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment