I'm trying to solve this problem:
http://projecteuler.net/index.php?section=problemsid=44, and my
program runs out of memory. I was wondering where I have a space leak,
I thought that this program doesn't accumulate any data structures
(i.e. should use constant memory):
CODE BEGINS
-- returns
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
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