-- http://www.codewars.com/kata/5464cbfb1e0c08e9b3000b3e
module IsHappy where

import Control.Arrow

isHappy :: Integer -> Bool
isHappy x = findCycle x == 1 where
  findCycle = fst . head . dropWhile (\(a,b) -> a/=b)
    . iterate (step . step *** step) . (step . step &&& step)
  step = sum . map ((^2) . (`mod`10)) . takeWhile (>0) . iterate (`div`10)

