import Data.Tuple (swap) import Data.List (unfoldr) digSum :: Int -> Int -> Int digSum base = sum . unfoldr f where f 0 = Nothing f n = Just (swap (quotRem n base)) digRoot :: Int -> Int -> (Int, Int) digRoot base = head . dropWhile ((>= base) . snd) . zip [0 ..] . iterate (digSum base) main :: IO () main = do putStrLn "in base 10:" mapM_ (print . ((,) <*> digRoot 10)) [627615, 39390, 588225, 393900588225]