Skip to content

Instantly share code, notes, and snippets.

@jlouis
Created November 1, 2009 22:41
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 jlouis/223770 to your computer and use it in GitHub Desktop.
Save jlouis/223770 to your computer and use it in GitHub Desktop.
import Data.List
numbers = [3..10^6] -- arbitrary guess
convRadix :: (Integral b) => b -> b -> [b]
convRadix n =
unfoldr (\b -> if b == 0 then Nothing else Just (b `mod` n, b `div` n))
fact n = facti n 1
where facti 0 a = a
facti n a = facti (n-1) a*n
check ns = filter predicate ns
where sumfact n = sum $ map fact (convRadix 10 n)
predicate n = n == sumfact n
main =
do putStrLn $ show $ sum (check numbers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment