module Problem38 where

import Data.List

lim :: Int
lim = 100000 - 1

main :: IO ()
main = print . maximum . map concatenedProduct $ [1 .. lim]

concatenedProduct :: Int -> Int
concatenedProduct n
    | repeated n = 0
    | otherwise  = go n 2
  where
    repeated' x = (length x /= (length . nub $ x)) || ('0' `elem` x)
    repeated = repeated' . show
    go x k = if repeated' next || length next > 9 then x else go (read next) (k + 1)
        where next = show x ++ show (k * x)
