Created
March 31, 2010 20:05
-
-
Save valyagolev/350802 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 List ( elemIndex ) | |
import Char ( digitToInt ) | |
check ones nines [] = length nines | |
check ones nines (x:xs) = if (ending x) == 1 then check (x:ones) nines xs else 1 + check ones (x:nines) xs | |
where | |
ending 1 = 1 | |
ending 89 = 89 | |
ending x = case elemIndex x ones of | |
Just _ -> 1 | |
Nothing -> case elemIndex x nines of | |
Just _ -> 89 | |
Nothing -> ending' x | |
ending' x = ending $ (sum $ map (^2) $ map digitToInt $ show x) | |
checkCount xs = check [] [] xs | |
main = print $ checkCount [1..10000000] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment