Record of experiments, readings, links, videos and other things that I find on the long road.
Registro de experimentos, lecturas, links, vídeos y otras cosas que voy encontrando en el largo camino.
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.
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.
ReplyDelete