Problem 40
The 40th problem of the project_euler can be solved by taking advantage of the Haskell laziness. As one can see below, I defined an infinite list inf_lst, which contains all positive integers in a string format. As I said, since Haskell is lazy, it will only compute the list if it needs its values. Therefore, it was only a matter of accessing the 6 required positions in the list and calculate its multiplication:
import Char
f = foldr ((*) . digitToInt) 1 l
where l = map ((!!) inf_lst) [10^i |
i <- [1..6]]
inf_lst = concat [show i | i <- [0..] ]
The execution time is: (0.32 secs, 69247988 bytes)
blog comments powered by Disqus