Hacker News new | ask | show | jobs
by andrewcooke 4624 days ago
no spaces.

but you can get the formula by imagining the numbers as piles of pennies and then completing them to make a square and then splitting down the diagonal

  *
  **
  ***

  *..
  **.
  ***

  \..   \
  *\. + \
  **\   \
where a \ is half a penny. so * = \\

so it's 1/2 * n * n (ie half the square) plus an extra 1/2 for each one on the diagonal.

so it's n * n/2 + n/2 = (n+1) * n/2