Problem 34
The solution for this problem is somewhat similar to the 30th problem, as it involves the construction of a list based on the problem rules:
import Char
f = sum [x | x <- [3..50000], x == g x]
where g = sum .
map (factorial . digitToInt) .
show
factorial n = foldl (*) 1 [1..n]
main = print f
Again, the execution was quite fast:
real 0m0.059s user 0m0.056s sys 0m0.003s
However, I started with going until 10^6, since I din’t know how many numbers would satisfy the condition. In fact, there are only two, so I could therefore reduce the search domain considerably.
blog comments powered by Disqus