[Haskell-beginners] Project Euler #01 on HackerRank, Performance issue‏

Brandon Allbery allbery.b at gmail.com
Wed Jan 28 01:37:58 UTC 2015


On Tue, Jan 27, 2015 at 8:33 PM, Jean Lopes <hawu.bnu at gmail.com> wrote:

> Just to illustrate what I am saying: for instance this function
> > sum [3,6..9999999]
> Takes ~1 second to return, and these are just the multiples of 3, to get
> the real answer I would have to first sum the multiples of 5 and 15...
>

Yes, and what people are telling you is how to do this without generating
and iterating through the list, just using the description of it. This is
the key to Euler problems; you're using the brute force solution, not the
math that lets you skip the slow part and get the answer immediately.

(I've been keeping quiet because I'm not very good at this kind of math
myself; I just recognize that Euler problems are always looking for it and
that almost any time you find yourself iterating through a generated list
of numbers, you're doing it wrong. Even in the cases where you *do* need to
do so, there's usually some math that will cut the search space down
considerably; you'll run into this if you do one of the Euler problems
involving prime numbers, most likely.)

-- 
brandon s allbery kf8nh                               sine nomine associates
allbery.b at gmail.com                                  ballbery at sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20150127/baee0cf7/attachment.html>


More information about the Beginners mailing list