Permalink
Browse files

euler 30

  • Loading branch information...
1 parent 4006b9f commit d9e0f64a2e80b136ef6abdd226d75889289df7e7 Andrew Korzhuev committed Apr 20, 2012
Showing with 13 additions and 0 deletions.
  1. +13 −0 euler/30.hs
View
13 euler/30.hs
@@ -0,0 +1,13 @@
+-- Find the sum of all the numbers that can be written
+-- as the sum of fifth powers of their digits.
+
+--import Data.Char (digitToInt)
+
+pwrSum :: Int -> Int
+pwrSum 0 = 0
+pwrSum n = (n `mod` 10)^5 + pwrSum (n `div` 10)
+
+answer = sum $ filter good [10..(9^5)*7]
+ where good x = pwrSum x == x
+
+main = print answer

0 comments on commit d9e0f64

Please sign in to comment.