Haskell solution:
import Numeric (floatToDigits) persistence :: Int -> Int persistence = recurse 0 where recurse d x | x > 9 = recurse (d+1) . foldr (*) 1 . digits $ x | otherwise = d digits = fst . floatToDigits 10 . fromIntegral
Edit: Inspired by other solutions I realized that I don't need to track recursion depth
import Numeric (floatToDigits) persistence :: Int -> Int persistence x | x > 9 = 1 + (persistence . foldr (*) 1 . digits $ x) | otherwise = 0 where digits = fst . floatToDigits 10 . fromIntegral
Nice use of pointfree style!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Haskell solution:
Edit:
Inspired by other solutions I realized that I don't need to track recursion depth
Nice use of pointfree style!