DEV Community

Discussion on: Daily Challenge #183 - Automorphic Numbers

Collapse
 
cipharius profile image
Valts Liepiņš

Ruby

def autoMorphic num
    dig = num.digits
    (num**2).digits[...dig.length].eql? dig
end

and Haskell:

autoMorphic :: Int -> Bool
autoMorphic x = (chars ==) . take (length chars) . reverse . show $ x^2
    where chars = reverse $ show x