I'm using Project Euler to learn Haskell. In particular, I'm writing a
program for Problem 18:
http://projecteuler.net/index.php?section=problemsid=18. As a solution, I'm
constructing a list, containing maximum sums of values on a path from top of
the triangle to a given item. In this list, item
On Sunday 23 May 2010 01:10:54, Vladimir Ch. wrote:
I'm using Project Euler to learn Haskell. In particular, I'm writing a
program for Problem 18:
snip
The program works, but consumes obscene amount of memory.
Not if it's compiled. Even interpreted I wouldn't call it obscene, though
it is
Not really. Your problem is that you calculate maxPaths vals over and over
again in
where mpath i val = val + maximum [(maxPaths vals) !! pi| pi - prev i]
; the value isn't shared (it is, if compiled with optimisations).
If you share the list by giving it a name, your programme becomes much