That programming book you never finished

Arik on June 22, 2018

Tell me if this sounds familiar: You walk into a bookstore, browse through some shelves and run into a programming book about a subject you al... [Read Full] Based on the opening, I was looking for strategies on finishing books.

Use iterators:

``````pages.each(&:read!)
``````

or mappers:

``````pages.map(&:memory)
``````

or even reducers:

``````pages.reduce([]) { |knowledge, page| knowledge << page }
``````

I was expecting the same U_u

Yes.

Me too

Try reducing computation by finding a closed form instead of writing a loop. Here, the closed form is `f(n) = n*(n+1)` (e.g. `f(100) = 100*101 = 10100`):

``````f(n) = S[1..n] 2*i     definition
= 2 * S[1..n] i   pull out the coefficient
= 2 * n*(n+1)/2   by triangular number formula
= n*(n+1)         cancel the twos
``````

Personally I would think the following is the exact translation in Python of the math formula shown in the article:

``````  sum(2*i for i in range(1, 101))
``````

(well... if you ignore the fact that the upper limit of `range` in not inclusive so I need to put 101 instead of 100)

So now that you know about Sigmas etc. you can read The Art of Computer Programming ;-)

Not the topic I expected, bit was a nice read anyway.

I recommend this site brilliant.org for math and science stuff :)

*Greek…

I 💖 Math.

github.com/Jam3/math-as-code is a "cheatsheet" explaining tons of math notation by showing equivalent JavaScript code, similar to how this article explained Σ.

Mathematical Notation: A Guide for Engineers and Scientists
I bought this little jewel just for this situation:
amazon.com/Mathematical-Notation-G...

The rabbit hole in question.

mathworld.wolfram.com

I'm surprised they're not teaching this in school anymore.

Misleading headline. But now high school math is coming back to me...

code of conduct - report abuse  