Monday, September 1, 2014

Euler Project: Problem 6 in Clojure

This is my solution in Clojure to the sixth problem from Euler project:

1 comment:

  1. Why didn't you simply solve it in closed form? D(n) = T(n)^2-P(n) where T(n) is the n'th triangular number = n(n+1)/2 and P(n) is the n'th square pyramidal number = (2n^3+3n^2+n)/6. This simplifies to the exact formula for S(n) = n/12[3n^3+2n^2-3n-2]. This leads to a one line Clojure definition with much less room for error to creep in. One should always check the math first as opposed to diving straight into algorithmics.