Link for clojail broken.

]]>The basic idea is that we can generate primes completely in advance because we know the stopping criteria, which we capture in a stop predicate passed to a primes generator. Once that machinery is in place, it’s easy to write a prime-factor method that walks the list of primes and tests to see if they’re a factor of a given number. We run that tail-recursively and accumulate the list of factors.

Clojure’s nice for this problem and problem 8 because it has really nice support for large numbers.

Cheers,

]]>(def routes

[[5]

[9 6]

[4 6 9]

[0 7 1 9]])

your solution gives wrong answer. (27 instead of 29)

Zippers + BFS doesn’t work in this case.

Clever solution to this problem is to go from bottom to top, eliminating all sums except maximum (see my gist solution).

I find your post trying to solve euler18 with zippers and very fast found an error in your code.

HTH,

Eduard

(defn merge-rows[a b]

(map + (map #(apply max %) (partition 2 1 a)) b))

(reduce merge-rows (reverse routes))

]]>here is my simple solution: https://gist.github.com/718088

You wrote a good example of zippers usage, thanks.

]]>Max should be

(+ 5 6 9 9)

29

but it’s not:

user=> (def nv [5 [9 [4 [0] [7]] [6 [7] [1]]] [6 [6 [7] [1]] [9 [1] [9]]]])

user=> (sum-path zv >)

27