Question
The series, .
Find the last ten digits of the series, .
Clojure
#!/usr/bin/env clojure
(defn raise [x n]
(. (. java.math.BigInteger (valueOf x)) (pow n)))
(defn raise-to-itself [number]
(raise number number))
(defn digits [n]
(map #(- (int %) 48) (str n)))
(def result (reduce + (map raise-to-itself (range 1 1001))))
(println (apply str (reverse (take 10 (reverse (digits result))))))
Haskell
lastN :: Int -> [a] -> [a]
lastN n xs = foldl (const . drop 1) xs (drop n xs)
main :: IO ()
main = putStrLn $ lastN 10 $ show $ sum [x^x | x <- [1..1000]]
$ ghc -O2 -o self-powers self-powers.hs
$ time ./self-powers
real 0m0.005s
user 0m0.000s
sys 0m0.005s