Created
May 2, 2015 22:27
-
-
Save tom-galvin/e36a0eb6426d23bbf6e3 to your computer and use it in GitHub Desktop.
DailyProgrammer Challenge Solution (Sad Cycles)
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
import Control.Applicative | |
import Data.Char | |
import Data.List | |
iterateU f (x:xs) | x `elem` xs = x : (reverse $ takeWhile (/= x) xs) | |
| otherwise = iterateU f $ f x : x : xs | |
main = do power <- read <$> getLine | |
num <- getLine | |
putStrLn $ intercalate ", " $ | |
(iterateU (show . foldl1 (+) . | |
map ((^ power) . digitToInt)) . (:[])) num |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment