[ create a new paste ] login | about

Link: http://codepad.org/YO0PAxrQ    [ raw code | output | fork ]

Haskell, pasted on Jun 30:
module Main where                                                                    
import Data.List                                                                     
                                                                                     
isCurious :: Integer -> Bool                                                         
isCurious n = n == (mod (n * n) p) where                                             
    powersOfTen = map (\x -> 10^x) [1..]                                             
    p = head $ dropWhile (< n) powersOfTen                                           
                                                                                     
curiousUpToNDigits :: Integer -> [Integer]                                           
curiousUpToNDigits n                                                                 
    | n == 1        = [1,5,6]                                                        
    | n > 1         = let l = (curiousUpToNDigits (n-1)) in                          
        nub $ filter isCurious [x*(10^(n-1)) + y | x <- [0..9], y <- l]              
    | otherwise     = []                                                             
                                                                                     
sumOfCurious :: Integer -> Integer                                                   
sumOfCurious n = sum $ curiousUpToNDigits n                                          
                                                                                     
main :: IO ()                                                                        
main = do                                                                            
    let sum = sumOfCurious 20                                                        
    print "The sum is:"                                                              
    print sum 


Output:
1
2
"The sum is:"
103367370865749773002


Create a new paste based on this one


Comments: