module Problem206 where

import Data.Maybe

main :: IO ()
main = print $ head $ mapMaybe (isPerfectSquare . numeral) cands
  where
    isPerfectSquare n =
        let root = round (sqrt . fromIntegral $ n :: Double)
        in if root * root == n then Just (10 * root) else Nothing
    numeral = go 0
    go res []       = res
    go res (x : xs) = go (10 * res + x) xs
    cands = mapM
        (\x -> if x == -1 then [0 .. 9] else [x])
        [1, -1, 2, -1, 3, -1, 4, -1, 5, -1, 6, -1, 7, -1, 8, -1, 9]
  -- start = sqrt 1020304050607080900 :: Int
  -- end   = sqrt 1929394959697989900 :: Int
