Created
November 1, 2009 22:41
-
-
Save jlouis/223770 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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