Skip to content

Instantly share code, notes, and snippets.

@larryv
Created March 11, 2012 05:38
Show Gist options
  • Save larryv/2015163 to your computer and use it in GitHub Desktop.
Save larryv/2015163 to your computer and use it in GitHub Desktop.
-- Project Euler, Problem 48
--
-- ==========
-- The series, 1^1 + 2^2 + 3^3 + ... + 10^10 = 10405071317.
--
-- Find the last ten digits of the series, 1^1 + 2^2 + 3^3 + ... + 1000^1000.
-- ==========
--
-- Lawrence Velazquez
-- 13 June 2011
-- To keep the sum a little more manageable, we'll filter out any number
-- x such that x is divisible by 10. This is because x^x ends in at least
-- 10 zeroes and therefore wouldn't effect the last ten digits of the sum.
main = print $ reverse . take 10 . reverse . show . sum $
[x ^ x | x <- [1 .. 1000], x `mod` 10 /= 0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment