DEV Community

Discussion on: Daily Challenge #214 - Persistent Bugger

Collapse
 
cipharius profile image
Valts Liepiņš • Edited

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
Collapse
 
destynova profile image
Oisín

Nice use of pointfree style!