6 ms·
Actually that code snippet that computes a summation can be done without any loop or recursion at all: function sum (m, n) { return m * (m + 1) / 2
by substack 14y ago
Actually that code snippet that computes a summation can be done without any loop or recursion at all:
function sum (m, n) {
return m * (m + 1) / 2 - n * (n - 1) / 2
}
I only know this because I remember from math competitions in high school learning that you can compute the sum of the digits from 1 to n quickly from `n * (n + 1) / 2` which naturally follows from the equations regarding binomial sums.
This example somewhat agrees with the author's main point that we are more a product of our experiences than endowed with certain innate capabilities.