Created
August 18, 2019 11:51
-
-
Save cacharle/fc17d709a9cd54d222e6aee38fb3da5f to your computer and use it in GitHub Desktop.
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
-- check the multiplicative persistence of a given number | |
-- https://www.youtube.com/watch?v=Wim9WJeDTHQ&list=PLt5AfwLFPxWKuRpivZd_ivR2EvEzKrDUu&index=2 | |
-- https://oeis.org/A003001 | |
import System.Environment(getArgs) | |
import Data.List(intercalate) | |
main = do | |
args <- getArgs | |
let n = read (head args) :: Integer | |
nMult = selfMult n | |
putStrLn (intercalate "\n" (map show nMult)) | |
putStrLn (show n ++ " has a multiplicative persistence of " ++ (show $ length nMult - 1)) | |
selfMult :: (Integral a) => a -> [a] | |
selfMult n | |
| length ndigits < 2 = [n] | |
| otherwise = n : (selfMult $ product ndigits) | |
where ndigits = digits n | |
digits 0 = [] | |
digits x = digits (x `div` 10) ++ [x `mod` 10] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment