Skip to content

Instantly share code, notes, and snippets.

@willnet
Created August 20, 2012 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willnet/3403825 to your computer and use it in GitHub Desktop.
Save willnet/3403825 to your computer and use it in GitHub Desktop.
-- http://www.rubyquiz.com/quiz93.html
import Data.Char
checkHappy :: Int -> Bool
checkHappy n = checkHappy' [n]
checkHappy' :: [Int] -> Bool
checkHappy' list
| firstInput == 1 = True
| firstInput == nextValue = False
| otherwise = checkHappy' (nextValue:list)
where firstInput = last list
nextValue = next $ head list
next :: Int -> Int
next = foldl1 (+) . map ((^2) . digitToInt) . show
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment