Skip to content

Instantly share code, notes, and snippets.

@tom-galvin
Created May 2, 2015 22:27
Show Gist options
  • Save tom-galvin/e36a0eb6426d23bbf6e3 to your computer and use it in GitHub Desktop.
Save tom-galvin/e36a0eb6426d23bbf6e3 to your computer and use it in GitHub Desktop.
DailyProgrammer Challenge Solution (Sad Cycles)
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